|
- // Copyright (c) 2020 Jan Kaßel
- // Copyright (c) 2022 Gerben
- //
- // SPDX-License-Identifier: MIT
-
- import type { Request, Response } from 'express';
- import db from '../db.js';
- import { renderUser } from '../render/renderUser.js';
- import { getPrefixedEntries } from '../util.js';
- import users from '../../config/users.json';
- import { CollectionInfo } from './collection.js';
-
- export async function getUser(req: Request, res: Response) {
- const name = req.params.user;
- if (!(name in users)) {
- res.status(404).send('Not found');
- return;
- }
- try {
- const collections: CollectionInfo[] = (await getPrefixedEntries(db, `${name}/`, true)).map(
- ([_, value]) => value,
- );
-
- const user = {
- name,
- collections,
- };
-
- res.format({
- html: () => renderUser(req, res, user),
- default: () => res.send(user),
- });
- } catch (err: any) {
- console.error(req.method, req.path, err);
- res.status(500).send('Internal Server Error');
- }
- }
|