2018-07-26 16:54:08 -04:00
|
|
|
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
|
|
|
|
2019-01-02 16:49:56 -05:00
|
|
|
|
|
|
|
|
2019-01-02 14:25:51 -05:00
|
|
|
router.post('/', uploadMultipart, 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,
|
2018-07-26 19:40:42 -04:00
|
|
|
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
|
|
|
});
|
2019-01-02 14:25:51 -05:00
|
|
|
});
|
2017-10-09 22:01:02 -04:00
|
|
|
|
2019-01-02 16:49:56 -05:00
|
|
|
|
|
|
|
|
2017-10-09 22:01:02 -04:00
|
|
|
module.exports = router;
|