Skip to content

Commit 49575d3

Browse files
committed
separate pfp from normal pic
1 parent fe4bf7f commit 49575d3

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

server/src/database/picture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function set(guid: GUID, buf: Buffer): Promise<Result<string>> {
1717
})
1818
.then(() => {
1919
// ?update=${date} is necessary to let the browsers properly cache the image.
20-
const pictureUrl = `/picture/${guid}?update=${new Date().getTime()}`;
20+
const pictureUrl = `/picture/profile/${guid}?update=${new Date().getTime()}`;
2121
return Ok(pictureUrl);
2222
})
2323
.catch((err) => {

server/src/router/picture.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import * as storage from "../database/picture";
44
import { safeGetGUID } from "../firebase/auth/lib";
55
import { compressImage } from "../functions/img/compress";
66

7-
// TODO: truncate file at frontend s.t. even the largest file won't trigger the limit
87
const parseLargeBuffer = bodyParser.raw({
98
type: "image/png",
10-
// TODO: block large files (larger than 1mb? idk)
119
limit: "5mb",
1210
});
1311
const router = express.Router();
1412

15-
router.get("/:guid", async (req, res) => {
13+
/* General Pictures in chat */
14+
15+
/* Profile Pictures */
16+
17+
router.get("/profile/:guid", async (req, res) => {
1618
const guid = req.params.guid;
1719
const result = await storage.get(guid);
1820
switch (result.ok) {
@@ -23,7 +25,7 @@ router.get("/:guid", async (req, res) => {
2325
}
2426
});
2527

26-
router.post("/", parseLargeBuffer, async (req, res) => {
28+
router.post("/profile", parseLargeBuffer, async (req, res) => {
2729
const guid = await safeGetGUID(req);
2830
if (!guid.ok) return res.status(401).send();
2931

web/src/api/internal/endpoints.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,13 @@ export const message = (messageId: MessageID) =>
359359
/**
360360
* GET: get profile picture of URL (this is usually hard-encoded in pictureURL so this variable is barely used)
361361
*/
362-
export const pictureOf = (guid: GUID) => `${origin}/picture/${guid}`;
362+
export const profilePictureOf = (guid: GUID) =>
363+
`${origin}/picture/profile/${guid}`;
363364

364365
/**
365366
* POST: update my profile picture.
366367
*/
367-
export const picture = `${origin}/picture`;
368+
export const profilePicture = `${origin}/picture/profile`;
368369

369370
export default {
370371
user,
@@ -393,6 +394,6 @@ export default {
393394
message,
394395
coursesMine,
395396
coursesMineOverlaps,
396-
pictureOf,
397-
picture,
397+
profilePictureOf,
398+
profilePicture,
398399
};

web/src/api/internal/fetch-func.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ export async function uploadImage(file: File): Promise<URL> {
2626
if (file.size >= MAX_IMAGE_SIZE) {
2727
throw new Error("画像のアップロードに失敗しました: 画像が大きすぎます");
2828
}
29-
const res = await fetch(`${endpoints.picture}?token=${await getIdToken()}`, {
30-
method: "POST",
31-
headers: {
32-
"Content-Type": "image/png",
29+
const res = await fetch(
30+
`${endpoints.profilePicture}?token=${await getIdToken()}`,
31+
{
32+
method: "POST",
33+
headers: {
34+
"Content-Type": "image/png",
35+
},
36+
body: file,
3337
},
34-
body: file,
35-
});
38+
);
3639
if (res.status !== 201)
3740
throw new Error(
3841
`Unexpected status code: expected 201, but got ${res.status}`,

0 commit comments

Comments
 (0)