add user avatars, delete, set, view
This commit is contained in:
parent
cc4ebfbdd0
commit
f14daf041a
6 changed files with 560 additions and 0 deletions
44
config/sql/avatars.ts
Normal file
44
config/sql/avatars.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 6;
|
||||
|
||||
export async function createTable(reservation?: ReservedSQL): Promise<void> {
|
||||
let selfReservation: boolean = false;
|
||||
|
||||
if (!reservation) {
|
||||
reservation = await sql.reserve();
|
||||
selfReservation = true;
|
||||
}
|
||||
|
||||
try {
|
||||
await reservation`
|
||||
CREATE TABLE IF NOT EXISTS avatars (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
owner UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
mime_type VARCHAR(255) NOT NULL,
|
||||
extension VARCHAR(255) NOT NULL,
|
||||
size BIGINT NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW() NOT NULL
|
||||
);
|
||||
`;
|
||||
} catch (error) {
|
||||
logger.error(["Could not create the avatars table:", error as Error]);
|
||||
throw error;
|
||||
} finally {
|
||||
if (selfReservation) {
|
||||
reservation.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isValidTypeOrExtension(
|
||||
type: string,
|
||||
extension: string,
|
||||
): boolean {
|
||||
return (
|
||||
["image/jpeg", "image/png", "image/gif", "image/webp"].includes(type) &&
|
||||
["jpeg", "jpg", "png", "gif", "webp"].includes(extension)
|
||||
);
|
||||
}
|
|
@ -15,6 +15,8 @@ const defaultSettings: Setting[] = [
|
|||
{ key: "random_name_length", value: "8" },
|
||||
{ key: "enable_thumbnails", value: "true" },
|
||||
{ key: "index_page_stats", value: "true" },
|
||||
{ key: "instance_name", value: "Atums World" },
|
||||
{ key: "max_avatar_size", value: "10000000" }, // 10 MB
|
||||
];
|
||||
|
||||
export async function createTable(reservation?: ReservedSQL): Promise<void> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue