Update button styling and render additional elements on file page if authenticated
This commit is contained in:
@@ -119,9 +119,16 @@ export const pageRoutes: FastifyPluginAsync<{ deps: Deps }> = async (app, { deps
|
||||
reply.redirect('/files');
|
||||
});
|
||||
|
||||
// GET /f/:id — public file view
|
||||
// GET /f/:id — public file view (owner-aware)
|
||||
app.get<{ Params: { id: string } }>('/f/:id', async (request, reply) => {
|
||||
const { id } = request.params;
|
||||
|
||||
let userId: number | null = null;
|
||||
try {
|
||||
await request.jwtVerify();
|
||||
userId = (request.user as JwtPayload).sub;
|
||||
} catch { /* not logged in — fine */ }
|
||||
|
||||
const file = getFileById(db, id);
|
||||
|
||||
if (!file) {
|
||||
@@ -129,7 +136,8 @@ export const pageRoutes: FastifyPluginAsync<{ deps: Deps }> = async (app, { deps
|
||||
return reply.status(404).type('text/html').send(notFoundPage());
|
||||
}
|
||||
|
||||
reply.type('text/html').send(fileViewPage(file));
|
||||
const isOwner = userId !== null && userId === file.user_id;
|
||||
reply.type('text/html').send(fileViewPage(file, isOwner));
|
||||
});
|
||||
|
||||
// GET /f/:id/raw — serve raw file
|
||||
|
||||
Reference in New Issue
Block a user