Merge branch 'master' into fix/password-mfacode-schemas

This commit is contained in:
TomatoCake 2024-08-29 10:40:45 +02:00 committed by GitHub
commit 1d98b2ff5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 6 deletions

View File

@ -54,6 +54,8 @@ export const NO_AUTHORIZATION_ROUTES = [
/GET \/guilds\/\d+\/widget\.(json|png)/, /GET \/guilds\/\d+\/widget\.(json|png)/,
// Connections // Connections
/POST \/connections\/\w+\/callback/, /POST \/connections\/\w+\/callback/,
// Image proxy
/GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/,
]; ];
export const API_PREFIX = /^\/api(\/v\d+)?/; export const API_PREFIX = /^\/api(\/v\d+)?/;

View File

@ -67,7 +67,12 @@ export async function ImageProxy(req: Request, res: Response) {
if (!crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(path[0]))) if (!crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(path[0])))
throw new Error("Invalid signature"); throw new Error("Invalid signature");
} catch { } catch {
console.log("Invalid signature, expected " + hash + " got " + path[0]); console.log(
"[ImageProxy] Invalid signature, expected " +
hash +
" but got " +
path[0],
);
res.status(403).send("Invalid signature"); res.status(403).send("Invalid signature");
return; return;
} }
@ -75,7 +80,7 @@ export async function ImageProxy(req: Request, res: Response) {
const abort = new AbortController(); const abort = new AbortController();
setTimeout(() => abort.abort(), 5000); setTimeout(() => abort.abort(), 5000);
const request = await fetch(path.slice(2).join("/"), { const request = await fetch("https://" + path.slice(2).join("/"), {
headers: { headers: {
"User-Agent": "SpacebarImageProxy/1.0.0 (https://spacebar.chat)", "User-Agent": "SpacebarImageProxy/1.0.0 (https://spacebar.chat)",
}, },

View File

@ -179,6 +179,7 @@ router.get(
const pins = await Message.find({ const pins = await Message.find({
where: { channel_id: channel_id, pinned: true }, where: { channel_id: channel_id, pinned: true },
relations: ["author"],
}); });
res.send(pins); res.send(pins);

View File

@ -68,7 +68,6 @@ async function getMembers(guild_id: string, range: [number, number]) {
if (!Array.isArray(range) || range.length !== 2) { if (!Array.isArray(range) || range.length !== 2) {
throw new Error("range is not a valid array"); throw new Error("range is not a valid array");
} }
// TODO: wait for typeorm to implement ordering for .find queries https://github.com/typeorm/typeorm/issues/2620
let members: Member[] = []; let members: Member[] = [];
try { try {
@ -82,11 +81,11 @@ async function getMembers(guild_id: string, range: [number, number]) {
.leftJoinAndSelect("user.sessions", "session") .leftJoinAndSelect("user.sessions", "session")
.addSelect("user.settings") .addSelect("user.settings")
.addSelect( .addSelect(
"CASE WHEN session.status = 'offline' THEN 0 ELSE 1 END", "CASE WHEN session.status IS NULL OR session.status = 'offline' OR session.status = 'invisible' THEN 0 ELSE 1 END",
"_status", "_status",
) )
.orderBy("role.position", "DESC") .orderBy("_status", "DESC")
.addOrderBy("_status", "DESC") .addOrderBy("role.position", "DESC")
.addOrderBy("user.username", "ASC") .addOrderBy("user.username", "ASC")
.offset(Number(range[0]) || 0) .offset(Number(range[0]) || 0)
.limit(Number(range[1]) || 100) .limit(Number(range[1]) || 100)