drop.chapril.org-firefoxsend/app/routes/download.js

31 lines
689 B
JavaScript
Raw Normal View History

2018-08-08 00:40:17 +02:00
/* global downloadMetadata */
2018-01-30 21:15:09 +01:00
const preview = require('../pages/preview');
2018-07-31 20:09:18 +02:00
const password = require('../pages/password');
2018-08-08 00:40:17 +02:00
function createFileInfo(state) {
return {
id: state.params.id,
secretKey: state.params.key,
nonce: downloadMetadata.nonce,
requiresPassword: downloadMetadata.pwd
};
}
module.exports = function(state, emit) {
2018-01-24 19:23:13 +01:00
if (!state.fileInfo) {
2018-08-08 00:40:17 +02:00
state.fileInfo = createFileInfo(state);
2018-07-31 20:09:18 +02:00
}
if (!state.transfer && !state.fileInfo.requiresPassword) {
emit('getMetadata');
2018-01-24 19:23:13 +01:00
}
if (state.transfer) {
2018-07-31 20:09:18 +02:00
return preview(state, emit);
}
if (state.fileInfo.requiresPassword && !state.fileInfo.password) {
return password(state, emit);
}
};