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

Commit

Permalink
Merge pull request #112 from SpringRoll/release/1.10.0
Browse files Browse the repository at this point in the history
Release/1.10.0
  • Loading branch information
chipbell4 authored Apr 15, 2020
2 parents 2877379 + a4cbe07 commit 062c02a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ SpringRoll Connect is a content management system built using [NodeJS](https://n

## License

Copyright (c) 2018 [SpringRoll](https://github.com/SpringRoll)
Copyright (c) 2020 [SpringRoll](https://github.com/SpringRoll)

Released under the MIT License.
4 changes: 3 additions & 1 deletion app/models/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ ReleaseSchema.statics.getByGame = function(slug, options, callback) {
);

function addUrl(r) {
let isDebug = options.debug !== undefined && JSON.parse(options.debug) === true;

r.url =
r.game.location +
'/' +
r.commitId +
'/' +
(options.debug ? 'debug' : 'release') +
(isDebug ? 'debug' : 'release') +
(options.archive ? '.zip' : '/index.html');
}

Expand Down
4 changes: 4 additions & 0 deletions app/routes/api/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ router.get('/:slugOrBundleId', cache, function(req, res) {
// If the request was for a dev game without a token, it's a 403
log.warn(`Request for game "${req.params.slugOrBundleId}" without token`);
return res.status(403).send({ success: false, error: err });
} else if (err.toLowerCase() === 'unauthorized token') {
// The request has provided a token but does not have access to this game
log.warn(`Unauthorized request for game "${req.params.slugOrBundleId}" using token "${req.query.token}"`);
return res.status(403).send({ success: false, error: err });
} else {
// Otherwise, we don't know what it is so it's probably a 500
log.warn(err);
Expand Down
50 changes: 39 additions & 11 deletions app/routes/games/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const async = require('async'),
log = require('../../helpers/logger'),
Game = require('../../models/game'),
User = require('../../models/user');
http = require('http'),
https = require('https'),
log = require('../../helpers/logger'),
Game = require('../../models/game'),
User = require('../../models/user');

/**
* Abstraction to handle the page errors
Expand All @@ -22,17 +24,31 @@ function handleError(req, res, errors)
}

function validateRequest(req){
req.checkBody('title', 'Title is required').notEmpty();
req.checkBody('title', 'Title is required').notEmpty();
req.checkBody('bundleId', 'Bundle ID is required').isBundleId();
req.checkBody('slug', 'Slug is required').isSlug();
req.checkBody('repository', 'Repository needs to be a URL').isURL();
req.checkBody('location', 'Location needs to be a URL').isURL();
req.checkBody('description').optional();
req.checkBody('thumbnail').optional();
var errors = req.validationErrors();
req.checkBody('thumbnail').optional();
var errors = req.validationErrors();
return errors ? errors : false;
}

/**
* Convert bytes into a human readable format
* source: https://stackoverflow.com/a/20732091/10236401
* thanks andrew!
*
* @param {integer} size file size that we want to convert
* @return {string} file size in human readable format
*/
function niceFileSize(size) {
const i = Math.floor( Math.log(size) / Math.log(1024) );

return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}

/**
* Abstraction to render a page, takes care of all
* of the access control and populate the page with
Expand All @@ -49,14 +65,14 @@ function renderPage(req, res, template, populate=null)
[
function(done)
{
var game = Game.getBySlug(req.params.slug, done);
if (populate){
game.populate({
var game = Game.getBySlug(req.params.slug, done);
if (populate){
game.populate({
path: populate,
options: { sort: { 'updated': -1 } }
});
};
},
},
function(game, done)
{
if (!game){
Expand All @@ -66,7 +82,7 @@ function renderPage(req, res, template, populate=null)
game.getAccess(req.user, done);
}
],
function(err, game, access)
async function(err, game, access)
{
if (err)
{
Expand All @@ -89,6 +105,18 @@ function renderPage(req, res, template, populate=null)
: Number(req.query.page)
: 1;

// iterate game releases to add file sizes
for (let k = 0; k < game.releases.length; k++) {
const compressedSize = parseInt(game.releases[k].releaseCompressedSize || 0);
if (compressedSize > 0) {
game.releases[k].releaseCompressedSize = niceFileSize(compressedSize);
}
const uncompressedSize = parseInt(game.releases[k].releaseUncompressedSize || 0);
if (uncompressedSize > 0) {
game.releases[k].releaseUncompressedSize = niceFileSize(uncompressedSize);
}
}

res.render(template, {
game: game,
page: pageIndex,
Expand Down
8 changes: 8 additions & 0 deletions app/views/games/releases.jade
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ append gameContent
a(href="#{game.repository}/browse?at=refs/heads/#{release.branch.replace('origin/', '')}" data-toggle="tooltip" title="View Branch")=' '+release.branch

.help-block.updated
if release.releaseCompressedSize
span Compressed Size: &nbsp;
span.file-size=((release.releaseCompressedSize / 1024 / 1024).toFixed(2) + ' MB')
br
if release.releaseUncompressedSize
span Uncompressed Size: &nbsp;
span.file-size=((release.releaseUncompressedSize / 1024 / 1024).toFixed(2) + ' MB')
br
span Updated &nbsp;
span=moment(release.updated).fromNow()
if release.updatedBy
Expand Down
Loading

0 comments on commit 062c02a

Please sign in to comment.