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

Commit baea5c0

Browse files
Blckbrry-PiNathanFlurry
authored andcommitted
feat(users): Update users config to use UploadSize from `uploads
1 parent f378b0b commit baea5c0

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

modules/uploads/module.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
name: Uploads
2+
description: Upload & store files in an object store.
3+
icon: file-arrow-up
4+
tags:
5+
- core
6+
- utility
7+
authors:
8+
- rivet-gg
9+
- Blckbrry-Pi
10+
- NathanFlurry
11+
status: stable
112
scripts:
213
prepare:
314
name: Prepare Upload

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 { Module } from "./module.gen.ts";
2+
13
export interface Config {
2-
maxProfilePictureBytes: number;
4+
maxProfilePictureSize: Module.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, Module } from "../module.gen.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 = Module.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)