Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

expired ids should reject instead of returning null #311

Merged
merged 3 commits into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions frontend/src/fileReceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class FileReceiver extends EventEmitter {

xhr.onload = function(event) {
if (xhr.status === 404) {
reject(
new Error('notfound')
);
reject(new Error('notfound'));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ $(document).ready(function() {
event.preventDefault();

// don't allow upload if not on upload page
if ($('#page-one').attr('hidden')){
if ($('#page-one').attr('hidden')) {
return;
}

Expand Down Expand Up @@ -472,7 +472,7 @@ $(document).ready(function() {
const $popupNvmSpan = $('<span>', { class: 'popup-no' });
$popupNvmSpan.attr('data-l10n-id', 'deletePopupCancel');

$popupText.html([$popupMessage, $popupDelSpan, $popupNvmSpan]);
$popupText.html([$popupMessage, $popupDelSpan, $popupNvmSpan]);

// add data cells to table row
row.appendChild(name);
Expand Down
21 changes: 9 additions & 12 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ app.use(
'https://sentry.prod.mozaws.net',
'https://www.google-analytics.com'
],
imgSrc: [
"'self'",
'https://www.google-analytics.com'
],
imgSrc: ["'self'", 'https://www.google-analytics.com'],
scriptSrc: ["'self'"],
styleSrc: ["'self'", 'https://code.cdn.mozilla.net'],
fontSrc: ["'self'", 'https://code.cdn.mozilla.net'],
Expand Down Expand Up @@ -116,10 +113,10 @@ app.get('/download/:id', (req, res) => {
return;
}

storage.filename(id).then(filename => {
storage
.length(id)
.then(contentLength => {
storage
.filename(id)
.then(filename => {
return storage.length(id).then(contentLength => {
storage.ttl(id).then(timeToExpiry => {
res.render('download', {
filename: decodeURIComponent(filename),
Expand All @@ -128,11 +125,11 @@ app.get('/download/:id', (req, res) => {
timeToExpiry: timeToExpiry
});
});
})
.catch(() => {
res.status(404).render('notfound');
});
});
})
.catch(() => {
res.status(404).render('notfound');
});
});

app.get('/assets/download/:id', (req, res) => {
Expand Down
35 changes: 9 additions & 26 deletions server/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ if (conf.s3_bucket) {
length: awsLength,
get: awsGet,
set: awsSet,
aad: aad,
setField: setField,
delete: awsDelete,
forceDelete: awsForceDelete,
Expand All @@ -44,7 +43,6 @@ if (conf.s3_bucket) {
length: localLength,
get: localGet,
set: localSet,
aad: aad,
setField: setField,
delete: localDelete,
forceDelete: localForceDelete,
Expand All @@ -66,35 +64,32 @@ function quit() {
function metadata(id) {
return new Promise((resolve, reject) => {
redis_client.hgetall(id, (err, reply) => {
if (!err) {
resolve(reply);
} else {
reject(err);
if (err || !reply) {
return reject(err);
}
resolve(reply);
});
});
}

function ttl(id) {
return new Promise((resolve, reject) => {
redis_client.ttl(id, (err, reply) => {
if (!err) {
resolve(reply * 1000);
} else {
reject(err);
if (err || !reply) {
return reject(err);
}
resolve(reply * 1000);
});
});
}

function filename(id) {
return new Promise((resolve, reject) => {
redis_client.hget(id, 'filename', (err, reply) => {
if (!err) {
resolve(reply);
} else {
reject(err);
if (err || !reply) {
return reject();
}
resolve(reply);
});
});
}
Expand All @@ -115,18 +110,6 @@ function setField(id, key, value) {
redis_client.hset(id, key, value);
}

function aad(id) {
return new Promise((resolve, reject) => {
redis_client.hget(id, 'aad', (err, reply) => {
if (!err) {
resolve(reply);
} else {
reject();
}
});
});
}

function localLength(id) {
return new Promise((resolve, reject) => {
try {
Expand Down