From b97c4511d91728c5d21231a9e6da87f35c2a34b3 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 12 Sep 2023 15:11:55 +0200 Subject: [PATCH] Make MFM search engine a config option, switch default engine to DuckDuckGo, replaces #207 --- .config/example-docker.yml | 3 +++ .config/example.yml | 3 +++ packages/backend/src/config/load.ts | 2 ++ packages/backend/src/config/sane-defaults.ts | 1 - packages/backend/src/config/types.ts | 2 ++ packages/backend/src/mfm/to-html.ts | 3 +-- packages/backend/src/server/api/endpoints/meta.ts | 6 ++++++ packages/client/src/components/MkGoogle.vue | 4 ++-- packages/client/src/config.ts | 5 +++++ packages/client/src/init.ts | 3 ++- packages/iceshrimp-js/src/entities.ts | 1 + sane-defaults.js | 1 - 12 files changed, 27 insertions(+), 7 deletions(-) delete mode 100644 packages/backend/src/config/sane-defaults.ts delete mode 100644 sane-defaults.js diff --git a/.config/example-docker.yml b/.config/example-docker.yml index 359b72f40..b80e809a2 100644 --- a/.config/example-docker.yml +++ b/.config/example-docker.yml @@ -204,6 +204,9 @@ reservedUsernames: [ # notFound: '/twemoji/2049.svg' # error: '/twemoji/1f480.svg' +# Search engine (MFM) +#searchEngine: 'https://duckduckgo.com/?q=' + #allowedPrivateNetworks: [ # '127.0.0.1/32' #] diff --git a/.config/example.yml b/.config/example.yml index 20e301070..7fd3e5812 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -203,6 +203,9 @@ reservedUsernames: [ # notFound: '/twemoji/2049.svg' # error: '/twemoji/1f480.svg' +# Search engine (MFM) +#searchEngine: 'https://duckduckgo.com/?q=' + #allowedPrivateNetworks: [ # '127.0.0.1/32' #] diff --git a/packages/backend/src/config/load.ts b/packages/backend/src/config/load.ts index 31ca4242e..945863a44 100644 --- a/packages/backend/src/config/load.ts +++ b/packages/backend/src/config/load.ts @@ -49,6 +49,8 @@ export default function load() { error: '/twemoji/1f480.svg', }; + config.searchEngine = config.searchEngine ?? 'https://duckduckgo.com/?q='; + mixin.version = meta.version; mixin.host = url.host; mixin.hostname = url.hostname; diff --git a/packages/backend/src/config/sane-defaults.ts b/packages/backend/src/config/sane-defaults.ts deleted file mode 100644 index 2d9788c24..000000000 --- a/packages/backend/src/config/sane-defaults.ts +++ /dev/null @@ -1 +0,0 @@ -export const engine = "https://www.google.com/search?q=" diff --git a/packages/backend/src/config/types.ts b/packages/backend/src/config/types.ts index a53a54651..2b8fa5a71 100644 --- a/packages/backend/src/config/types.ts +++ b/packages/backend/src/config/types.ts @@ -72,6 +72,8 @@ export type Source = { info?: string; }; + searchEngine?: string; + proxy?: string; proxySmtp?: string; proxyBypassHosts?: string[]; diff --git a/packages/backend/src/mfm/to-html.ts b/packages/backend/src/mfm/to-html.ts index a923d389e..1693f2cef 100644 --- a/packages/backend/src/mfm/to-html.ts +++ b/packages/backend/src/mfm/to-html.ts @@ -3,7 +3,6 @@ import type * as mfm from "mfm-js"; import config from "@/config/index.js"; import { intersperse } from "@/prelude/array.js"; import type { IMentionedRemoteUsers } from "@/models/entities/note.js"; -import { engine } from "@/config/sane-defaults.js"; export function toHtml( nodes: mfm.MfmNode[] | null, @@ -157,7 +156,7 @@ export function toHtml( search(node) { const a = doc.createElement("a"); - a.href = `${engine}{node.props.query}`; + a.href = `${config.searchEngine}${node.props.query}`; a.textContent = node.props.content; return a; }, diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 964919dce..a80fcd5f5 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -190,6 +190,11 @@ export const meta = { optional: false, nullable: false, }, + searchEngine: { + type: "string", + optional: false, + nullable: false, + }, emojis: { type: "array", optional: false, @@ -449,6 +454,7 @@ export default define(meta, paramDef, async (ps, me) => { logoImageUrl: instance.logoImageUrl, maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため maxCaptionTextLength: MAX_CAPTION_TEXT_LENGTH, + searchEngine: config.searchEngine, emojis: instance.privateMode && !me ? [] : await Emojis.packMany(emojis), // クライアントの手間を減らすためあらかじめJSONに変換しておく defaultLightTheme: instance.defaultLightTheme diff --git a/packages/client/src/components/MkGoogle.vue b/packages/client/src/components/MkGoogle.vue index a69b09b7e..8d7388e84 100644 --- a/packages/client/src/components/MkGoogle.vue +++ b/packages/client/src/components/MkGoogle.vue @@ -11,7 +11,7 @@