Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit d24daf9

Browse files
committed
feat(users): Update users config to use UploadSize from `uploads
1 parent f496b8f commit d24daf9

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

modules/uploads/public.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const __CANONICAL_MODULE_NAME = "uploads";
2+
3+
export type { UploadSize } from "./utils/data_size.ts";
4+
export { getBytes } from "./utils/data_size.ts";

modules/users/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { Public } from "./_gen/mod.ts";
2+
13
export interface Config {
2-
maxProfilePictureBytes: number;
4+
maxProfilePictureSize: Public.Uploads.UploadSize;
35
allowedMimes?: string[];
46
}
57

modules/users/scripts/prepare_profile_picture_upload.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScriptContext, RuntimeError } from "../_gen/scripts/prepare_profile_picture_upload.ts";
1+
import { ScriptContext, RuntimeError, Public } from "../_gen/scripts/prepare_profile_picture_upload.ts";
22
import { DEFAULT_MIME_TYPES } from "../config.ts";
33

44
export interface Request {
@@ -30,7 +30,8 @@ export async function run(
3030
}
3131

3232
// Ensure the file is within the maximum configured size for a PFP
33-
if (BigInt(req.contentLength) > ctx.userConfig.maxProfilePictureBytes) {
33+
const maxBytes = Public.Uploads.getBytes(ctx.userConfig.maxProfilePictureSize);
34+
if (BigInt(req.contentLength) > maxBytes) {
3435
throw new RuntimeError(
3536
"file_too_large",
3637
{ cause: `File is too large (${req.contentLength} bytes)` },

tests/basic/backend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ modules:
1414
users:
1515
registry: local
1616
config:
17-
maxProfilePictureBytes: 1048576 # 1 MiB
17+
maxProfilePictureSize: 1mib
1818
uploads:
1919
registry: local
2020
config:

0 commit comments

Comments
 (0)