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

35 lines
866 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 = {
2018-09-15 16:20:14 -04:00
uid: 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.',
2018-09-15 16:20:14 -04:00
uid: req.file.name,
url: config.get('Server.hostname') + '/v/' + upload.uid
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;