From 1129a2ec8c25f572dff6f87bcb5044ae5568e472 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Wed, 27 Jul 2022 10:25:30 -0700 Subject: [PATCH] Custom splash icons! --- locales/en-US.yml | 3 +- locales/ja-JP.yml | 2 ++ .../1658941974648CustomSplashIcons.js | 8 +++++ packages/backend/src/models/entities/meta.ts | 5 +++ packages/backend/src/server/api/endpoints.ts | 2 ++ .../src/server/api/endpoints/admin/meta.ts | 9 ++++++ .../server/api/endpoints/admin/update-meta.ts | 7 ++++ .../src/server/api/endpoints/custom-motd.ts | 2 +- .../api/endpoints/custom-splash-icons.ts | 32 +++++++++++++++++++ packages/backend/src/server/web/index.ts | 6 +++- packages/client/src/pages/admin/settings.vue | 8 +++++ 11 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 packages/backend/migration/1658941974648CustomSplashIcons.js create mode 100644 packages/backend/src/server/api/endpoints/custom-splash-icons.ts diff --git a/locales/en-US.yml b/locales/en-US.yml index 53cb9185f..b8e8fe1bd 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -903,7 +903,8 @@ enterSendsMessage: "Press Return in Messaging to send message (off is Ctrl + Ret adminCustomCssWarn: "This setting should only be used if you know what it does. Entering improper values may cause EVERYONE'S clients to stop functioning normally. Please ensure your CSS works properly by testing it in your user settings." customMOTD: "Custom MOTD (splash screen messages)" customMOTDDescription: "Custom messages for the MOTD (splash screen) separated by line breaks to be shown randomly every time a user loads/reloads the page." - +customSplashIcons: "Custom splash screen icons (urls)" +customSplashIconsDescription: "URLs for custom splash screen icons separated by line breaks to be shown randomly every time a user loads/reloads the page. Please make sure the images are on a static URL, preferably all resized to 192x192." _sensitiveMediaDetection: description: "Reduces the effort of server moderation through automatically recognizing NSFW media via Machine Learning. This will slightly increase the load on the server." diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 3ce268ddd..ff96cc77c 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -903,6 +903,8 @@ move: "移動" adminCustomCssWarn: "この設定は、それが何をするものであるかを知っている場合のみ使用してください。不適切な値を入力すると、クライアントが正常に動作しなくなる可能性があります。ユーザー設定でCSSをテストし、正しく動作することを確認してください。" customMOTD: "カスタムMOTD(スプラッシュスクリーンメッセージ)" customMOTDDescription: "ユーザがページをロード/リロードするたびにランダムに表示される、改行で区切られたMOTD(スプラッシュスクリーン)用のカスタムメッセージ" +customSplashIcons: "カスタムスプラッシュスクリーンアイコン" +customSplashIconsDescription: "ユーザがページをロード/リロードするたびにランダムに表示される、改行で区切られたカスタムスプラッシュスクリーンアイコンの URL。画像は静的なURLで、できればすべて192x192にリサイズしてください。" _sensitiveMediaDetection: description: "機械学習を使って自動でセンシティブなメディアを検出し、モデレーションに役立てることができます。サーバーの負荷が少し増えます。" diff --git a/packages/backend/migration/1658941974648CustomSplashIcons.js b/packages/backend/migration/1658941974648CustomSplashIcons.js new file mode 100644 index 000000000..fce5eb767 --- /dev/null +++ b/packages/backend/migration/1658941974648CustomSplashIcons.js @@ -0,0 +1,8 @@ +export class CustomSplashIcons1658941974648 { + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "customSplashIcons" character varying(256) array NOT NULL DEFAULT '{}'::varchar[]`); + } + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "customSplashIcons"`); + } +} diff --git a/packages/backend/src/models/entities/meta.ts b/packages/backend/src/models/entities/meta.ts index cb47307f9..475f68324 100644 --- a/packages/backend/src/models/entities/meta.ts +++ b/packages/backend/src/models/entities/meta.ts @@ -72,6 +72,11 @@ export class Meta { }) public customMOTD: string[]; + @Column('varchar', { + length: 256, array: true, default: '{}', + }) + public customSplashIcons: string[]; + @Column('varchar', { length: 256, array: true, default: '{}', }) diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 0c29e16fc..c8f64ee46 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -269,6 +269,7 @@ import * as ep___pages_update from './endpoints/pages/update.js'; import * as ep___ping from './endpoints/ping.js'; import * as ep___pinnedUsers from './endpoints/pinned-users.js'; import * as ep___customMOTD from './endpoints/custom-motd.js'; +import * as ep___customSplashIcons from './endpoints/custom-splash-icons.js'; import * as ep___promo_read from './endpoints/promo/read.js'; import * as ep___requestResetPassword from './endpoints/request-reset-password.js'; import * as ep___resetDb from './endpoints/reset-db.js'; @@ -587,6 +588,7 @@ const eps = [ ['ping', ep___ping], ['pinned-users', ep___pinnedUsers], ['custom-motd', ep___customMOTD], + ['custom-motd', ep___customSplashIcons], ['promo/read', ep___promo_read], ['request-reset-password', ep___requestResetPassword], ['reset-db', ep___resetDb], diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index b5201ea9f..32441a335 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -179,6 +179,14 @@ export const meta = { optional: false, nullable: false, }, }, + customSplashIcons: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, hiddenTags: { type: 'array', optional: true, nullable: false, @@ -411,6 +419,7 @@ export default define(meta, paramDef, async (ps, me) => { useStarForReactionFallback: instance.useStarForReactionFallback, pinnedUsers: instance.pinnedUsers, customMOTD: instance.customMOTD, + customSplashIcons: instance.customSplashIcons, hiddenTags: instance.hiddenTags, blockedHosts: instance.blockedHosts, allowedHosts: instance.allowedHosts, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 60d388d68..f8077a033 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -24,6 +24,9 @@ export const paramDef = { customMOTD: { type: 'array', nullable: true, items: { type: 'string', } }, + customSplashIcons: { type: 'array', nullable: true, items: { + type: 'string', + } }, hiddenTags: { type: 'array', nullable: true, items: { type: 'string', } }, @@ -142,6 +145,10 @@ export default define(meta, paramDef, async (ps, me) => { set.customMOTD = ps.customMOTD.filter(Boolean); } + if (Array.isArray(ps.customSplashIcons)) { + set.customSplashIcons = ps.customSplashIcons.filter(Boolean); + } + if (Array.isArray(ps.hiddenTags)) { set.hiddenTags = ps.hiddenTags.filter(Boolean); } diff --git a/packages/backend/src/server/api/endpoints/custom-motd.ts b/packages/backend/src/server/api/endpoints/custom-motd.ts index 859bde904..fd58424bd 100644 --- a/packages/backend/src/server/api/endpoints/custom-motd.ts +++ b/packages/backend/src/server/api/endpoints/custom-motd.ts @@ -19,7 +19,7 @@ export const meta = { } as const; export const paramDef = { - type: 'array', + type: 'object', properties: {}, required: [], } as const; diff --git a/packages/backend/src/server/api/endpoints/custom-splash-icons.ts b/packages/backend/src/server/api/endpoints/custom-splash-icons.ts new file mode 100644 index 000000000..380e2131b --- /dev/null +++ b/packages/backend/src/server/api/endpoints/custom-splash-icons.ts @@ -0,0 +1,32 @@ +// import { IsNull } from 'typeorm'; +import { fetchMeta } from '@/misc/fetch-meta.js'; +import define from '../define.js'; + +export const meta = { + tags: ['meta'], + + requireCredential: false, + requireCredentialPrivateMode: true, + + res: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, +} as const; + +export const paramDef = { + type: 'object', + properties: {}, + required: [], +} as const; + +// eslint-disable-next-line import/no-default-export +export default define(meta, paramDef, async () => { + const meta = await fetchMeta(); + const icons = await Promise.all(meta.customSplashIcons.map(x => x)); + return icons; +}); diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index 161f8a473..bb5b1a772 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -530,12 +530,16 @@ router.get('(.*)', async ctx => { if (meta.customMOTD.length > 0) { motd = meta.customMOTD; } + let iconUrl = meta.iconUrl; + if (meta.customSplashIcons.length > 0) { + iconUrl = meta.customSplashIcons[Math.floor(Math.random() * meta.customSplashIcons.length)]; + } await ctx.render('base', { img: meta.bannerUrl, title: meta.name || 'Calckey', instanceName: meta.name || 'Calckey', desc: meta.description, - icon: meta.iconUrl, + icon: iconUrl, themeColor: meta.themeColor, privateMode: meta.privateMode, randomMOTD: motd[Math.floor(Math.random() * motd.length)], diff --git a/packages/client/src/pages/admin/settings.vue b/packages/client/src/pages/admin/settings.vue index 995c8e805..2060328a2 100644 --- a/packages/client/src/pages/admin/settings.vue +++ b/packages/client/src/pages/admin/settings.vue @@ -39,6 +39,11 @@ + + + + + @@ -182,6 +187,7 @@ let enableLocalTimeline: boolean = $ref(false); let enableGlobalTimeline: boolean = $ref(false); let pinnedUsers: string = $ref(''); let customMOTD: string = $ref(''); +let customSplashIcons: string = $ref(''); let cacheRemoteFiles: boolean = $ref(false); let localDriveCapacityMb: any = $ref(0); let remoteDriveCapacityMb: any = $ref(0); @@ -210,6 +216,7 @@ async function init() { enableGlobalTimeline = !meta.disableGlobalTimeline; pinnedUsers = meta.pinnedUsers.join('\n'); customMOTD = meta.customMOTD.join('\n'); + customSplashIcons = meta.customSplashIcons.join('\n'); cacheRemoteFiles = meta.cacheRemoteFiles; localDriveCapacityMb = meta.driveCapacityPerLocalUserMb; remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb; @@ -239,6 +246,7 @@ function save() { disableGlobalTimeline: !enableGlobalTimeline, pinnedUsers: pinnedUsers.split('\n'), customMOTD: customMOTD.split('\n'), + customSplashIcons: customSplashIcons.split('\n'), cacheRemoteFiles, localDriveCapacityMb: parseInt(localDriveCapacityMb, 10), remoteDriveCapacityMb: parseInt(remoteDriveCapacityMb, 10),