2017-08-24 23:54:02 +02:00
|
|
|
const choo = require('choo');
|
2017-11-08 00:54:42 +01:00
|
|
|
const html = require('choo/html');
|
2018-02-21 01:00:19 +01:00
|
|
|
const nanotiming = require('nanotiming');
|
2017-08-24 23:54:02 +02:00
|
|
|
const download = require('./download');
|
2017-11-08 00:54:42 +01:00
|
|
|
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');
|
2017-08-24 23:54:02 +02:00
|
|
|
|
2018-02-21 01:00:19 +01:00
|
|
|
nanotiming.disabled = true;
|
2017-08-24 23:54:02 +02:00
|
|
|
|
2018-09-19 01:23:58 +02:00
|
|
|
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
|
|
|
}
|
2018-01-12 06:22:11 +01:00
|
|
|
|
2018-09-19 01:23:58 +02: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) {
|
2018-09-19 01:23:58 +02:00
|
|
|
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-10-17 01:53:33 +02:00
|
|
|
${page(state, emit)}
|
2017-11-08 00:54:42 +01:00
|
|
|
${footer(state)}
|
2018-10-17 01:53:33 +02:00
|
|
|
</body>`;
|
2018-09-19 01:23:58 +02:00
|
|
|
if (state.layout) {
|
|
|
|
// server side only
|
|
|
|
return state.layout(state, b);
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
};
|
2018-09-14 17:00:33 +02:00
|
|
|
}
|
2017-08-24 23:54:02 +02:00
|
|
|
|
2018-09-19 01:23:58 +02:00
|
|
|
app.route('/', body(require('../pages/welcome')));
|
|
|
|
app.route('/share/:id', body(require('../pages/share')));
|
2018-10-17 01:53:33 +02:00
|
|
|
app.route('/uploads', body(require('../pages/uploads')));
|
2018-09-19 01:23:58 +02:00
|
|
|
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) {
|
2018-09-19 01:23:58 +02:00
|
|
|
try {
|
2018-09-21 23:16:56 +02:00
|
|
|
await state.user.finishLogin(state.query.code, state.query.state);
|
2018-09-19 01:23:58 +02:00
|
|
|
emit('replaceState', '/');
|
|
|
|
} catch (e) {
|
|
|
|
emit('replaceState', '/error');
|
|
|
|
setTimeout(() => emit('render'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
app.route('*', body(require('../pages/notFound')));
|
|
|
|
return app;
|
|
|
|
};
|