Merge pull request #18 from Dahlgren/feature/steam-workshop

Download missions from Steam Workshop
This commit is contained in:
Björn Dahlgren 2015-08-15 17:16:14 +02:00
commit 47629c5f4d
10 changed files with 104 additions and 7 deletions

1
app.js
View File

@ -33,6 +33,7 @@ app.resource('api/mods', modsRoutes);
var serversResource = app.resource('api/servers', serversRoutes);
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/search', modsRoutes.search);
app.get('/api/servers/:server/start', serversRoutes.start);

View File

@ -19,6 +19,7 @@
"playwithsix": "0.0.10",
"slug": "~0.4.0",
"socket.io": "^1.0.4",
"steam-workshop": "0.0.1",
"userhome": "^1.0.0",
"when": "~3.1.0"
},

View File

@ -6,7 +6,8 @@ define(function (require) {
_ = require('underscore'),
Backbone = require('backbone'),
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'),
tpl = require('text!tpl/missions/index.html');
@ -14,12 +15,14 @@ define(function (require) {
template: _.template(tpl),
regions: {
formView: "#form",
uploadView: "#upload",
workshopView: "#workshop",
listView: "#list",
},
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}));
},
});

View File

@ -10,7 +10,7 @@ define(function (require) {
Ladda = require('ladda'),
IframeTransport = require('jquery.iframe-transport'),
Mission = require('app/models/mission'),
tpl = require('text!tpl/missions/form.html');
tpl = require('text!tpl/missions/upload.html');
return Marionette.ItemView.extend({
template: _.template(tpl),
@ -33,7 +33,7 @@ define(function (require) {
submit: function () {
var self = this;
var $form = $('form');
var $form = this.$el.find('form');
this.laddaBtn.start();

View 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();
},
});
},
});
});

View File

@ -1,4 +1,9 @@
<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>

View 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>

View File

@ -9,7 +9,9 @@ exports.index = function(req, res){
res.send(err);
} else {
var missions = files.map(function (filename) {
return { name: filename }
return {
name: filename,
};
});
res.send(missions);
}

16
routes/workshop.js Normal file
View 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});
}
});
};