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

Commit 43d7a67

Browse files
committed
feat(users): users profile pictures
1 parent c86878b commit 43d7a67

File tree

8 files changed

+2870
-7
lines changed

8 files changed

+2870
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "User" ADD COLUMN "avatarUploadId" UUID;

modules/users/db/schema.prisma

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ datasource db {
44
}
55

66
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
1113
}

modules/users/module.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ tags:
77
authors:
88
- rivet-gg
99
- NathanFlurry
10+
- Blckbrry-Pi
1011
status: stable
1112
dependencies:
1213
rate_limit: {}
1314
tokens: {}
15+
uploads: {}
1416
scripts:
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
2737
errors:
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

modules/users/scripts/create_user.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface Request {
66
}
77

88
export interface Response {
9-
user: User;
9+
user: Omit<User, "profilePictureUrl">;
1010
}
1111

1212
export 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

modules/users/scripts/get_user.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ScriptContext } from "../module.gen.ts";
22
import { User } from "../utils/types.ts";
3+
import { withPfpUrls } from "../utils/pfp.ts";
34

45
export 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
}

modules/users/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export interface User {
33
username: string;
44
createdAt: Date;
55
updatedAt: Date;
6+
profilePictureUrl: string | null;
67
}

tests/basic/backend.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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:

tests/basic/deno.lock

Lines changed: 2830 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)