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

Commit 260b431

Browse files
Blckbrry-PiNathanFlurry
authored andcommitted
feat(users): users profile pictures
1 parent fa4f889 commit 260b431

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 { 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.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScriptContext, RuntimeError } from "../module.gen.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.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"users": {
2323
"registry": "local",
2424
"config": {
25-
"maxProfilePictureBytes": 1048576
25+
"maxProfilePictureSize": "1mib"
2626
}
2727
},
2828
"uploads": {

0 commit comments

Comments
 (0)