From 4aceb2e119f5204ca1c8176881811bc2350bd0e6 Mon Sep 17 00:00:00 2001 From: Essem Date: Thu, 21 Sep 2023 19:40:02 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20normalize=20post=20langua?= =?UTF-8?q?ge=20strings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref: !10603 NOTE: if you upgraded to 4a7bad11c697b53712dfc162f87941dd16199c9c but before this commit, manually download and run this migration: https://git.joinfirefish.org/firefish/firefish/-/blob/0f5e09d3ae4429c99ee0719295eeb8f282d53fe2/packages/backend/migration/1695348946091-normalize-locales.js --- packages/backend/src/remote/activitypub/models/note.ts | 8 ++++---- packages/backend/src/server/api/endpoints/notes/edit.ts | 2 +- packages/backend/src/services/note/create.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 5c8807c29d..fa01046f2d 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -314,11 +314,11 @@ export async function createNote( text = note.source.content; if (note.contentMap != null) { const key = Object.keys(note.contentMap)[0]; - lang = Object.keys(langmap).includes(key) ? key : null; + lang = Object.keys(langmap).includes(key) ? key.trim().split("-")[0].split("@")[0] : null; } } else if (note.contentMap != null) { const entry = Object.entries(note.contentMap)[0]; - lang = Object.keys(langmap).includes(entry[0]) ? entry[0] : null; + lang = Object.keys(langmap).includes(entry[0]) ? entry[0].trim().split("-")[0].split("@")[0] : null; text = htmlToMfm(entry[1], note.tag); } else if (typeof note.content === "string") { text = htmlToMfm(note.content, note.tag); @@ -584,11 +584,11 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { text = post.source.content; if (post.contentMap != null) { const key = Object.keys(post.contentMap)[0]; - lang = Object.keys(langmap).includes(key) ? key : null; + lang = Object.keys(langmap).includes(key) ? key.trim().split("-")[0].split("@")[0] : null; } } else if (post.contentMap != null) { const entry = Object.entries(post.contentMap)[0]; - lang = Object.keys(langmap).includes(entry[0]) ? entry[0] : null; + lang = Object.keys(langmap).includes(entry[0]) ? entry[0].trim().split("-")[0].split("@")[0] : null; text = htmlToMfm(entry[1], post.tag); } else if (typeof post.content === "string") { text = htmlToMfm(post.content, post.tag); diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts index 9e58021c2f..8d825cf61c 100644 --- a/packages/backend/src/server/api/endpoints/notes/edit.ts +++ b/packages/backend/src/server/api/endpoints/notes/edit.ts @@ -379,8 +379,8 @@ export default define(meta, paramDef, async (ps, user) => { } if (ps.lang) { - ps.lang = ps.lang.trim(); if (!Object.keys(langmap).includes(ps.lang.trim())) throw new Error("invalid param"); + ps.lang = ps.lang.trim().split("-")[0].split("@")[0]; } else if (ps.text) { ps.lang = detectLanguage(ps.text); } else { diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 80ea6255ea..080925048c 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -280,8 +280,8 @@ export default async ( } if (data.lang) { - data.lang = data.lang.trim(); if (!Object.keys(langmap).includes(data.lang.trim())) throw new Error("invalid param"); + data.lang = data.lang.trim().split("-")[0].split("@")[0]; } else if (data.text) { data.lang = detectLanguage(data.text); } else {