From 9c905f84e8bee551ad6abcc2d51788b1731099a5 Mon Sep 17 00:00:00 2001 From: mattyatea Date: Fri, 16 Feb 2024 20:36:23 +0900 Subject: [PATCH] a --- .../backend/src/core/NoteCreateService.ts | 34 ++++++++-- packages/backend/src/models/Meta.ts | 7 +++ .../src/server/api/endpoints/admin/meta.ts | 4 ++ .../server/api/endpoints/admin/update-meta.ts | 4 ++ .../src/server/web/ClientServerService.ts | 13 ---- packages/frontend/src/pages/about.vue | 1 - .../src/pages/admin/other-settings.vue | 62 +++++++++++-------- 7 files changed, 80 insertions(+), 45 deletions(-) diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 378c215b6c..5951d2d6fa 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -265,17 +265,43 @@ export class NoteCreateService implements OnApplicationShutdown { } if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) { - const { DiscordWebhookUrl } = (await this.metaService.fetch()); + const { DiscordWebhookUrlWordBlock } = (await this.metaService.fetch()); + const regexpregexp = /^\/(.+)\/(.*)$/; + let matchedString = ''; + for (const filter of meta.prohibitedWords) { + // represents RegExp + const regexp = filter.match(regexpregexp); + // This should never happen due to input sanitisation. + if (!regexp) { + const words = filter.split(' '); + const foundWord = words.find(keyword => (data.cw ?? data.text ?? '').includes(keyword)); + if (foundWord) { + matchedString = foundWord; + break; + } + } else { + const match = new RE2(regexp[1], regexp[2]).exec(data.cw ?? data.text ?? ''); + if (match) { + matchedString = match[0]; + break; + } + } + } - if (DiscordWebhookUrl) { + console.log('matched', matchedString); + if (DiscordWebhookUrlWordBlock) { const data_disc = { 'username': 'ノートブロックお知らせ', 'content': 'ユーザー名 :' + user.username + '\n' + 'url : ' + user.host + '\n' + - 'contents : ' + data.text, + 'contents : ' + data.text + '\n' + + '引っかかったワード :' + matchedString, + 'allowed_mentions': { + 'parse': [], + }, }; - await fetch(DiscordWebhookUrl, { + await fetch(DiscordWebhookUrlWordBlock, { 'method': 'post', headers: { 'Content-Type': 'application/json', diff --git a/packages/backend/src/models/Meta.ts b/packages/backend/src/models/Meta.ts index 7796de6ef7..cdb2955f01 100644 --- a/packages/backend/src/models/Meta.ts +++ b/packages/backend/src/models/Meta.ts @@ -229,6 +229,13 @@ export class MiMeta { nullable: true, }) public DiscordWebhookUrl: string | null; + + @Column('varchar', { + length: 1024, + nullable: true, + }) + public DiscordWebhookUrlWordBlock: string | null; + @Column('varchar', { length: 1024, nullable: true, diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index ef00a987bc..08f2b95df6 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -458,6 +458,9 @@ export const meta = { DiscordWebhookUrl: { type: 'string', optional: false, nullable: true, + }, DiscordWebhookUrlWordBlock: { + type: 'string', + optional: false, nullable: true, }, enableProxyCheckio: { type: 'boolean', @@ -595,6 +598,7 @@ export default class extends Endpoint { // eslint- perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax, notesPerOneAd: instance.notesPerOneAd, DiscordWebhookUrl: instance.DiscordWebhookUrl, + DiscordWebhookUrlWordBlock: instance.DiscordWebhookUrlWordBlock, EmojiBotToken: instance.EmojiBotToken, ApiBase: instance.ApiBase, enableGDPRMode: instance.enableGDPRMode, 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 4acd51c0db..f7ca38f81f 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -92,6 +92,7 @@ export const paramDef = { }, summalyProxy: { type: 'string', nullable: true }, DiscordWebhookUrl: { type: 'string', nullable: true }, + DiscordWebhookUrlWordBlock: { type: 'string', nullable: true }, deeplAuthKey: { type: 'string', nullable: true }, deeplIsPro: { type: 'boolean' }, enableEmail: { type: 'boolean' }, @@ -210,6 +211,9 @@ export default class extends Endpoint { // eslint- if (ps.DiscordWebhookUrl !== undefined) { set.DiscordWebhookUrl = ps.DiscordWebhookUrl; } + if (ps.DiscordWebhookUrlWordBlock !== undefined) { + set.DiscordWebhookUrlWordBlock = ps.DiscordWebhookUrlWordBlock; + } if (ps.EmojiBotToken !== undefined) { set.EmojiBotToken = ps.EmojiBotToken; } diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 28acc47a40..e788b292d9 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -61,7 +61,6 @@ const clientAssets = `${_dirname}/../../../../frontend/assets/`; const assets = `${_dirname}/../../../../../built/_frontend_dist_/`; const swAssets = `${_dirname}/../../../../../built/_sw_dist_/`; const viteOut = `${_dirname}/../../../../../built/_vite_/`; -const tarball = `${_dirname}/../../../../../built/tarball/`; @Injectable() export class ClientServerService { @@ -309,18 +308,6 @@ export class ClientServerService { decorateReply: false, }); - fastify.register((fastify, options, done) => { - fastify.register(fastifyStatic, { - root: tarball, - prefix: '/tarball/', - maxAge: ms('30 days'), - immutable: true, - decorateReply: false, - }); - fastify.addHook('onRequest', handleRequestRedirectToOmitSearch); - done(); - }); - fastify.get('/favicon.ico', async (request, reply) => { return reply.sendFile('/favicon.ico', staticAssets); }); diff --git a/packages/frontend/src/pages/about.vue b/packages/frontend/src/pages/about.vue index c500ce49ce..71d813b696 100644 --- a/packages/frontend/src/pages/about.vue +++ b/packages/frontend/src/pages/about.vue @@ -87,7 +87,6 @@ SPDX-License-Identifier: AGPL-3.0-only nodeinfo robots.txt manifest.json - source code diff --git a/packages/frontend/src/pages/admin/other-settings.vue b/packages/frontend/src/pages/admin/other-settings.vue index c542686c3c..9b8f1a61b4 100644 --- a/packages/frontend/src/pages/admin/other-settings.vue +++ b/packages/frontend/src/pages/admin/other-settings.vue @@ -36,21 +36,25 @@ SPDX-License-Identifier: AGPL-3.0-only - - - - - - - - - - - - - -絵文字の申請全部許可 - + + + + + + + + + + + + + + + + + + 絵文字の申請全部許可 + @@ -67,26 +71,29 @@ import { fetchInstance } from '@/instance.js'; import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; import MkSwitch from '@/components/MkSwitch.vue'; -import MkInput from "@/components/MkInput.vue"; +import MkInput from '@/components/MkInput.vue'; const enableServerMachineStats = ref(false); const enableIdenticonGeneration = ref(false); const enableChartsForRemoteUser = ref(false); const enableChartsForFederatedInstances = ref(false); -const requestEmojiAllOk = ref(false) +const requestEmojiAllOk = ref(false); let DiscordWebhookUrl = ref(null); -let EmojiBotToken= ref(null); -let ApiBase= ref(null) +let DiscordWebhookUrlWordBlock = ref(null); +let EmojiBotToken = ref(null); +let ApiBase = ref(null); + async function init() { const meta = await misskeyApi('admin/meta'); enableServerMachineStats.value = meta.enableServerMachineStats; enableIdenticonGeneration.value = meta.enableIdenticonGeneration; enableChartsForRemoteUser.value = meta.enableChartsForRemoteUser; enableChartsForFederatedInstances.value = meta.enableChartsForFederatedInstances; - requestEmojiAllOk.value = meta.requestEmojiAllOk; - DiscordWebhookUrl.value = meta.DiscordWebhookUrl; - EmojiBotToken.value = meta.EmojiBotToken; - ApiBase.value = meta.ApiBase; + requestEmojiAllOk.value = meta.requestEmojiAllOk; + DiscordWebhookUrl.value = meta.DiscordWebhookUrl; + DiscordWebhookUrlWordBlock.value = meta.DiscordWebhookUrlWordBlock; + EmojiBotToken.value = meta.EmojiBotToken; + ApiBase.value = meta.ApiBase; } function save() { @@ -94,11 +101,12 @@ function save() { enableServerMachineStats: enableServerMachineStats.value, enableIdenticonGeneration: enableIdenticonGeneration.value, enableChartsForRemoteUser: enableChartsForRemoteUser.value, - requestEmojiAllOk: requestEmojiAllOk.value, + requestEmojiAllOk: requestEmojiAllOk.value, enableChartsForFederatedInstances: enableChartsForFederatedInstances.value, - DiscordWebhookUrl:DiscordWebhookUrl.value, - EmojiBotToken:EmojiBotToken.value, - ApiBase:ApiBase.value + DiscordWebhookUrl: DiscordWebhookUrl.value, + EmojiBotToken: EmojiBotToken.value, + ApiBase: ApiBase.value, + DiscordWebhookUrlWordBlock: DiscordWebhookUrlWordBlock.value, }).then(() => { fetchInstance(); });