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

Commit

Permalink
feat(users): users profile pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
Blckbrry-Pi authored and NathanFlurry committed Jun 10, 2024
1 parent d7a5892 commit eaf3316
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions modules/uploads/public.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const __CANONICAL_MODULE_NAME = "uploads";

export type { UploadSize } from "./utils/data_size.ts";
export { getBytes } from "./utils/data_size.ts";
4 changes: 3 additions & 1 deletion modules/users/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Module } from "./module.gen.ts";

export interface Config {
maxProfilePictureBytes: number;
maxProfilePictureSize: Module.uploads.UploadSize;
allowedMimes?: string[];
}

Expand Down
5 changes: 3 additions & 2 deletions modules/users/scripts/prepare_profile_picture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScriptContext, RuntimeError } from "../module.gen.ts";
import { ScriptContext, RuntimeError, Module } from "../module.gen.ts";
import { DEFAULT_MIME_TYPES } from "../config.ts";

export interface Request {
Expand Down Expand Up @@ -30,7 +30,8 @@ export async function run(
}

// Ensure the file is within the maximum configured size for a PFP
if (BigInt(req.contentLength) > ctx.userConfig.maxProfilePictureBytes) {
const maxBytes = Module.uploads.getBytes(ctx.userConfig.maxProfilePictureSize);
if (BigInt(req.contentLength) > maxBytes) {
throw new RuntimeError(
"file_too_large",
{ cause: `File is too large (${req.contentLength} bytes)` },
Expand Down
2 changes: 1 addition & 1 deletion tests/basic/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"users": {
"registry": "local",
"config": {
"maxProfilePictureBytes": 1048576
"maxProfilePictureSize": "1mib"
}
},
"uploads": {
Expand Down

0 comments on commit eaf3316

Please sign in to comment.