Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.
This repository was archived by the owner on May 22, 2021. It is now read-only.

[style] use async/await #325

@dannycoates

Description

@dannycoates

It might be fun to use async/await syntax on the server.

Here's a sample snippet:

app.get('/download/:id', async (req, res) => {
  const id = req.params.id;
  if (!validateID(id)) {
    return res.sendStatus(404);
  }
  try {
    const filename = await storage.filename(id);
    const contentLength = await storage.length(id);
    const timeToExpiry = await storage.ttl(id);
    res.render('download', {
      filename: decodeURIComponent(filename),
      filesize: bytes(contentLength),
      sizeInBytes: contentLength,
      timeToExpiry: timeToExpiry
    });
  } catch (e) {
    res.status(404).render('notfound');
  }
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions