fix: use presigned S3 URLs for avatar images instead of /uploads/ paths
Avatar images were rendered via /uploads/ which doesn't exist since the S3 migration. Now the server enriches profile responses with avatarImageUrl (presigned S3 URL) and the frontend uses it directly. Also fixed the public profile page at /users/:id. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
listApiKeys,
|
||||
} from "../services/auth.service.ts";
|
||||
import { updateProfile } from "../services/profile.service.ts";
|
||||
import { getImageUrl } from "../services/storage.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any; userId?: number } };
|
||||
|
||||
@@ -97,7 +98,12 @@ app.put(
|
||||
const data = c.req.valid("json");
|
||||
const updated = await updateProfile(db, userId, data);
|
||||
if (!updated) return c.json({ error: "User not found" }, 404);
|
||||
return c.json(updated);
|
||||
return c.json({
|
||||
...updated,
|
||||
avatarImageUrl: updated.avatarUrl
|
||||
? await getImageUrl(updated.avatarUrl)
|
||||
: null,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
import { Hono } from "hono";
|
||||
import { parseId } from "../lib/params.ts";
|
||||
import { getPublicProfile } from "../services/profile.service.ts";
|
||||
import { getImageUrl } from "../services/storage.service.ts";
|
||||
|
||||
type Env = { Variables: { db?: any; userId?: number } };
|
||||
|
||||
async function enrichAvatarUrl<T extends { avatarUrl: string | null }>(
|
||||
record: T,
|
||||
): Promise<T & { avatarImageUrl: string | null }> {
|
||||
return {
|
||||
...record,
|
||||
avatarImageUrl: record.avatarUrl
|
||||
? await getImageUrl(record.avatarUrl)
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
const app = new Hono<Env>();
|
||||
|
||||
// GET /:id/profile — Public profile (no auth required)
|
||||
@@ -15,7 +27,7 @@ app.get("/:id/profile", async (c) => {
|
||||
const profile = await getPublicProfile(db, id);
|
||||
if (!profile) return c.json({ error: "User not found" }, 404);
|
||||
|
||||
return c.json(profile);
|
||||
return c.json(await enrichAvatarUrl(profile));
|
||||
});
|
||||
|
||||
export { app as profileRoutes };
|
||||
|
||||
Reference in New Issue
Block a user