1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-12-03 10:59:13 -05:00
shimapan/app/routes/api/upload.js

35 lines
863 B
JavaScript
Raw Normal View History

const express = require('express');
const router = express.Router();
const config = require('config');
2017-10-09 22:01:02 -04:00
2018-08-01 11:54:35 -04:00
const ModelPath = '../../models/';
2018-07-26 19:01:16 -04:00
const Upload = require(ModelPath + 'Upload.js');
2018-07-28 12:19:38 -04:00
2018-08-01 11:54:35 -04:00
const uploadMultipart = require('../../util/upload/multipart');
const updateStats = require('../../util/upload/stats');
2017-10-09 22:01:02 -04:00
2018-08-01 11:54:35 -04:00
const wrap = require('../../util/wrap.js');
2018-07-26 13:17:37 -04:00
router.post('/', uploadMultipart, wrap(async (req, res) => {
2018-07-26 13:17:37 -04:00
const upload = {
id: req.file.name,
uploader: req.username,
uploaderKey: req.key,
2018-07-26 13:17:37 -04:00
date: Date.now(),
file: req.file
};
await Promise.all([
Upload.create(upload),
updateStats(req)
]);
res.status(200).json({
2018-07-27 14:26:55 -04:00
message: 'File uploaded.',
id: req.file.name,
url: config.get('Server.hostname') + '/v/' + upload.id
2017-10-09 22:01:02 -04:00
});
2018-07-26 13:17:37 -04:00
}));
2017-10-09 22:01:02 -04:00
module.exports = router;