💾 Archived View for iich.space › src › app › images.ts captured on 2021-12-03 at 14:04:38.

View Raw

More Information

-=-=-=-=-=-=-

import { readFile } from 'fs/promises';

import { Status } from '@/gemini';
import { Handler, Router } from '@/mission-control';

const router = new Router<Handler>();

router.use('/:id.png', async (_, res, { params }) => {
  const id = params.id.replace(/[^a-zA-Z0-9]/g, '');
  const path = `./images/${id}.png`;

  try {
    const data = await readFile(path);
    res.sendStatus(Status.SUCCESS, 'image/png');
    res.send(data);
    res.end();
  } catch (error) {
    res.sendStatus(Status.NOT_FOUND);
    res.end();
  }
});

export default router;