2017-08-24 21:54:02 +00:00
|
|
|
const choo = require('choo');
|
2017-11-07 23:54:42 +00:00
|
|
|
const html = require('choo/html');
|
2018-02-21 00:00:19 +00:00
|
|
|
const nanotiming = require('nanotiming');
|
2017-08-24 21:54:02 +00:00
|
|
|
const download = require('./download');
|
2017-11-07 23:54:42 +00:00
|
|
|
const footer = require('../templates/footer');
|
|
|
|
const fxPromo = require('../templates/fxPromo');
|
2018-07-31 18:09:18 +00:00
|
|
|
const signupPromo = require('../templates/signupPromo');
|
2018-06-19 19:58:42 +00:00
|
|
|
const activeBackground = require('../templates/activeBackground');
|
2018-07-31 18:09:18 +00:00
|
|
|
const fileList = require('../templates/fileList');
|
|
|
|
const profile = require('../templates/userAccount');
|
2018-09-07 17:53:40 +00:00
|
|
|
const modal = require('../templates/modal');
|
2017-08-24 21:54:02 +00:00
|
|
|
|
2018-02-21 00:00:19 +00:00
|
|
|
nanotiming.disabled = true;
|
2017-08-24 21:54:02 +00:00
|
|
|
|
2018-09-18 23:23:58 +00: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 18:23:13 +00:00
|
|
|
}
|
2018-01-12 05:22:11 +00:00
|
|
|
|
2018-09-18 23:23:58 +00:00
|
|
|
function modalDialog(state, emit) {
|
|
|
|
if (state.modal) {
|
|
|
|
return modal(state, emit);
|
|
|
|
}
|
2018-09-07 17:53:40 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 23:23:58 +00:00
|
|
|
function body(template) {
|
|
|
|
return function(state, emit) {
|
|
|
|
const b = html`<body class="background ${activeBackground(state)}">
|
2018-09-07 17:53:40 +00:00
|
|
|
${modalDialog(state, emit)}
|
2018-01-24 18:23:13 +00:00
|
|
|
${banner(state, emit)}
|
2018-02-20 07:10:03 +00:00
|
|
|
<main class="main">
|
2017-11-07 23:54:42 +00:00
|
|
|
<noscript>
|
2018-02-20 07:10:03 +00:00
|
|
|
<div class="noscript">
|
|
|
|
<h2>${state.translate('javascriptRequired')}</h2>
|
|
|
|
<p>
|
|
|
|
<a class="link" href="https://github.com/mozilla/send/blob/master/docs/faq.md#why-does-firefox-send-require-javascript">
|
|
|
|
${state.translate('whyJavascript')}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<p>${state.translate('enableJavascript')}</p>
|
|
|
|
</div>
|
2017-11-07 23:54:42 +00:00
|
|
|
</noscript>
|
2018-08-09 00:24:58 +00:00
|
|
|
${signupPromo(state)}
|
2018-06-20 22:23:15 +00:00
|
|
|
<div class="stripedBox">
|
|
|
|
<div class="mainContent">
|
2018-07-31 18:09:18 +00:00
|
|
|
|
2018-08-07 22:40:17 +00:00
|
|
|
${profile(state, emit)}
|
2018-07-31 18:09:18 +00:00
|
|
|
|
2018-06-20 22:23:15 +00:00
|
|
|
${template(state, emit)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-07-31 18:09:18 +00:00
|
|
|
|
2018-06-20 22:23:15 +00:00
|
|
|
<div class="spacer"></div>
|
2018-07-31 18:09:18 +00:00
|
|
|
<div class="uploads">
|
|
|
|
${fileList(state)}
|
|
|
|
</div>
|
2018-02-20 07:10:03 +00:00
|
|
|
</main>
|
2017-11-07 23:54:42 +00:00
|
|
|
${footer(state)}
|
|
|
|
</body>`;
|
2018-09-18 23:23:58 +00:00
|
|
|
if (state.layout) {
|
|
|
|
// server side only
|
|
|
|
return state.layout(state, b);
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
};
|
2018-09-14 15:00:33 +00:00
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
|
2018-09-18 23:23:58 +00:00
|
|
|
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')));
|
|
|
|
app.route('/api/fxa/oauth', async function(state, emit) {
|
|
|
|
try {
|
2018-09-21 21:16:56 +00:00
|
|
|
await state.user.finishLogin(state.query.code, state.query.state);
|
2018-09-18 23:23:58 +00:00
|
|
|
emit('replaceState', '/');
|
|
|
|
} catch (e) {
|
|
|
|
emit('replaceState', '/error');
|
|
|
|
setTimeout(() => emit('render'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
app.route('*', body(require('../pages/notFound')));
|
|
|
|
return app;
|
|
|
|
};
|