2018-10-25 04:07:10 +02:00
|
|
|
const choo = require('choo');
|
|
|
|
const download = require('./ui/download');
|
2018-11-12 20:13:31 +01:00
|
|
|
const body = require('./ui/body');
|
2018-10-25 04:07:10 +02:00
|
|
|
|
2018-11-12 20:13:31 +01:00
|
|
|
module.exports = function(app = choo()) {
|
2018-10-30 19:37:33 +01:00
|
|
|
app.route('/', body(require('./ui/home')));
|
2018-10-25 04:07:10 +02:00
|
|
|
app.route('/download/:id', body(download));
|
|
|
|
app.route('/download/:id/:key', body(download));
|
|
|
|
app.route('/unsupported/:reason', body(require('./ui/unsupported')));
|
|
|
|
app.route('/legal', body(require('./ui/legal')));
|
|
|
|
app.route('/error', body(require('./ui/error')));
|
|
|
|
app.route('/blank', body(require('./ui/blank')));
|
|
|
|
app.route('/oauth', async function(state, emit) {
|
|
|
|
try {
|
|
|
|
await state.user.finishLogin(state.query.code, state.query.state);
|
2018-12-12 19:14:06 +01:00
|
|
|
await state.user.syncFileList();
|
2018-10-25 04:07:10 +02:00
|
|
|
emit('replaceState', '/');
|
|
|
|
} catch (e) {
|
|
|
|
emit('replaceState', '/error');
|
|
|
|
setTimeout(() => emit('render'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
app.route('*', body(require('./ui/notFound')));
|
|
|
|
return app;
|
|
|
|
};
|