chore: 🎨 format
This commit is contained in:
parent
02a8d3283e
commit
c392697b4c
@ -24,14 +24,14 @@ export default define(meta, paramDef, async (ps) => {
|
|||||||
patrons = JSON.parse(cachedPatrons);
|
patrons = JSON.parse(cachedPatrons);
|
||||||
} else {
|
} else {
|
||||||
AbortSignal.timeout ??= function timeout(ms) {
|
AbortSignal.timeout ??= function timeout(ms) {
|
||||||
const ctrl = new AbortController()
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), ms)
|
setTimeout(() => ctrl.abort(), ms);
|
||||||
return ctrl.signal
|
return ctrl.signal;
|
||||||
}
|
};
|
||||||
|
|
||||||
patrons = await fetch(
|
patrons = await fetch(
|
||||||
"https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json",
|
"https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json",
|
||||||
{ signal: AbortSignal.timeout(2000) }
|
{ signal: AbortSignal.timeout(2000) },
|
||||||
)
|
)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
@ -34,9 +34,9 @@ export default define(meta, paramDef, async () => {
|
|||||||
const instanceMeta = await fetchMeta();
|
const instanceMeta = await fetchMeta();
|
||||||
if (!instanceMeta.enableServerMachineStats) {
|
if (!instanceMeta.enableServerMachineStats) {
|
||||||
return {
|
return {
|
||||||
machine: 'Not specified',
|
machine: "Not specified",
|
||||||
cpu: {
|
cpu: {
|
||||||
model: 'Not specified',
|
model: "Not specified",
|
||||||
cores: 0,
|
cores: 0,
|
||||||
},
|
},
|
||||||
mem: {
|
mem: {
|
||||||
|
@ -132,9 +132,8 @@ router.get("/identicon/:x", async (ctx) => {
|
|||||||
await genIdenticon(ctx.params.x, fs.createWriteStream(temp));
|
await genIdenticon(ctx.params.x, fs.createWriteStream(temp));
|
||||||
ctx.set("Content-Type", "image/png");
|
ctx.set("Content-Type", "image/png");
|
||||||
ctx.body = fs.createReadStream(temp).on("close", () => cleanup());
|
ctx.body = fs.createReadStream(temp).on("close", () => cleanup());
|
||||||
}
|
} else {
|
||||||
else {
|
ctx.redirect("/static-assets/avatar.png");
|
||||||
ctx.redirect("/static-assets/avatar.png")
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,18 +4,25 @@ import config from "@/config/index.js";
|
|||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
import { Notes, DriveFiles, UserProfiles, Users } from "@/models/index.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 = {
|
const author = {
|
||||||
link: `${config.url}/@${user.username}`,
|
link: `${config.url}/@${user.username}`,
|
||||||
email: `${user.username}@${config.host}`,
|
email: `${user.username}@${config.host}`,
|
||||||
name: user.name || user.username
|
name: user.name || user.username,
|
||||||
};
|
};
|
||||||
|
|
||||||
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
||||||
|
|
||||||
const searchCriteria = {
|
const searchCriteria = {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
visibility: In(['public', 'home']),
|
visibility: In(["public", "home"]),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!renotes) {
|
if (!renotes) {
|
||||||
@ -36,8 +43,12 @@ export default async function (user: User, threadDepth = 5, history = 20, notein
|
|||||||
id: author.link,
|
id: author.link,
|
||||||
title: `${author.name} (@${user.username}@${config.host})`,
|
title: `${author.name} (@${user.username}@${config.host})`,
|
||||||
updated: notes[0].createdAt,
|
updated: notes[0].createdAt,
|
||||||
generator: 'Calckey',
|
generator: "Calckey",
|
||||||
description: `${user.notesCount} Notes, ${profile.ffVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.ffVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
|
description: `${user.notesCount} Notes, ${
|
||||||
|
profile.ffVisibility === "public" ? user.followingCount : "?"
|
||||||
|
} Following, ${
|
||||||
|
profile.ffVisibility === "public" ? user.followersCount : "?"
|
||||||
|
} Followers${profile.description ? ` · ${profile.description}` : ""}`,
|
||||||
link: author.link,
|
link: author.link,
|
||||||
image: await Users.getAvatarUrl(user),
|
image: await Users.getAvatarUrl(user),
|
||||||
feedLinks: {
|
feedLinks: {
|
||||||
@ -61,59 +72,87 @@ export default async function (user: User, threadDepth = 5, history = 20, notein
|
|||||||
|
|
||||||
let title = `${author.name} `;
|
let title = `${author.name} `;
|
||||||
if (note.renoteId) {
|
if (note.renoteId) {
|
||||||
title += 'renotes';
|
title += "renotes";
|
||||||
} else if (note.replyId) {
|
} else if (note.replyId) {
|
||||||
title += 'replies';
|
title += "replies";
|
||||||
} else {
|
} else {
|
||||||
title += 'says';
|
title += "says";
|
||||||
}
|
}
|
||||||
if (noteintitle) {
|
if (noteintitle) {
|
||||||
const content = note.cw ?? note.text;
|
const content = note.cw ?? note.text;
|
||||||
if (content) {
|
if (content) {
|
||||||
title += `: ${content}`;
|
title += `: ${content}`;
|
||||||
} else {
|
} else {
|
||||||
title += 'something';
|
title += "something";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
feed.addItem({
|
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}`,
|
link: `${config.url}/notes/${note.id}`,
|
||||||
date: note.createdAt,
|
date: note.createdAt,
|
||||||
description: note.cw ? note.cw.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '') : undefined,
|
description: note.cw
|
||||||
content: contentStr.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, '')
|
? 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) {
|
async function noteToString(note, isTheNote = false) {
|
||||||
const author = isTheNote ? null : await Users.findOneBy({ id: note.userId });
|
const author = isTheNote
|
||||||
let outstr = author ? `${author.name}(@${author.username}@${author.host ? author.host : config.host}) ${(note.renoteId ? 'renotes' : (note.replyId ? 'replies' : 'says'))}: <br>` : '';
|
? null
|
||||||
const files = note.fileIds.length > 0 ? await DriveFiles.findBy({
|
: await Users.findOneBy({ id: note.userId });
|
||||||
id: In(note.fileIds),
|
let outstr = author
|
||||||
}) : [];
|
? `${author.name}(@${author.username}@${
|
||||||
let fileEle = '';
|
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) {
|
for (const file of files) {
|
||||||
if (file.type.startsWith('image/')) {
|
if (file.type.startsWith("image/")) {
|
||||||
fileEle += ` <br><img src="${DriveFiles.getPublicUrl(file)}">`;
|
fileEle += ` <br><img src="${DriveFiles.getPublicUrl(file)}">`;
|
||||||
} else if (file.type.startsWith('audio/')) {
|
} else if (file.type.startsWith("audio/")) {
|
||||||
fileEle += ` <br><audio controls src="${DriveFiles.getPublicUrl(file)}" type="${file.type}">`;
|
fileEle += ` <br><audio controls src="${DriveFiles.getPublicUrl(
|
||||||
} else if (file.type.startsWith('video/')) {
|
file,
|
||||||
fileEle += ` <br><video controls src="${DriveFiles.getPublicUrl(file)}" type="${file.type}">`;
|
)}" type="${file.type}">`;
|
||||||
|
} else if (file.type.startsWith("video/")) {
|
||||||
|
fileEle += ` <br><video controls src="${DriveFiles.getPublicUrl(
|
||||||
|
file,
|
||||||
|
)}" type="${file.type}">`;
|
||||||
} else {
|
} 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) {
|
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;
|
return outstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findById (id) {
|
async function findById(id) {
|
||||||
let text = '';
|
let text = "";
|
||||||
let next = null;
|
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) {
|
if (findings) {
|
||||||
text += `<hr>`;
|
text += `<hr>`;
|
||||||
text += await noteToString(findings);
|
text += await noteToString(findings);
|
||||||
|
@ -247,7 +247,14 @@ router.get("/api.json", async (ctx) => {
|
|||||||
ctx.body = genOpenapiSpec();
|
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();
|
const meta = await fetchMeta();
|
||||||
if (meta.privateMode) {
|
if (meta.privateMode) {
|
||||||
return;
|
return;
|
||||||
@ -257,7 +264,7 @@ const getFeed = async (acct: string, threadDepth:string, historyCount:string, no
|
|||||||
usernameLower: username.toLowerCase(),
|
usernameLower: username.toLowerCase(),
|
||||||
host: host ?? IsNull(),
|
host: host ?? IsNull(),
|
||||||
isSuspended: false,
|
isSuspended: false,
|
||||||
isLocked:false,
|
isLocked: false,
|
||||||
});
|
});
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return;
|
return;
|
||||||
@ -271,7 +278,17 @@ const getFeed = async (acct: string, threadDepth:string, historyCount:string, no
|
|||||||
if (isNaN(history) || history <= 0 || history > 30) {
|
if (isNaN(history) || history <= 0 || history > 30) {
|
||||||
history = 20;
|
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.
|
// 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
|
// Atom
|
||||||
const atomFeed: Router.Middleware = async (ctx) => {
|
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) {
|
if (feed) {
|
||||||
ctx.set("Content-Type", "application/atom+xml; charset=utf-8");
|
ctx.set("Content-Type", "application/atom+xml; charset=utf-8");
|
||||||
@ -325,7 +349,14 @@ const atomFeed: Router.Middleware = async (ctx) => {
|
|||||||
|
|
||||||
// RSS
|
// RSS
|
||||||
const rssFeed: Router.Middleware = async (ctx) => {
|
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) {
|
if (feed) {
|
||||||
ctx.set("Content-Type", "application/rss+xml; charset=utf-8");
|
ctx.set("Content-Type", "application/rss+xml; charset=utf-8");
|
||||||
@ -337,7 +368,14 @@ const rssFeed: Router.Middleware = async (ctx) => {
|
|||||||
|
|
||||||
// JSON
|
// JSON
|
||||||
const jsonFeed: Router.Middleware = async (ctx) => {
|
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) {
|
if (feed) {
|
||||||
ctx.set("Content-Type", "application/json; charset=utf-8");
|
ctx.set("Content-Type", "application/json; charset=utf-8");
|
||||||
|
@ -29,7 +29,7 @@ export default class ActiveUsersChart extends Chart<typeof schema> {
|
|||||||
id: User["id"];
|
id: User["id"];
|
||||||
host: null;
|
host: null;
|
||||||
createdAt: User["createdAt"];
|
createdAt: User["createdAt"];
|
||||||
}) {
|
}) {
|
||||||
this.commit({
|
this.commit({
|
||||||
read: [user.id],
|
read: [user.id],
|
||||||
registeredWithinWeek:
|
registeredWithinWeek:
|
||||||
|
@ -12,15 +12,14 @@
|
|||||||
><i class="ph-warning ph-bold ph-lg"></i>
|
><i class="ph-warning ph-bold ph-lg"></i>
|
||||||
{{ i18n.ts.sensitive }}</b
|
{{ i18n.ts.sensitive }}</b
|
||||||
>
|
>
|
||||||
<span style="display: block">{{ i18n.ts.clickToShow }}</span>
|
<span style="display: block">{{
|
||||||
|
i18n.ts.clickToShow
|
||||||
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<a
|
<a v-if="media.type.startsWith('image')" :href="media.url">
|
||||||
v-if="media.type.startsWith('image')"
|
|
||||||
:href="media.url"
|
|
||||||
>
|
|
||||||
<ImgWithBlurhash
|
<ImgWithBlurhash
|
||||||
:hash="media.blurhash"
|
:hash="media.blurhash"
|
||||||
:src="url"
|
:src="url"
|
||||||
@ -132,7 +131,7 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.media.type.startsWith('video')) {
|
if (props.media.type.startsWith("video")) {
|
||||||
plyrMini.value = plyr.value.player.media.scrollWidth < 300;
|
plyrMini.value = plyr.value.player.media.scrollWidth < 300;
|
||||||
if (plyrMini.value) {
|
if (plyrMini.value) {
|
||||||
plyr.value.player.on("play", () => {
|
plyr.value.player.on("play", () => {
|
||||||
|
@ -174,7 +174,7 @@ let patrons = [];
|
|||||||
try {
|
try {
|
||||||
patrons = await os.api("patrons", { forceUpdate: true });
|
patrons = await os.api("patrons", { forceUpdate: true });
|
||||||
} catch {
|
} catch {
|
||||||
console.error("Codeberg's down.")
|
console.error("Codeberg's down.");
|
||||||
}
|
}
|
||||||
|
|
||||||
let easterEggReady = false;
|
let easterEggReady = false;
|
||||||
|
@ -455,7 +455,7 @@ let patrons = [];
|
|||||||
try {
|
try {
|
||||||
patrons = await os.api("patrons");
|
patrons = await os.api("patrons");
|
||||||
} catch {
|
} catch {
|
||||||
console.error("Codeberg's down.")
|
console.error("Codeberg's down.");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parallaxLoop() {
|
function parallaxLoop() {
|
||||||
|
Loading…
Reference in New Issue
Block a user