Merge branch 'revert-71460802' into 'develop'

Revert "Merge branch 'fix/normalize-lang-locales' into 'develop'"


See merge request firefish/firefish!10604
This commit is contained in:
Kainoa Kanter 2023-09-22 02:36:57 +00:00
commit 7ecd1e9399
4 changed files with 6 additions and 28 deletions

View File

@ -1,22 +0,0 @@
export class NormalizeLocales1695348946091 {
name = "NormalizeLocales1695348946091";
async up(queryRunner) {
await queryRunner
.query(`SELECT "id", "lang" FROM "note" WHERE "lang" IS NOT NULL`)
.then((notes) =>
Promise.all(
notes.map((note) => {
return queryRunner.query(
'UPDATE "note" SET "lang" = $1 WHERE "id" = $2',
[note.lang.trim().split("-")[0].split("@")[0], note.id],
);
}),
),
);
}
async down(queryRunner) {
// The original locales are not stored, so migrating back is not possible.
}
}

View File

@ -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.trim().split("-")[0].split("@")[0] : null;
lang = Object.keys(langmap).includes(key) ? key : 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] : 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.trim().split("-")[0].split("@")[0] : null;
lang = Object.keys(langmap).includes(key) ? key : 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] : null;
text = htmlToMfm(entry[1], post.tag);
} else if (typeof post.content === "string") {
text = htmlToMfm(post.content, post.tag);

View File

@ -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 {

View File

@ -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 {