Skip to content

Commit

Permalink
fixed error on metadata 404
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Jan 12, 2018
1 parent 76175d6 commit bace117
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/fileReceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class FileReceiver extends Nanobus {
super('FileReceiver');
this.secretKeyPromise = window.crypto.subtle.importKey(
'raw',
b64ToArray(file.key),
b64ToArray(file.secretKey),
'HKDF',
false,
['deriveKey']
Expand Down Expand Up @@ -122,6 +122,9 @@ export default class FileReceiver extends Nanobus {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 404) {
return reject(new Error(xhr.status));
}
const nonce = xhr.getResponseHeader('WWW-Authenticate').split(' ')[1];
this.file.nonce = nonce;
if (xhr.status === 200) {
Expand Down Expand Up @@ -172,6 +175,8 @@ export default class FileReceiver extends Nanobus {
this.file.iv = meta.iv;
this.file.size = data.size;
this.file.ttl = data.ttl;
this.file.dlimit = data.dlimit;
this.file.dtotal = data.dtotal;
this.state = 'ready';
} catch (e) {
this.state = 'invalid';
Expand Down
2 changes: 1 addition & 1 deletion app/templates/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function(state, emit) {
return notFound(state, emit);
}
state.fileInfo.id = state.params.id;
state.fileInfo.key = state.params.key;
state.fileInfo.secretKey = state.params.key;
const fileInfo = state.fileInfo;
const size = fileInfo.size
? state.translate('downloadFileSize', { size: bytes(fileInfo.size) })
Expand Down

0 comments on commit bace117

Please sign in to comment.