Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 062c02a

Browse files
authored
Merge pull request #112 from SpringRoll/release/1.10.0
Release/1.10.0
2 parents 2877379 + a4cbe07 commit 062c02a

File tree

9 files changed

+136
-63
lines changed

9 files changed

+136
-63
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ SpringRoll Connect is a content management system built using [NodeJS](https://n
2020

2121
## License
2222

23-
Copyright (c) 2018 [SpringRoll](https://github.com/SpringRoll)
23+
Copyright (c) 2020 [SpringRoll](https://github.com/SpringRoll)
2424

2525
Released under the MIT License.

app/models/release.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ ReleaseSchema.statics.getByGame = function(slug, options, callback) {
233233
);
234234

235235
function addUrl(r) {
236+
let isDebug = options.debug !== undefined && JSON.parse(options.debug) === true;
237+
236238
r.url =
237239
r.game.location +
238240
'/' +
239241
r.commitId +
240242
'/' +
241-
(options.debug ? 'debug' : 'release') +
243+
(isDebug ? 'debug' : 'release') +
242244
(options.archive ? '.zip' : '/index.html');
243245
}
244246

app/routes/api/release.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ router.get('/:slugOrBundleId', cache, function(req, res) {
215215
// If the request was for a dev game without a token, it's a 403
216216
log.warn(`Request for game "${req.params.slugOrBundleId}" without token`);
217217
return res.status(403).send({ success: false, error: err });
218+
} else if (err.toLowerCase() === 'unauthorized token') {
219+
// The request has provided a token but does not have access to this game
220+
log.warn(`Unauthorized request for game "${req.params.slugOrBundleId}" using token "${req.query.token}"`);
221+
return res.status(403).send({ success: false, error: err });
218222
} else {
219223
// Otherwise, we don't know what it is so it's probably a 500
220224
log.warn(err);

app/routes/games/helpers.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const async = require('async'),
2-
log = require('../../helpers/logger'),
3-
Game = require('../../models/game'),
4-
User = require('../../models/user');
2+
http = require('http'),
3+
https = require('https'),
4+
log = require('../../helpers/logger'),
5+
Game = require('../../models/game'),
6+
User = require('../../models/user');
57

68
/**
79
* Abstraction to handle the page errors
@@ -22,17 +24,31 @@ function handleError(req, res, errors)
2224
}
2325

2426
function validateRequest(req){
25-
req.checkBody('title', 'Title is required').notEmpty();
27+
req.checkBody('title', 'Title is required').notEmpty();
2628
req.checkBody('bundleId', 'Bundle ID is required').isBundleId();
2729
req.checkBody('slug', 'Slug is required').isSlug();
2830
req.checkBody('repository', 'Repository needs to be a URL').isURL();
2931
req.checkBody('location', 'Location needs to be a URL').isURL();
3032
req.checkBody('description').optional();
31-
req.checkBody('thumbnail').optional();
32-
var errors = req.validationErrors();
33+
req.checkBody('thumbnail').optional();
34+
var errors = req.validationErrors();
3335
return errors ? errors : false;
3436
}
3537

38+
/**
39+
* Convert bytes into a human readable format
40+
* source: https://stackoverflow.com/a/20732091/10236401
41+
* thanks andrew!
42+
*
43+
* @param {integer} size file size that we want to convert
44+
* @return {string} file size in human readable format
45+
*/
46+
function niceFileSize(size) {
47+
const i = Math.floor( Math.log(size) / Math.log(1024) );
48+
49+
return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
50+
}
51+
3652
/**
3753
* Abstraction to render a page, takes care of all
3854
* of the access control and populate the page with
@@ -49,14 +65,14 @@ function renderPage(req, res, template, populate=null)
4965
[
5066
function(done)
5167
{
52-
var game = Game.getBySlug(req.params.slug, done);
53-
if (populate){
54-
game.populate({
68+
var game = Game.getBySlug(req.params.slug, done);
69+
if (populate){
70+
game.populate({
5571
path: populate,
5672
options: { sort: { 'updated': -1 } }
5773
});
5874
};
59-
},
75+
},
6076
function(game, done)
6177
{
6278
if (!game){
@@ -66,7 +82,7 @@ function renderPage(req, res, template, populate=null)
6682
game.getAccess(req.user, done);
6783
}
6884
],
69-
function(err, game, access)
85+
async function(err, game, access)
7086
{
7187
if (err)
7288
{
@@ -89,6 +105,18 @@ function renderPage(req, res, template, populate=null)
89105
: Number(req.query.page)
90106
: 1;
91107

108+
// iterate game releases to add file sizes
109+
for (let k = 0; k < game.releases.length; k++) {
110+
const compressedSize = parseInt(game.releases[k].releaseCompressedSize || 0);
111+
if (compressedSize > 0) {
112+
game.releases[k].releaseCompressedSize = niceFileSize(compressedSize);
113+
}
114+
const uncompressedSize = parseInt(game.releases[k].releaseUncompressedSize || 0);
115+
if (uncompressedSize > 0) {
116+
game.releases[k].releaseUncompressedSize = niceFileSize(uncompressedSize);
117+
}
118+
}
119+
92120
res.render(template, {
93121
game: game,
94122
page: pageIndex,

app/views/games/releases.jade

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ append gameContent
9696
a(href="#{game.repository}/browse?at=refs/heads/#{release.branch.replace('origin/', '')}" data-toggle="tooltip" title="View Branch")=' '+release.branch
9797

9898
.help-block.updated
99+
if release.releaseCompressedSize
100+
span Compressed Size: &nbsp;
101+
span.file-size=((release.releaseCompressedSize / 1024 / 1024).toFixed(2) + ' MB')
102+
br
103+
if release.releaseUncompressedSize
104+
span Uncompressed Size: &nbsp;
105+
span.file-size=((release.releaseUncompressedSize / 1024 / 1024).toFixed(2) + ' MB')
106+
br
99107
span Updated &nbsp;
100108
span=moment(release.updated).fromNow()
101109
if release.updatedBy

0 commit comments

Comments
 (0)