Store and publish annotations on the web, as described in the Web Annotation Discovery proposal.

user.ts 981 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) 2020 Jan Kaßel
  2. // Copyright (c) 2022 Gerben
  3. //
  4. // SPDX-License-Identifier: MIT
  5. import type { Request, Response } from 'express';
  6. import db from '../db.js';
  7. import { renderUser } from '../render/renderUser.js';
  8. import { getPrefixedEntries } from '../util.js';
  9. import users from '../../config/users.json';
  10. import { CollectionInfo } from './collection.js';
  11. export async function getUser(req: Request, res: Response) {
  12. const name = req.params.user;
  13. if (!(name in users)) {
  14. res.status(404).send('Not found');
  15. return;
  16. }
  17. try {
  18. const collections: CollectionInfo[] = (await getPrefixedEntries(db, `${name}/`, true)).map(
  19. ([_, value]) => value,
  20. );
  21. const user = {
  22. name,
  23. collections,
  24. };
  25. res.format({
  26. html: () => renderUser(req, res, user),
  27. default: () => res.send(user),
  28. });
  29. } catch (err: any) {
  30. console.error(req.method, req.path, err);
  31. res.status(500).send('Internal Server Error');
  32. }
  33. }