Skip to content

Commit

Permalink
Added version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
fishdev committed Jan 25, 2019
1 parent 0ccb596 commit 9832004
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
32 changes: 32 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"author": "QuantumStack",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
Expand Down
5 changes: 5 additions & 0 deletions server/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const json2csv = require('json2csv').parse;
const User = require('./../models/User');
const Entry = require('./../models/Entry');
const adminRequired = require('./../util/adminRequired');
const version = require('./../util/version');

const router = express.Router();

Expand All @@ -17,6 +18,7 @@ router.get('/lab', adminRequired, (req, res) => {
course: process.env.CMULAB_COURSE,
loc: process.env.CMULAB_LOC,
isLab: true,
version: version(),
});
});

Expand All @@ -25,6 +27,7 @@ router.get('/csv', adminRequired, (req, res) => {
course: process.env.CMULAB_COURSE,
loc: process.env.CMULAB_LOC,
isCsv: true,
version: version(),
});
});

Expand All @@ -33,6 +36,7 @@ router.get('/delete', adminRequired, (req, res) => {
course: process.env.CMULAB_COURSE,
loc: process.env.CMULAB_LOC,
isDelete: true,
version: version(),
});
});

Expand All @@ -44,6 +48,7 @@ router.get('/users', adminRequired, (req, res, next) => {
loc: process.env.CMULAB_LOC,
isUsers: true,
users,
version: version(),
});
});
});
Expand Down
22 changes: 22 additions & 0 deletions server/util/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const axios = require('axios');

const current = 'v1.0';
let latest;

function check() {
axios.get('https://api.github.com/repos/QuantumStack/CMULab/releases')
.then((res) => {
latest = res.data[0].tag_name;
})
.catch(() => {
latest = current;
});
}

check();
setInterval(check, 86400000);

module.exports = () => {
if (current === latest) return { update: false };
return { update: true, latest, current };
};
18 changes: 17 additions & 1 deletion server/views/admin.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
<br />
<center><a href="/" class="tag is-primary is-large is-rounded">CMULab</a> &nbsp;<span class="title is-5"> {{course}}</span></center>
<br />

{{#if version.update}}
<section class="section">
<div class="container">
<article class="message is-warning">
<div class="message-header">
<p>CMULab Update Available!</p>
</div>
<div class="message-body">
QuantumStack has released a <strong>new version</strong> of CMULab. You are currently using {{version.current}}, but <strong>{{version.latest}}</strong> is now available. Please visit our <a href="https://github.com/QuantumStack/CMULab">GitHub repository</a> to download the update and deploy it onto your CMULab instance. Go to the <a href="https://github.com/QuantumStack/CMULab/releases/tag/{{version.latest}}">release page</a> to see what's new.
</div>
</article>
</div>
</section>
{{else}}
<br />
{{/if}}

<div class="tabs is-centered is-boxed is-small">
<ul>
Expand Down

0 comments on commit 9832004

Please sign in to comment.