From c392697b4cdd91fdb8735ea4e6ffcc07c6f14b42 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 2 Jul 2023 23:08:33 -0700 Subject: [PATCH] chore: :art: format --- .../src/server/api/endpoints/patrons.ts | 10 +- .../src/server/api/endpoints/server-info.ts | 4 +- packages/backend/src/server/index.ts | 5 +- packages/backend/src/server/web/feed.ts | 99 +++++++++++++------ packages/backend/src/server/web/index.ts | 50 ++++++++-- .../src/services/chart/charts/active-users.ts | 2 +- packages/client/src/components/MkMedia.vue | 11 +-- packages/client/src/pages/about-calckey.vue | 2 +- packages/client/src/pages/user/home.vue | 2 +- 9 files changed, 130 insertions(+), 55 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/patrons.ts b/packages/backend/src/server/api/endpoints/patrons.ts index 353cba1dc..be89c571f 100644 --- a/packages/backend/src/server/api/endpoints/patrons.ts +++ b/packages/backend/src/server/api/endpoints/patrons.ts @@ -24,14 +24,14 @@ export default define(meta, paramDef, async (ps) => { patrons = JSON.parse(cachedPatrons); } else { AbortSignal.timeout ??= function timeout(ms) { - const ctrl = new AbortController() - setTimeout(() => ctrl.abort(), ms) - return ctrl.signal - } + const ctrl = new AbortController(); + setTimeout(() => ctrl.abort(), ms); + return ctrl.signal; + }; patrons = await fetch( "https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json", - { signal: AbortSignal.timeout(2000) } + { signal: AbortSignal.timeout(2000) }, ) .then((response) => response.json()) .catch(() => { diff --git a/packages/backend/src/server/api/endpoints/server-info.ts b/packages/backend/src/server/api/endpoints/server-info.ts index 746eae662..87132758f 100644 --- a/packages/backend/src/server/api/endpoints/server-info.ts +++ b/packages/backend/src/server/api/endpoints/server-info.ts @@ -34,9 +34,9 @@ export default define(meta, paramDef, async () => { const instanceMeta = await fetchMeta(); if (!instanceMeta.enableServerMachineStats) { return { - machine: 'Not specified', + machine: "Not specified", cpu: { - model: 'Not specified', + model: "Not specified", cores: 0, }, mem: { diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index 7f8d0ed71..cd2d13219 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -132,9 +132,8 @@ router.get("/identicon/:x", async (ctx) => { await genIdenticon(ctx.params.x, fs.createWriteStream(temp)); ctx.set("Content-Type", "image/png"); ctx.body = fs.createReadStream(temp).on("close", () => cleanup()); - } - else { - ctx.redirect("/static-assets/avatar.png") + } else { + ctx.redirect("/static-assets/avatar.png"); } }); diff --git a/packages/backend/src/server/web/feed.ts b/packages/backend/src/server/web/feed.ts index 1d2434502..004745901 100644 --- a/packages/backend/src/server/web/feed.ts +++ b/packages/backend/src/server/web/feed.ts @@ -4,18 +4,25 @@ import config from "@/config/index.js"; import type { User } from "@/models/entities/user.js"; import { Notes, DriveFiles, UserProfiles, Users } from "@/models/index.js"; -export default async function (user: User, threadDepth = 5, history = 20, noteintitle = false, renotes = true, replies = true) { +export default async function ( + user: User, + threadDepth = 5, + history = 20, + noteintitle = false, + renotes = true, + replies = true, +) { const author = { link: `${config.url}/@${user.username}`, email: `${user.username}@${config.host}`, - name: user.name || user.username + name: user.name || user.username, }; const profile = await UserProfiles.findOneByOrFail({ userId: user.id }); const searchCriteria = { userId: user.id, - visibility: In(['public', 'home']), + visibility: In(["public", "home"]), }; if (!renotes) { @@ -36,8 +43,12 @@ export default async function (user: User, threadDepth = 5, history = 20, notein id: author.link, title: `${author.name} (@${user.username}@${config.host})`, updated: notes[0].createdAt, - generator: 'Calckey', - description: `${user.notesCount} Notes, ${profile.ffVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.ffVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`, + generator: "Calckey", + description: `${user.notesCount} Notes, ${ + profile.ffVisibility === "public" ? user.followingCount : "?" + } Following, ${ + profile.ffVisibility === "public" ? user.followersCount : "?" + } Followers${profile.description ? ` · ${profile.description}` : ""}`, link: author.link, image: await Users.getAvatarUrl(user), feedLinks: { @@ -61,59 +72,87 @@ export default async function (user: User, threadDepth = 5, history = 20, notein let title = `${author.name} `; if (note.renoteId) { - title += 'renotes'; + title += "renotes"; } else if (note.replyId) { - title += 'replies'; + title += "replies"; } else { - title += 'says'; + title += "says"; } if (noteintitle) { const content = note.cw ?? note.text; if (content) { title += `: ${content}`; } else { - title += 'something'; + title += "something"; } } feed.addItem({ - title: title.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '').substring(0,100), + title: title + .replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "") + .substring(0, 100), link: `${config.url}/notes/${note.id}`, date: note.createdAt, - description: note.cw ? note.cw.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '') : undefined, - content: contentStr.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '') + description: note.cw + ? note.cw.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "") + : undefined, + content: contentStr.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ""), }); } - async function noteToString (note, isTheNote = false) { - const author = isTheNote ? null : await Users.findOneBy({ id: note.userId }); - let outstr = author ? `${author.name}(@${author.username}@${author.host ? author.host : config.host}) ${(note.renoteId ? 'renotes' : (note.replyId ? 'replies' : 'says'))}:
` : ''; - const files = note.fileIds.length > 0 ? await DriveFiles.findBy({ - id: In(note.fileIds), - }) : []; - let fileEle = ''; + async function noteToString(note, isTheNote = false) { + const author = isTheNote + ? null + : await Users.findOneBy({ id: note.userId }); + let outstr = author + ? `${author.name}(@${author.username}@${ + author.host ? author.host : config.host + }) ${ + note.renoteId ? "renotes" : note.replyId ? "replies" : "says" + }:
` + : ""; + const files = + note.fileIds.length > 0 + ? await DriveFiles.findBy({ + id: In(note.fileIds), + }) + : []; + let fileEle = ""; for (const file of files) { - if (file.type.startsWith('image/')) { + if (file.type.startsWith("image/")) { fileEle += `
`; - } else if (file.type.startsWith('audio/')) { - fileEle += `