mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Merge pull request #18 from Dahlgren/feature/steam-workshop
Download missions from Steam Workshop
This commit is contained in:
commit
47629c5f4d
1
app.js
1
app.js
@ -33,6 +33,7 @@ app.resource('api/mods', modsRoutes);
|
|||||||
var serversResource = app.resource('api/servers', serversRoutes);
|
var serversResource = app.resource('api/servers', serversRoutes);
|
||||||
app.resource('api/settings', require('./routes/settings'));
|
app.resource('api/settings', require('./routes/settings'));
|
||||||
|
|
||||||
|
app.post('/api/missions/workshop', require('./routes/workshop').mission);
|
||||||
app.post('/api/mods/refresh', modsRoutes.refresh);
|
app.post('/api/mods/refresh', modsRoutes.refresh);
|
||||||
app.post('/api/mods/search', modsRoutes.search);
|
app.post('/api/mods/search', modsRoutes.search);
|
||||||
app.get('/api/servers/:server/start', serversRoutes.start);
|
app.get('/api/servers/:server/start', serversRoutes.start);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"playwithsix": "0.0.10",
|
"playwithsix": "0.0.10",
|
||||||
"slug": "~0.4.0",
|
"slug": "~0.4.0",
|
||||||
"socket.io": "^1.0.4",
|
"socket.io": "^1.0.4",
|
||||||
|
"steam-workshop": "0.0.1",
|
||||||
"userhome": "^1.0.0",
|
"userhome": "^1.0.0",
|
||||||
"when": "~3.1.0"
|
"when": "~3.1.0"
|
||||||
},
|
},
|
||||||
|
@ -6,7 +6,8 @@ define(function (require) {
|
|||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
Backbone = require('backbone'),
|
Backbone = require('backbone'),
|
||||||
Marionette = require('marionette'),
|
Marionette = require('marionette'),
|
||||||
FormView = require('app/views/missions/form'),
|
UploadView = require('app/views/missions/upload'),
|
||||||
|
WorkshopView = require('app/views/missions/workshop'),
|
||||||
ListView = require('app/views/missions/list'),
|
ListView = require('app/views/missions/list'),
|
||||||
tpl = require('text!tpl/missions/index.html');
|
tpl = require('text!tpl/missions/index.html');
|
||||||
|
|
||||||
@ -14,12 +15,14 @@ define(function (require) {
|
|||||||
template: _.template(tpl),
|
template: _.template(tpl),
|
||||||
|
|
||||||
regions: {
|
regions: {
|
||||||
formView: "#form",
|
uploadView: "#upload",
|
||||||
|
workshopView: "#workshop",
|
||||||
listView: "#list",
|
listView: "#list",
|
||||||
},
|
},
|
||||||
|
|
||||||
onRender: function() {
|
onRender: function() {
|
||||||
this.formView.show(new FormView({missions: this.options.missions}));
|
this.uploadView.show(new UploadView({missions: this.options.missions}));
|
||||||
|
this.workshopView.show(new WorkshopView({missions: this.options.missions}));
|
||||||
this.listView.show(new ListView({collection: this.options.missions}));
|
this.listView.show(new ListView({collection: this.options.missions}));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -10,7 +10,7 @@ define(function (require) {
|
|||||||
Ladda = require('ladda'),
|
Ladda = require('ladda'),
|
||||||
IframeTransport = require('jquery.iframe-transport'),
|
IframeTransport = require('jquery.iframe-transport'),
|
||||||
Mission = require('app/models/mission'),
|
Mission = require('app/models/mission'),
|
||||||
tpl = require('text!tpl/missions/form.html');
|
tpl = require('text!tpl/missions/upload.html');
|
||||||
|
|
||||||
return Marionette.ItemView.extend({
|
return Marionette.ItemView.extend({
|
||||||
template: _.template(tpl),
|
template: _.template(tpl),
|
||||||
@ -33,7 +33,7 @@ define(function (require) {
|
|||||||
|
|
||||||
submit: function () {
|
submit: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
var $form = $('form');
|
var $form = this.$el.find('form');
|
||||||
|
|
||||||
this.laddaBtn.start();
|
this.laddaBtn.start();
|
||||||
|
|
58
public/js/app/views/missions/workshop.js
Normal file
58
public/js/app/views/missions/workshop.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
define(function (require) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var $ = require('jquery'),
|
||||||
|
_ = require('underscore'),
|
||||||
|
Backbone = require('backbone'),
|
||||||
|
Marionette = require('marionette'),
|
||||||
|
FormView = require('marionette-formview'),
|
||||||
|
Ladda = require('ladda'),
|
||||||
|
IframeTransport = require('jquery.iframe-transport'),
|
||||||
|
Mission = require('app/models/mission'),
|
||||||
|
tpl = require('text!tpl/missions/workshop.html');
|
||||||
|
|
||||||
|
return Marionette.ItemView.extend({
|
||||||
|
template: _.template(tpl),
|
||||||
|
|
||||||
|
events: {
|
||||||
|
'click form button': 'submit',
|
||||||
|
},
|
||||||
|
|
||||||
|
initialize: function (options) {
|
||||||
|
this.missions = options.missions;
|
||||||
|
},
|
||||||
|
|
||||||
|
onShow: function () {
|
||||||
|
var $okBtn = this.$el.find('form button[type=submit]');
|
||||||
|
$okBtn.addClass('ladda-button').attr('data-style', 'expand-left');
|
||||||
|
|
||||||
|
this.laddaBtn = Ladda.create($okBtn.get(0));
|
||||||
|
},
|
||||||
|
|
||||||
|
submit: function () {
|
||||||
|
var self = this;
|
||||||
|
var $form = this.$el.find('form');
|
||||||
|
|
||||||
|
this.laddaBtn.start();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/missions/workshop',
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
id: $form.find("input.workshop").val(),
|
||||||
|
},
|
||||||
|
dataType: 'json',
|
||||||
|
success: function (data) {
|
||||||
|
self.missions.fetch({success : function () {
|
||||||
|
self.laddaBtn.stop();
|
||||||
|
self.render();
|
||||||
|
}});
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
self.laddaBtn.stop();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
@ -1,4 +1,9 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 col-md-push-8" id="form"></div>
|
<div class="col-md-4 col-md-push-8">
|
||||||
|
<h4>Upload Mission</h4>
|
||||||
|
<div id="upload"></div>
|
||||||
|
<h4>Download Mission</h4>
|
||||||
|
<div id="workshop"></div>
|
||||||
|
</div>
|
||||||
<div class="col-md-8 col-md-pull-4" id="list"></div>
|
<div class="col-md-8 col-md-pull-4" id="list"></div>
|
||||||
</div>
|
</div>
|
||||||
|
11
public/js/tpl/missions/workshop.html
Normal file
11
public/js/tpl/missions/workshop.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<form class="form" role="form" enctype="multipart/form-data">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="workshop" class="control-label">Steam Workshop ID</label>
|
||||||
|
<input type="number" class="form-control workshop" name="workshop" id="workshop" data-field="workshop">
|
||||||
|
<span class="help-block">
|
||||||
|
ID can be found in the URL of Workshop i.e.
|
||||||
|
<i>https://steamcommunity.com/workshop/filedetails/?id=$id</i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Download</button>
|
||||||
|
</form>
|
@ -9,7 +9,9 @@ exports.index = function(req, res){
|
|||||||
res.send(err);
|
res.send(err);
|
||||||
} else {
|
} else {
|
||||||
var missions = files.map(function (filename) {
|
var missions = files.map(function (filename) {
|
||||||
return { name: filename }
|
return {
|
||||||
|
name: filename,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
res.send(missions);
|
res.send(missions);
|
||||||
}
|
}
|
||||||
|
16
routes/workshop.js
Normal file
16
routes/workshop.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
var path = require('path');
|
||||||
|
var SteamWorkshop = require('steam-workshop');
|
||||||
|
|
||||||
|
var config = require('./../config');
|
||||||
|
|
||||||
|
exports.mission = function(req, res){
|
||||||
|
var outputFolder = path.join(config.path, 'mpmissions');
|
||||||
|
var steamWorkshop = new SteamWorkshop(outputFolder);
|
||||||
|
steamWorkshop.downloadFile(req.body.id, function (err, files) {
|
||||||
|
if (err) {
|
||||||
|
res.json(500, {success: false});
|
||||||
|
} else {
|
||||||
|
res.json({success: true});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user