mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Fix SIGSEGV bug!!
This commit is contained in:
parent
9514deb330
commit
63b13ca5e8
|
|
@ -9,7 +9,6 @@ import type { StatusWithRelations } from "./Status";
|
|||
/**
|
||||
* Represents a Like entity in the database.
|
||||
*/
|
||||
|
||||
export const toLysand = (like: Like): LysandLike => {
|
||||
return {
|
||||
id: like.id,
|
||||
|
|
@ -21,6 +20,11 @@ export const toLysand = (like: Like): LysandLike => {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a like
|
||||
* @param user User liking the status
|
||||
* @param status Status being liked
|
||||
*/
|
||||
export const createLike = async (
|
||||
user: UserWithRelations,
|
||||
status: StatusWithRelations
|
||||
|
|
@ -47,6 +51,11 @@ export const createLike = async (
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a like
|
||||
* @param user User deleting their like
|
||||
* @param status Status being unliked
|
||||
*/
|
||||
export const deleteLike = async (
|
||||
user: UserWithRelations,
|
||||
status: StatusWithRelations
|
||||
|
|
@ -68,7 +77,7 @@ export const deleteLike = async (
|
|||
},
|
||||
});
|
||||
|
||||
if (user.instanceId === null) {
|
||||
if (user.instanceId === null && status.author.instanceId !== null) {
|
||||
// User is local, federate the delete
|
||||
// TODO: Federate this
|
||||
}
|
||||
|
|
|
|||
3
index.ts
3
index.ts
|
|
@ -4,7 +4,6 @@ import type { MatchedRoute } from "bun";
|
|||
import chalk from "chalk";
|
||||
import { appendFile } from "fs/promises";
|
||||
import { matches } from "ip-matching";
|
||||
import "reflect-metadata";
|
||||
import type { AuthData } from "~database/entities/User";
|
||||
import { getFromRequest } from "~database/entities/User";
|
||||
import type { APIRouteMeta } from "~types/api";
|
||||
|
|
@ -121,7 +120,7 @@ Bun.serve({
|
|||
}
|
||||
}
|
||||
|
||||
return file.default(req, matchedRoute, auth);
|
||||
return await file.default(req.clone(), matchedRoute, auth);
|
||||
} else {
|
||||
return new Response(undefined, {
|
||||
status: 404,
|
||||
|
|
|
|||
|
|
@ -78,10 +78,7 @@
|
|||
"isomorphic-dompurify": "^1.9.0",
|
||||
"jsonld": "^8.3.1",
|
||||
"marked": "^9.1.2",
|
||||
"pg": "^8.11.3",
|
||||
"prisma": "latest",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sharp": "^0.32.6",
|
||||
"typeorm": "^0.3.17"
|
||||
"sharp": "^0.32.6"
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
export async function parseRequest<T>(request: Request): Promise<Partial<T>> {
|
||||
const query = new URL(request.url).searchParams;
|
||||
let output: Partial<T> = {};
|
||||
|
||||
// Parse SearchParams arrays into JSON arrays
|
||||
const arrayKeys = [...query.keys()].filter(key => key.endsWith("[]"));
|
||||
|
|
@ -17,24 +18,46 @@ export async function parseRequest<T>(request: Request): Promise<Partial<T>> {
|
|||
query.append(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
// If body is empty
|
||||
if (request.body === null) {
|
||||
return {};
|
||||
const queryEntries = [...query.entries()];
|
||||
|
||||
if (queryEntries.length > 0) {
|
||||
const data: Record<string, string | string[]> = {};
|
||||
|
||||
const arrayKeys = [...query.keys()].filter(key => key.endsWith("[]"));
|
||||
|
||||
for (const key of arrayKeys) {
|
||||
const value = query.getAll(key);
|
||||
query.delete(key);
|
||||
// @ts-expect-error JSON arrays are valid
|
||||
data[key] = JSON.parse(value);
|
||||
}
|
||||
|
||||
output = {
|
||||
...output,
|
||||
...(data as T),
|
||||
};
|
||||
}
|
||||
|
||||
// if request contains a JSON body
|
||||
if (request.headers.get("Content-Type")?.includes("application/json")) {
|
||||
return (await request.json()) as T;
|
||||
try {
|
||||
output = {
|
||||
...output,
|
||||
...((await request.json()) as T),
|
||||
};
|
||||
} catch {
|
||||
// Invalid JSON
|
||||
}
|
||||
}
|
||||
|
||||
// If request contains FormData
|
||||
if (request.headers.get("Content-Type")?.includes("multipart/form-data")) {
|
||||
const formData = await request.formData();
|
||||
const formData = [...(await request.formData()).entries()];
|
||||
|
||||
if ([...formData.entries()].length > 0) {
|
||||
if (formData.length > 0) {
|
||||
const data: Record<string, string | File> = {};
|
||||
|
||||
for (const [key, value] of formData.entries()) {
|
||||
for (const [key, value] of formData) {
|
||||
// If object, parse as JSON
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-base-to-string
|
||||
|
|
@ -51,23 +74,12 @@ export async function parseRequest<T>(request: Request): Promise<Partial<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
return data as T;
|
||||
output = {
|
||||
...output,
|
||||
...(data as T),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ([...query.entries()].length > 0) {
|
||||
const data: Record<string, string | string[]> = {};
|
||||
|
||||
for (const [key, value] of query.entries()) {
|
||||
try {
|
||||
data[key] = JSON.parse(value) as string[];
|
||||
} catch {
|
||||
data[key] = value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return data as T;
|
||||
}
|
||||
|
||||
return {};
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue