2018-08-07 22:40:17 +00:00
|
|
|
const html = require('choo/html');
|
|
|
|
const raw = require('choo/html/raw');
|
2018-11-20 20:07:47 +00:00
|
|
|
const config = require('./config');
|
2019-02-26 18:39:50 +00:00
|
|
|
const clientConstants = require('./clientConstants');
|
2018-11-20 20:07:47 +00:00
|
|
|
|
|
|
|
let sentry = '';
|
|
|
|
if (config.sentry_id) {
|
2022-08-09 15:26:25 +00:00
|
|
|
//eslint-disable-next-line n/no-missing-require
|
2018-11-21 22:40:38 +00:00
|
|
|
const version = require('../dist/version.json');
|
2018-11-20 20:07:47 +00:00
|
|
|
sentry = `
|
2019-08-09 18:06:21 +00:00
|
|
|
var SENTRY_CONFIG = {
|
|
|
|
dsn: '${config.sentry_id}',
|
2018-11-20 20:07:47 +00:00
|
|
|
release: '${version.version}',
|
2019-08-09 18:06:21 +00:00
|
|
|
beforeSend: function (data) {
|
2018-11-20 20:07:47 +00:00
|
|
|
var hash = window.location.hash;
|
|
|
|
if (hash) {
|
|
|
|
return JSON.parse(JSON.stringify(data).replace(new RegExp(hash.slice(1), 'g'), ''));
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2018-08-07 22:40:17 +00:00
|
|
|
module.exports = function(state) {
|
2018-11-20 20:07:47 +00:00
|
|
|
const authConfig = state.authConfig
|
|
|
|
? `var AUTH_CONFIG = ${JSON.stringify(state.authConfig)};`
|
|
|
|
: '';
|
|
|
|
|
|
|
|
/* eslint-disable no-useless-escape */
|
|
|
|
const jsconfig = `
|
|
|
|
var isIE = /trident\\\/7\.|msie/i.test(navigator.userAgent);
|
|
|
|
var isUnsupportedPage = /\\\/unsupported/.test(location.pathname);
|
|
|
|
if (isIE && !isUnsupportedPage) {
|
2018-12-18 20:27:43 +00:00
|
|
|
window.location.assign('/unsupported/ie');
|
2018-11-20 20:07:47 +00:00
|
|
|
}
|
2018-12-18 20:27:43 +00:00
|
|
|
if (
|
|
|
|
// Firefox < 50
|
|
|
|
/firefox/i.test(navigator.userAgent) &&
|
|
|
|
parseInt(navigator.userAgent.match(/firefox\\/*([^\\n\\r]*)\./i)[1], 10) < 50
|
|
|
|
) {
|
|
|
|
window.location.assign('/unsupported/outdated');
|
|
|
|
}
|
|
|
|
|
2019-02-26 18:39:50 +00:00
|
|
|
var LIMITS = ${JSON.stringify(clientConstants.LIMITS)};
|
2021-01-26 23:13:56 +00:00
|
|
|
var WEB_UI = ${JSON.stringify(clientConstants.WEB_UI)};
|
2019-02-26 18:39:50 +00:00
|
|
|
var DEFAULTS = ${JSON.stringify(clientConstants.DEFAULTS)};
|
2019-04-26 20:30:33 +00:00
|
|
|
var PREFS = ${JSON.stringify(state.prefs)};
|
|
|
|
var downloadMetadata = ${
|
2018-11-20 20:07:47 +00:00
|
|
|
state.downloadMetadata ? raw(JSON.stringify(state.downloadMetadata)) : '{}'
|
|
|
|
};
|
|
|
|
${authConfig};
|
|
|
|
${sentry}
|
|
|
|
`;
|
2018-08-07 22:40:17 +00:00
|
|
|
return state.cspNonce
|
|
|
|
? html`
|
2018-11-16 20:39:36 +00:00
|
|
|
<script nonce="${state.cspNonce}">
|
2018-11-20 20:07:47 +00:00
|
|
|
${raw(jsconfig)};
|
2018-11-16 20:39:36 +00:00
|
|
|
</script>
|
|
|
|
`
|
2018-08-07 22:40:17 +00:00
|
|
|
: '';
|
|
|
|
};
|