mirror of
https://github.com/Foltik/Shimapan
synced 2024-12-02 18:48:32 -05:00
35 lines
863 B
JavaScript
35 lines
863 B
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const config = require('config');
|
|
|
|
const ModelPath = '../../models/';
|
|
const Upload = require(ModelPath + 'Upload.js');
|
|
|
|
const uploadMultipart = require('../../util/upload/multipart');
|
|
const updateStats = require('../../util/upload/stats');
|
|
|
|
const wrap = require('../../util/wrap.js');
|
|
|
|
router.post('/', uploadMultipart, wrap(async (req, res) => {
|
|
const upload = {
|
|
id: req.file.name,
|
|
uploader: req.username,
|
|
uploaderKey: req.key,
|
|
date: Date.now(),
|
|
file: req.file
|
|
};
|
|
|
|
await Promise.all([
|
|
Upload.create(upload),
|
|
updateStats(req)
|
|
]);
|
|
|
|
res.status(200).json({
|
|
message: 'File uploaded.',
|
|
id: req.file.name,
|
|
url: config.get('Server.hostname') + '/v/' + upload.id
|
|
});
|
|
}));
|
|
|
|
module.exports = router;
|