This repository was archived by the owner on Sep 17, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +51
-22
lines changed
migrations/20240522003232_initial_setup Expand file tree Collapse file tree 8 files changed +51
-22
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 {
4
4
}
5
5
6
6
model 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
11
13
}
Original file line number Diff line number Diff line change 8
8
],
9
9
"authors" : [
10
10
" rivet-gg" ,
11
- " NathanFlurry"
11
+ " NathanFlurry" ,
12
+ " Blckbrry-Pi"
12
13
],
13
14
"status" : " stable" ,
14
15
"dependencies" : {
15
16
"rate_limit" : {},
16
- "tokens" : {}
17
+ "tokens" : {},
18
+ "uploads" : {}
17
19
},
18
20
"scripts" : {
19
21
"get_user" : {
31
33
"create_user_token" : {
32
34
"name" : " Create User Token" ,
33
35
"description" : " Create a token for a user to authenticate future requests."
36
+ },
37
+ "set_profile_picture" : {
38
+ "name" : " Set Profile Picture" ,
39
+ "description" : " Set the profile picture for a user." ,
40
+ "public" : true
41
+ },
42
+ "prepare_profile_picture" : {
43
+ "name" : " Start Profile Picture Upload" ,
44
+ "description" : " Allow the user to begin uploading a profile picture." ,
45
+ "public" : true
34
46
}
35
47
},
36
48
"errors" : {
39
51
},
40
52
"unknown_identity_type" : {
41
53
"name" : " Unknown Identity Type"
54
+ },
55
+ "invalid_mime_type" : {
56
+ "name" : " Invalid MIME Type" ,
57
+ "description" : " The MIME type for the supposed PFP isn't an image"
58
+ },
59
+ "file_too_large" : {
60
+ "name" : " File Too Large" ,
61
+ "description" : " The file is larger than the configured maximum size for a profile picture"
42
62
}
43
63
}
44
64
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export interface Request {
6
6
}
7
7
8
8
export interface Response {
9
- user : User ;
9
+ user : Omit < User , "profilePictureUrl" > ;
10
10
}
11
11
12
12
export async function run (
@@ -20,10 +20,16 @@ export async function run(
20
20
data : {
21
21
username : req . username ?? generateUsername ( ) ,
22
22
} ,
23
+ select : {
24
+ id : true ,
25
+ username : true ,
26
+ createdAt : true ,
27
+ updatedAt : true ,
28
+ } ,
23
29
} ) ;
24
30
25
31
return {
26
- user,
32
+ user : user ,
27
33
} ;
28
34
}
29
35
Original file line number Diff line number Diff line change 1
1
import { ScriptContext } from "../module.gen.ts" ;
2
2
import { User } from "../utils/types.ts" ;
3
+ import { withPfpUrls } from "../utils/pfp.ts" ;
3
4
4
5
export interface Request {
5
6
userIds : string [ ] ;
@@ -20,5 +21,8 @@ export async function run(
20
21
orderBy : { username : "desc" } ,
21
22
} ) ;
22
23
23
- return { users } ;
24
+
25
+ const usersWithPfps = await withPfpUrls ( ctx , users ) ;
26
+
27
+ return { users : usersWithPfps } ;
24
28
}
Original file line number Diff line number Diff line change @@ -4,23 +4,14 @@ import { User } from "./types.ts";
4
4
const EXPIRY_SECS = 60 * 60 * 24 ; // 1 day
5
5
6
6
type 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
- }
18
7
19
8
export async function withPfpUrls < T extends ModuleContext > (
20
9
ctx : T ,
21
10
users : UserWithUploadidInfo [ ] ,
22
11
) : 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" } ) ) ;
24
15
25
16
const { files } = await ctx . modules . uploads . getPublicFileUrls ( {
26
17
files : fileRefs ,
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ export interface User {
3
3
username : string ;
4
4
createdAt : Date ;
5
5
updatedAt : Date ;
6
+ profilePictureUrl : string | null ;
6
7
}
Original file line number Diff line number Diff line change 20
20
"registry" : " local"
21
21
},
22
22
"users" : {
23
- "registry" : " local"
23
+ "registry" : " local" ,
24
+ "config" : {
25
+ "maxProfilePictureBytes" : 1048576
26
+ }
24
27
},
25
28
"uploads" : {
26
29
"registry" : " local" ,
You can’t perform that action at this time.
0 commit comments