fix: 🐛 normalize post language strings
ref: !10603 NOTE: if you upgraded to4a7bad11c6
but before this commit, manually download and run this migration:0f5e09d3ae/packages/backend/migration/1695348946091-normalize-locales.js
This commit is contained in:
parent
7ecd1e9399
commit
4aceb2e119
@ -314,11 +314,11 @@ export async function createNote(
|
|||||||
text = note.source.content;
|
text = note.source.content;
|
||||||
if (note.contentMap != null) {
|
if (note.contentMap != null) {
|
||||||
const key = Object.keys(note.contentMap)[0];
|
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) {
|
} else if (note.contentMap != null) {
|
||||||
const entry = Object.entries(note.contentMap)[0];
|
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);
|
text = htmlToMfm(entry[1], note.tag);
|
||||||
} else if (typeof note.content === "string") {
|
} else if (typeof note.content === "string") {
|
||||||
text = htmlToMfm(note.content, note.tag);
|
text = htmlToMfm(note.content, note.tag);
|
||||||
@ -584,11 +584,11 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
|
|||||||
text = post.source.content;
|
text = post.source.content;
|
||||||
if (post.contentMap != null) {
|
if (post.contentMap != null) {
|
||||||
const key = Object.keys(post.contentMap)[0];
|
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) {
|
} else if (post.contentMap != null) {
|
||||||
const entry = Object.entries(post.contentMap)[0];
|
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);
|
text = htmlToMfm(entry[1], post.tag);
|
||||||
} else if (typeof post.content === "string") {
|
} else if (typeof post.content === "string") {
|
||||||
text = htmlToMfm(post.content, post.tag);
|
text = htmlToMfm(post.content, post.tag);
|
||||||
|
@ -379,8 +379,8 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ps.lang) {
|
if (ps.lang) {
|
||||||
ps.lang = ps.lang.trim();
|
|
||||||
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) {
|
} else if (ps.text) {
|
||||||
ps.lang = detectLanguage(ps.text);
|
ps.lang = detectLanguage(ps.text);
|
||||||
} else {
|
} else {
|
||||||
|
@ -280,8 +280,8 @@ export default async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.lang) {
|
if (data.lang) {
|
||||||
data.lang = data.lang.trim();
|
|
||||||
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) {
|
} else if (data.text) {
|
||||||
data.lang = detectLanguage(data.text);
|
data.lang = detectLanguage(data.text);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user