diff --git a/src/server/lib/schemas/accounts.ts b/src/server/lib/schemas/accounts.ts index 7ff9699..64052b6 100644 --- a/src/server/lib/schemas/accounts.ts +++ b/src/server/lib/schemas/accounts.ts @@ -1,5 +1,6 @@ import {z} from "zod" import { FileId, FileVisibility } from "./files.js" +import { RGBHex } from "./misc.js" export const StringPassword = z.string().min(8,"password must be at least 8 characters") export const Password = @@ -46,7 +47,7 @@ export namespace Settings { barSide: BarSide.default("left") }) export const Links = z.object({ - color: z.string().toLowerCase().length(6).regex(/^[a-f0-9]+$/,"illegal characters").optional(), + color: RGBHex.optional(), largeImage: z.boolean().default(false) }) export const User = z.object({ diff --git a/src/server/lib/schemas/misc.ts b/src/server/lib/schemas/misc.ts new file mode 100644 index 0000000..7eea94d --- /dev/null +++ b/src/server/lib/schemas/misc.ts @@ -0,0 +1,3 @@ +import { z } from "zod"; + +export const RGBHex = z.string().toLowerCase().length(6).regex(/^[a-f0-9]+$/,"illegal characters") \ No newline at end of file diff --git a/src/server/routes/api/v1/file/index.ts b/src/server/routes/api/v1/file/index.ts index bf254a9..f943450 100644 --- a/src/server/routes/api/v1/file/index.ts +++ b/src/server/routes/api/v1/file/index.ts @@ -13,6 +13,7 @@ import pkg from "../../../../lib/package.js" import { type StatusCode } from "hono/utils/http-status" import { z } from "zod" import { FileSchemas } from "../../../../lib/schemas/index.js" +import config from "../../../../lib/config.js" const router = new Hono<{ Variables: { @@ -54,6 +55,9 @@ export default function(files: Files) { if (!ctx.req.raw.body) return resolve(ctx.body("body must be supplied", 400)) + if (config.accounts.requiredForUpload && !acc) + return resolve(ctx.body("instance requires you to be authenticated to upload files", 401)) + let file = files.createWriteStream(acc?.id) file