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

67 lines
1.9 KiB
JavaScript
Raw Normal View History

const choo = require('choo');
const html = require('choo/html');
const nanotiming = require('nanotiming');
const download = require('./download');
const footer = require('../templates/footer');
const fxPromo = require('../templates/fxPromo');
2018-09-07 19:53:40 +02:00
const modal = require('../templates/modal');
2018-09-28 16:54:23 +02:00
const header = require('../templates/header');
nanotiming.disabled = true;
module.exports = function() {
const app = choo();
function banner(state, emit) {
if (state.promo && !state.route.startsWith('/unsupported/')) {
return fxPromo(state, emit);
}
2018-01-24 19:23:13 +01:00
}
function modalDialog(state, emit) {
if (state.modal) {
return modal(state, emit);
}
2018-09-07 19:53:40 +02:00
}
2018-10-01 23:20:26 +02:00
function body(page) {
return function(state, emit) {
2018-09-25 22:39:45 +02:00
const b = html`<body>
2018-09-07 19:53:40 +02:00
${modalDialog(state, emit)}
2018-01-24 19:23:13 +01:00
${banner(state, emit)}
2018-10-01 23:20:26 +02:00
${header(state, emit)}
2018-02-20 08:10:03 +01:00
<main class="main">
2018-10-01 23:20:26 +02:00
${page(state, emit)}
2018-02-20 08:10:03 +01:00
</main>
${footer(state)}
</body>`;
if (state.layout) {
// server side only
return state.layout(state, b);
}
return b;
};
}
app.route('/', body(require('../pages/welcome')));
app.route('/share/:id', body(require('../pages/share')));
app.route('/download/:id', body(download));
app.route('/download/:id/:key', body(download));
app.route('/unsupported/:reason', body(require('../pages/unsupported')));
app.route('/legal', body(require('../pages/legal')));
app.route('/error', body(require('../pages/error')));
app.route('/blank', body(require('../pages/blank')));
app.route('/signin', body(require('../pages/signin')));
2018-09-26 21:22:04 +02:00
app.route('/oauth', async function(state, emit) {
try {
2018-09-21 23:16:56 +02:00
await state.user.finishLogin(state.query.code, state.query.state);
emit('replaceState', '/');
} catch (e) {
emit('replaceState', '/error');
setTimeout(() => emit('render'));
}
});
app.route('*', body(require('../pages/notFound')));
return app;
};