Skip to content

Commit

Permalink
Fix baseUri/uploadAppPath handling. (closes #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
psi-4ward committed Dec 4, 2020
1 parent 1283b86 commit 152b324
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/src/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
data () {
return {
files: [],
sid: document.location.href.substr(this.$root.baseURI.length),
sid: document.location.href.substr(this.$root.baseURI.length + 1),
baseURI: this.$root.baseURI,
passwordWrong: false,
needsPassword: false,
Expand Down Expand Up @@ -129,7 +129,7 @@
downloadAll(format) {
document.location.href = this.$root.baseURI
+ 'files/' + this.sid + '++'
+ '/files/' + this.sid + '++'
+ MD5(
this.files
.filter(f => !f.downloaded || f.metadata.retention !== 'one-time')
Expand Down
2 changes: 1 addition & 1 deletion app/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Vue.component('icon', Icon);
new Vue({
el: '#upload',
data: {
baseURI: document.head.getElementsByTagName('base')[0].href,
baseURI: document.head.getElementsByTagName('base')[0].href.replace(/\/$/),
configFetched: false,
lang: {},
},
Expand Down
34 changes: 29 additions & 5 deletions lib/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ app.get(`${ config.baseUrl }`, (req, res) => {
if (config.uploadAppPath !== `${ config.baseUrl }`) {
res.status(304).redirect(config.uploadAppPath);
} else {
res.send(uploadPage({...pugVars, lang: req.translations}));
res.send(uploadPage({
...pugVars,
baseUrl: config.uploadAppPath || config.baseUrl,
lang: req.translations
}));
}
});

Expand Down Expand Up @@ -192,10 +196,20 @@ app.get(`${ config.baseUrl }files/:fid`, async (req, res, next) => {
const format = req.params.fid.endsWith('.zip') ? 'zip' : 'tar.gz';
const bucket = db.get(sid);

if (!bucket) return res.status(404).send(errorPage({ ...pugVars, error: 'Download bucket not found.', lang: req.translations }));
if (!bucket) return res.status(404).send(errorPage({
...pugVars,
error: 'Download bucket not found.',
lang: req.translations,
uploadAppPath: config.uploadAppPath || config.baseUrl,
}));

if (req.params.fid !== sid + '++' + MD5(bucket.map(f => f.key).join()).toString() + '.' + format) {
res.status(404).send(errorPage({ ...pugVars, error: 'Invalid link', lang: req.translations }));
res.status(404).send(errorPage({
...pugVars,
error: 'Invalid link',
uploadAppPath: config.uploadAppPath || config.baseUrl,
lang: req.translations,
}));
return;
}
debug(`Download Bucket ${ sid }`);
Expand Down Expand Up @@ -273,7 +287,12 @@ app.get(`${ config.baseUrl }files/:fid`, async (req, res, next) => {
});
}
catch (e) {
res.status(404).send(errorPage({ ...pugVars, error: e.message, lang: req.translations }));
res.status(404).send(errorPage({
...pugVars,
error: e.message,
lang: req.translations,
uploadAppPath: config.uploadAppPath || config.baseUrl,
}));
}
});

Expand Down Expand Up @@ -359,7 +378,12 @@ app.use(`${ config.baseUrl }files`,
);

app.use((req, res, next) => {
res.status(404).send(errorPage({ ...pugVars, error: 'Download bucket not found.', lang: req.translations }));
res.status(404).send(errorPage({
...pugVars,
error: 'Download bucket not found.',
uploadAppPath: config.uploadAppPath || config.baseUrl,
lang: req.translations
}));
});

module.exports = app;
2 changes: 1 addition & 1 deletion public/pug/error.pug
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ html(lang='en')
i.fa.fa-fw.fa-exclamation-triangle
| #{error}
p
a.btn.btn-sm.btn-info(title='New Upload' href='/')
a.btn.btn-sm.btn-info(title='New Upload' href=uploadAppPath)
i.fa.fa-fw.fa-cloud-upload
| new upload
include partials/footer

0 comments on commit 152b324

Please sign in to comment.