diff --git a/packages/backend/migration/1695334243217-add-post-lang.js b/packages/backend/migration/1695334243217-add-post-lang.js index f41426b4e..7e8618953 100644 --- a/packages/backend/migration/1695334243217-add-post-lang.js +++ b/packages/backend/migration/1695334243217-add-post-lang.js @@ -1,11 +1,13 @@ export class AddPostLang1695334243217 { - name = 'AddPostLang1695334243217' + name = "AddPostLang1695334243217"; - async up(queryRunner) { - await queryRunner.query(`ALTER TABLE "note" ADD "lang" character varying(10)`); - } + async up(queryRunner) { + await queryRunner.query( + `ALTER TABLE "note" ADD "lang" character varying(10)`, + ); + } - async down(queryRunner) { - await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "lang"`); - } + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "lang"`); + } } diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index fa01046f2..b2354bba6 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -314,11 +314,15 @@ 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.trim().split("-")[0].split("@")[0] : 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].trim().split("-")[0].split("@")[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 +588,15 @@ 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.trim().split("-")[0].split("@")[0] : 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].trim().split("-")[0].split("@")[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/remote/activitypub/renderer/note.ts b/packages/backend/src/remote/activitypub/renderer/note.ts index 19db792f8..4c7650e8c 100644 --- a/packages/backend/src/remote/activitypub/renderer/note.ts +++ b/packages/backend/src/remote/activitypub/renderer/note.ts @@ -116,9 +116,11 @@ export default async function renderNote( ); const lang = note.lang ?? detectLanguage(text); - const contentMap = lang ? { - [lang]: content - } : null; + const contentMap = lang + ? { + [lang]: content, + } + : null; const emojis = await getEmojis(note.emojis); const apemojis = emojis.map((emoji) => renderEmoji(emoji)); diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts index 8d825cf61..9add57670 100644 --- a/packages/backend/src/server/api/endpoints/notes/edit.ts +++ b/packages/backend/src/server/api/endpoints/notes/edit.ts @@ -379,7 +379,8 @@ export default define(meta, paramDef, async (ps, user) => { } if (ps.lang) { - if (!Object.keys(langmap).includes(ps.lang.trim())) throw new Error("invalid param"); + 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); diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 080925048..dcd2428fe 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -280,7 +280,8 @@ export default async ( } if (data.lang) { - if (!Object.keys(langmap).includes(data.lang.trim())) throw new Error("invalid param"); + 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); diff --git a/packages/client/src/components/MkNote.vue b/packages/client/src/components/MkNote.vue index 73e3ed573..3581cd239 100644 --- a/packages/client/src/components/MkNote.vue +++ b/packages/client/src/components/MkNote.vue @@ -97,7 +97,11 @@
- +