chore: 🎨 format

This commit is contained in:
ThatOneCalculator 2023-07-02 23:08:33 -07:00
parent 02a8d3283e
commit c392697b4c
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
9 changed files with 130 additions and 55 deletions

View File

@ -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(() => {

View File

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

View File

@ -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");
}
});

View File

@ -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'))}: <br>` : '';
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"
}: <br>`
: "";
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 += ` <br><img src="${DriveFiles.getPublicUrl(file)}">`;
} else if (file.type.startsWith('audio/')) {
fileEle += ` <br><audio controls src="${DriveFiles.getPublicUrl(file)}" type="${file.type}">`;
} else if (file.type.startsWith('video/')) {
fileEle += ` <br><video controls src="${DriveFiles.getPublicUrl(file)}" type="${file.type}">`;
} else if (file.type.startsWith("audio/")) {
fileEle += ` <br><audio controls src="${DriveFiles.getPublicUrl(
file,
)}" type="${file.type}">`;
} else if (file.type.startsWith("video/")) {
fileEle += ` <br><video controls src="${DriveFiles.getPublicUrl(
file,
)}" type="${file.type}">`;
} else {
fileEle += ` <br><a href="${DriveFiles.getPublicUrl(file)}" download="${file.name}">${file.name}</a>`;
fileEle += ` <br><a href="${DriveFiles.getPublicUrl(file)}" download="${
file.name
}">${file.name}</a>`;
}
}
outstr += `${note.cw ? note.cw + '<br>' : ''}${note.text || ''}${fileEle}`;
outstr += `${note.cw ? note.cw + "<br>" : ""}${note.text || ""}${fileEle}`;
if (isTheNote) {
outstr += ` <span class="${(note.renoteId ? 'renote_note' : (note.replyId ? 'reply_note' : 'new_note'))} ${(fileEle.indexOf('img src') !== -1 ? 'with_img' : 'without_img')}"></span>`;
outstr += ` <span class="${
note.renoteId ? "renote_note" : note.replyId ? "reply_note" : "new_note"
} ${
fileEle.indexOf("img src") !== -1 ? "with_img" : "without_img"
}"></span>`;
}
return outstr;
}
async function findById (id) {
let text = '';
async function findById(id) {
let text = "";
let next = null;
const findings = await Notes.findOneBy({ id: id, visibility: In(['public', 'home']) });
const findings = await Notes.findOneBy({
id: id,
visibility: In(["public", "home"]),
});
if (findings) {
text += `<hr>`;
text += await noteToString(findings);

View File

@ -247,7 +247,14 @@ router.get("/api.json", async (ctx) => {
ctx.body = genOpenapiSpec();
});
const getFeed = async (acct: string, threadDepth:string, historyCount:string, noteInTitle:string, noRenotes:string, noReplies:string) => {
const getFeed = async (
acct: string,
threadDepth: string,
historyCount: string,
noteInTitle: string,
noRenotes: string,
noReplies: string,
) => {
const meta = await fetchMeta();
if (meta.privateMode) {
return;
@ -257,7 +264,7 @@ const getFeed = async (acct: string, threadDepth:string, historyCount:string, no
usernameLower: username.toLowerCase(),
host: host ?? IsNull(),
isSuspended: false,
isLocked:false,
isLocked: false,
});
if (!user) {
return;
@ -271,7 +278,17 @@ const getFeed = async (acct: string, threadDepth:string, historyCount:string, no
if (isNaN(history) || history <= 0 || history > 30) {
history = 20;
}
return user && await packFeed(user, thread, history, !isNaN(noteInTitle), isNaN(noRenotes), isNaN(noReplies));
return (
user &&
(await packFeed(
user,
thread,
history,
!isNaN(noteInTitle),
isNaN(noRenotes),
isNaN(noReplies),
))
);
};
// As the /@user[.json|.rss|.atom]/sub endpoint is complicated, we will use a regex to switch between them.
@ -313,7 +330,14 @@ router.get(reUser, async (ctx, next) => {
// Atom
const atomFeed: Router.Middleware = async (ctx) => {
const feed = await getFeed(ctx.params.user, ctx.query.thread, ctx.query.history, ctx.query.noteintitle, ctx.query.norenotes, ctx.query.noreplies);
const feed = await getFeed(
ctx.params.user,
ctx.query.thread,
ctx.query.history,
ctx.query.noteintitle,
ctx.query.norenotes,
ctx.query.noreplies,
);
if (feed) {
ctx.set("Content-Type", "application/atom+xml; charset=utf-8");
@ -325,7 +349,14 @@ const atomFeed: Router.Middleware = async (ctx) => {
// RSS
const rssFeed: Router.Middleware = async (ctx) => {
const feed = await getFeed(ctx.params.user, ctx.query.thread, ctx.query.history, ctx.query.noteintitle, ctx.query.norenotes, ctx.query.noreplies);
const feed = await getFeed(
ctx.params.user,
ctx.query.thread,
ctx.query.history,
ctx.query.noteintitle,
ctx.query.norenotes,
ctx.query.noreplies,
);
if (feed) {
ctx.set("Content-Type", "application/rss+xml; charset=utf-8");
@ -337,7 +368,14 @@ const rssFeed: Router.Middleware = async (ctx) => {
// JSON
const jsonFeed: Router.Middleware = async (ctx) => {
const feed = await getFeed(ctx.params.user, ctx.query.thread, ctx.query.history, ctx.query.noteintitle, ctx.query.norenotes, ctx.query.noreplies);
const feed = await getFeed(
ctx.params.user,
ctx.query.thread,
ctx.query.history,
ctx.query.noteintitle,
ctx.query.norenotes,
ctx.query.noreplies,
);
if (feed) {
ctx.set("Content-Type", "application/json; charset=utf-8");

View File

@ -29,7 +29,7 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
id: User["id"];
host: null;
createdAt: User["createdAt"];
}) {
}) {
this.commit({
read: [user.id],
registeredWithinWeek:

View File

@ -12,15 +12,14 @@
><i class="ph-warning ph-bold ph-lg"></i>
{{ i18n.ts.sensitive }}</b
>
<span style="display: block">{{ i18n.ts.clickToShow }}</span>
<span style="display: block">{{
i18n.ts.clickToShow
}}</span>
</div>
</div>
</button>
<template v-else>
<a
v-if="media.type.startsWith('image')"
:href="media.url"
>
<a v-if="media.type.startsWith('image')" :href="media.url">
<ImgWithBlurhash
:hash="media.blurhash"
:src="url"
@ -132,7 +131,7 @@ watch(
);
onMounted(() => {
if (props.media.type.startsWith('video')) {
if (props.media.type.startsWith("video")) {
plyrMini.value = plyr.value.player.media.scrollWidth < 300;
if (plyrMini.value) {
plyr.value.player.on("play", () => {

View File

@ -174,7 +174,7 @@ let patrons = [];
try {
patrons = await os.api("patrons", { forceUpdate: true });
} catch {
console.error("Codeberg's down.")
console.error("Codeberg's down.");
}
let easterEggReady = false;

View File

@ -455,7 +455,7 @@ let patrons = [];
try {
patrons = await os.api("patrons");
} catch {
console.error("Codeberg's down.")
console.error("Codeberg's down.");
}
function parallaxLoop() {