Merge pull request #83 from gruppe-adler/multi-upload

multi missions file upload
This commit is contained in:
Björn Dahlgren 2017-10-02 10:34:26 +02:00 committed by GitHub
commit b1bb295d57
3 changed files with 26 additions and 16 deletions

View File

@ -9,7 +9,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Download Mission</h3>
<h3 class="panel-title">Download Missions</h3>
</div>
<div class="panel-body" id="workshop"></div>
</div>

View File

@ -1,7 +1,14 @@
<form class="form" role="form" enctype="multipart/form-data">
<div class="form-group">
<label for="mission" class="control-label">Mission File</label>
<input type="file" class="form-control path" name="mission" id="mission" data-field="mission">
<label for="missions" class="control-label">Mission Files</label>
<input multiple="multiple"
accept=".pbo"
type="file"
class="form-control path"
name="missions"
id="missions"
data-field="missions"
>
<span class="help-block">Only supports missions packed as a PBO</span>
</div>
<button type="submit" class="btn btn-primary ladda-button" data-style="expand-left">

View File

@ -1,6 +1,7 @@
var express = require('express')
var multer = require('multer')
var upload = multer({ storage: multer.diskStorage({}) })
var async = require('async')
module.exports = function (missionsManager) {
var router = express.Router()
@ -15,20 +16,22 @@ module.exports = function (missionsManager) {
})
})
router.post('/', upload.single('mission'), function (req, res) {
var missionFile = req.file
if (!missionFile) {
return res.status(400).send('No mission file uploaded')
}
missionsManager.handleUpload(missionFile, function (err) {
if (err) {
res.status(500).send(err)
} else {
res.status(200).json({success: true})
router.post('/', upload.array('missions', 64), function (req, res) {
async.parallelLimit(
req.files.map(function (missionFile) {
return function (next) {
missionsManager.handleUpload(missionFile, next)
}
}),
8,
function (err) {
if (err) {
res.status(500).send(err)
} else {
res.status(200).json({success: true})
}
}
})
)
})
router.get('/:mission', function (req, res) {