delete.js 528 B

12345678910111213141516171819202122
  1. const storage = require('../storage');
  2. const { statDeleteEvent } = require('../amplitude');
  3. module.exports = async function(req, res) {
  4. try {
  5. const id = req.params.id;
  6. const meta = req.meta;
  7. const ttl = await storage.ttl(id);
  8. await storage.del(id);
  9. res.sendStatus(200);
  10. statDeleteEvent({
  11. id,
  12. ip: req.ip,
  13. owner: meta.owner,
  14. download_count: meta.dl,
  15. ttl,
  16. agent: req.ua.browser.name || req.ua.ua.substring(0, 6)
  17. });
  18. } catch (e) {
  19. res.sendStatus(404);
  20. }
  21. };