chore: 🎨 format

This commit is contained in:
ThatOneCalculator 2023-09-21 20:21:15 -07:00
parent 4aceb2e119
commit 260f444fb8
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
7 changed files with 43 additions and 19 deletions

View File

@ -1,11 +1,13 @@
export class AddPostLang1695334243217 { export class AddPostLang1695334243217 {
name = 'AddPostLang1695334243217' name = "AddPostLang1695334243217";
async up(queryRunner) { async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "note" ADD "lang" character varying(10)`); await queryRunner.query(
} `ALTER TABLE "note" ADD "lang" character varying(10)`,
);
}
async down(queryRunner) { async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "lang"`); await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "lang"`);
} }
} }

View File

@ -314,11 +314,15 @@ 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.trim().split("-")[0].split("@")[0] : 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].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); 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 +588,15 @@ 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.trim().split("-")[0].split("@")[0] : 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].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); 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);

View File

@ -116,9 +116,11 @@ export default async function renderNote(
); );
const lang = note.lang ?? detectLanguage(text); const lang = note.lang ?? detectLanguage(text);
const contentMap = lang ? { const contentMap = lang
[lang]: content ? {
} : null; [lang]: content,
}
: null;
const emojis = await getEmojis(note.emojis); const emojis = await getEmojis(note.emojis);
const apemojis = emojis.map((emoji) => renderEmoji(emoji)); const apemojis = emojis.map((emoji) => renderEmoji(emoji));

View File

@ -379,7 +379,8 @@ export default define(meta, paramDef, async (ps, user) => {
} }
if (ps.lang) { 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]; 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);

View File

@ -280,7 +280,8 @@ export default async (
} }
if (data.lang) { 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]; 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);

View File

@ -97,7 +97,11 @@
<div class="main"> <div class="main">
<div class="header-container"> <div class="header-container">
<MkAvatar class="avatar" :user="appearNote.user" /> <MkAvatar class="avatar" :user="appearNote.user" />
<XNoteHeader class="header" :note="appearNote" :can-open-server-info="true" /> <XNoteHeader
class="header"
:note="appearNote"
:can-open-server-info="true"
/>
</div> </div>
<div class="body"> <div class="body">
<MkSubNoteContent <MkSubNoteContent

View File

@ -74,9 +74,15 @@ const showTicker =
note.value.user.instance); note.value.user.instance);
function openServerInfo() { function openServerInfo() {
if (props.canOpenServerInfo && !defaultStore.state.openServerInfo || !note.value.user.instance) return; if (
(props.canOpenServerInfo && !defaultStore.state.openServerInfo) ||
!note.value.user.instance
)
return;
const instanceInfoUrl = const instanceInfoUrl =
props.host == null ? "/about" : `/instance-info/${note.value.user.instance}`; props.host == null
? "/about"
: `/instance-info/${note.value.user.instance}`;
pageWindow(instanceInfoUrl); pageWindow(instanceInfoUrl);
} }
</script> </script>