1
0
mirror of https://gitlab.com/timvisee/send.git synced 2024-11-14 07:02:30 +01:00
send/server/initScript.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-08-08 00:40:17 +02:00
const html = require('choo/html');
const raw = require('choo/html/raw');
2018-11-20 21:07:47 +01:00
const config = require('./config');
let sentry = '';
if (config.sentry_id) {
//eslint-disable-next-line node/no-missing-require
2018-11-21 23:40:38 +01:00
const version = require('../dist/version.json');
2018-11-20 21:07:47 +01:00
sentry = `
var RAVEN_CONFIG = {
release: '${version.version}',
tags: {
commit: '${version.commit}'
},
dataCallback: function (data) {
var hash = window.location.hash;
if (hash) {
return JSON.parse(JSON.stringify(data).replace(new RegExp(hash.slice(1), 'g'), ''));
}
return data;
}
}
var SENTRY_ID = '${config.sentry_id}';
`;
}
2018-08-08 00:40:17 +02:00
module.exports = function(state) {
2018-11-20 21:07:47 +01: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 21:27:43 +01:00
window.location.assign('/unsupported/ie');
2018-11-20 21:07:47 +01:00
}
2018-12-18 21:27:43 +01: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');
}
2018-11-20 21:07:47 +01:00
var LIMITS = {
ANON: {
MAX_FILE_SIZE: ${config.anon_max_file_size},
MAX_DOWNLOADS: ${config.anon_max_downloads},
MAX_EXPIRE_SECONDS: ${config.anon_max_expire_seconds},
},
MAX_FILE_SIZE: ${config.max_file_size},
MAX_DOWNLOADS: ${config.max_downloads},
MAX_EXPIRE_SECONDS: ${config.max_expire_seconds},
MAX_FILES_PER_ARCHIVE: ${config.max_files_per_archive},
MAX_ARCHIVES_PER_USER: ${config.max_archives_per_user}
};
var DEFAULTS = {
DOWNLOAD_COUNTS: ${JSON.stringify(config.download_counts)},
EXPIRE_TIMES_SECONDS: ${JSON.stringify(config.expire_times_seconds)},
EXPIRE_SECONDS: ${config.default_expire_seconds}
};
const LOCALE = '${state.locale}';
const downloadMetadata = ${
state.downloadMetadata ? raw(JSON.stringify(state.downloadMetadata)) : '{}'
};
${authConfig};
${sentry}
`;
2018-08-08 00:40:17 +02:00
return state.cspNonce
? html`
2018-11-16 21:39:36 +01:00
<script nonce="${state.cspNonce}">
2018-11-20 21:07:47 +01:00
${raw(jsconfig)};
2018-11-16 21:39:36 +01:00
</script>
`
2018-08-08 00:40:17 +02:00
: '';
};