This repository was archived by the owner on Sep 17, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +2873
-19
lines changed
migrations/20240522003232_initial_setup Expand file tree Collapse file tree 9 files changed +2873
-19
lines changed Original file line number Diff line number Diff line change 1+ -- AlterTable
2+ ALTER TABLE " User" ADD COLUMN " avatarUploadId" UUID;
Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ datasource db {
44}
55
66model User {
7- id String @id @default (uuid () ) @db.Uuid
8- username String @unique
9- createdAt DateTime @default (now () )
10- updatedAt DateTime @updatedAt
7+ id String @id @default (uuid () ) @db.Uuid
8+ username String @unique
9+ createdAt DateTime @default (now () )
10+ updatedAt DateTime @updatedAt
11+
12+ avatarUploadId String ? @db.Uuid
1113}
Original file line number Diff line number Diff line change 77authors :
88 - rivet-gg
99 - NathanFlurry
10+ - Blckbrry-Pi
1011status : stable
1112dependencies :
1213 rate_limit : {}
1314 tokens : {}
15+ uploads : {}
1416scripts :
1517 get_user :
1618 name : Get User
@@ -24,8 +26,22 @@ scripts:
2426 create_user_token :
2527 name : Create User Token
2628 description : Create a token for a user to authenticate future requests.
29+ set_profile_picture :
30+ name : Set Profile Picture
31+ description : Set the profile picture for a user.
32+ public : true
33+ prepare_profile_picture :
34+ name : Start Profile Picture Upload
35+ description : Allow the user to begin uploading a profile picture.
36+ public : true
2737errors :
2838 token_not_user_token :
2939 name : Token Not User Token
3040 unknown_identity_type :
3141 name : Unknown Identity Type
42+ invalid_mime_type :
43+ name : Invalid MIME Type
44+ description : The MIME type for the supposed PFP isn't an image
45+ file_too_large :
46+ name : File Too Large
47+ description : The file is larger than the configured maximum size for a profile picture
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export interface Request {
66}
77
88export interface Response {
9- user : User ;
9+ user : Omit < User , "profilePictureUrl" > ;
1010}
1111
1212export async function run (
@@ -20,10 +20,16 @@ export async function run(
2020 data : {
2121 username : req . username ?? generateUsername ( ) ,
2222 } ,
23+ select : {
24+ id : true ,
25+ username : true ,
26+ createdAt : true ,
27+ updatedAt : true ,
28+ } ,
2329 } ) ;
2430
2531 return {
26- user,
32+ user : user ,
2733 } ;
2834}
2935
Original file line number Diff line number Diff line change 11import { ScriptContext } from "../module.gen.ts" ;
22import { User } from "../utils/types.ts" ;
3+ import { withPfpUrls } from "../utils/pfp.ts" ;
34
45export interface Request {
56 userIds : string [ ] ;
@@ -20,5 +21,8 @@ export async function run(
2021 orderBy : { username : "desc" } ,
2122 } ) ;
2223
23- return { users } ;
24+
25+ const usersWithPfps = await withPfpUrls ( ctx , users ) ;
26+
27+ return { users : usersWithPfps } ;
2428}
Original file line number Diff line number Diff line change @@ -4,23 +4,14 @@ import { User } from "./types.ts";
44const EXPIRY_SECS = 60 * 60 * 24 ; // 1 day
55
66type UserWithUploadidInfo = Omit < User , "profilePictureUrl" > & { avatarUploadId : string | null } ;
7- type FileRef = { uploadId : string ; path : string } ;
8-
9- function getFileRefs ( users : UserWithUploadidInfo [ ] ) {
10- const pairs : FileRef [ ] = [ ] ;
11- for ( const { avatarUploadId : uploadId } of users ) {
12- if ( uploadId ) {
13- pairs . push ( { uploadId : uploadId , path : "profile-picture" } ) ;
14- }
15- }
16- return pairs ;
17- }
187
198export async function withPfpUrls < T extends ModuleContext > (
209 ctx : T ,
2110 users : UserWithUploadidInfo [ ] ,
2211) : Promise < User [ ] > {
23- const fileRefs = getFileRefs ( users ) ;
12+ const fileRefs = users
13+ . filter ( user => user . avatarUploadId )
14+ . map ( user => ( { uploadId : user . avatarUploadId ! , path : "profile-picture" } ) ) ;
2415
2516 const { files } = await ctx . modules . uploads . getPublicFileUrls ( {
2617 files : fileRefs ,
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ export interface User {
33 username : string ;
44 createdAt : Date ;
55 updatedAt : Date ;
6+ profilePictureUrl : string | null ;
67}
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ modules:
1313 registry : local
1414 users :
1515 registry : local
16+ config :
17+ maxProfilePictureBytes : 1048576 # 1 MiB
1618 uploads :
1719 registry : local
1820 config :
You can’t perform that action at this time.
0 commit comments