Reduce JavaScript footprint

This commit is contained in:
djmaze 2021-08-20 15:40:07 +02:00
parent fea65b7ebf
commit cc03546484
12 changed files with 811 additions and 942 deletions

View file

@ -8,174 +8,140 @@ const
VERSION = Settings.app('version'),
VERSION_PREFIX = Settings.app('webVersionPath') || 'snappymail/v/' + VERSION + '/';
/**
* @returns {string}
*/
export const SUB_QUERY_PREFIX = '&q[]=';
export const
SUB_QUERY_PREFIX = '&q[]=',
/**
* @param {string=} startupUrl
* @returns {string}
*/
export function root(startupUrl = '') {
return HASH_PREFIX + pString(startupUrl);
}
/**
* @param {string=} startupUrl
* @returns {string}
*/
root = (startupUrl = '') => HASH_PREFIX + pString(startupUrl),
/**
* @returns {string}
*/
export function logoutLink() {
return (rl.adminArea() && !Settings.app('adminHostUse'))
/**
* @returns {string}
*/
logoutLink = () => (rl.adminArea() && !Settings.app('adminHostUse'))
? SERVER_PREFIX + (Settings.app('adminPath') || 'admin')
: ROOT;
}
: ROOT,
/**
* @param {string} type
* @param {string} hash
* @param {string=} customSpecSuffix
* @returns {string}
*/
export function serverRequestRaw(type, hash, customSpecSuffix) {
return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/'
/**
* @param {string} type
* @param {string} hash
* @param {string=} customSpecSuffix
* @returns {string}
*/
serverRequestRaw = (type, hash, customSpecSuffix) =>
SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/'
+ (null == customSpecSuffix ? '0' : customSpecSuffix) + '/'
+ (type
? type + '/' + (hash ? SUB_QUERY_PREFIX + '/' + hash : '')
: '')
;
}
: ''),
/**
* @param {string} download
* @param {string=} customSpecSuffix
* @returns {string}
*/
export function attachmentDownload(download, customSpecSuffix) {
return serverRequestRaw('Download', download, customSpecSuffix);
}
/**
* @param {string} download
* @param {string=} customSpecSuffix
* @returns {string}
*/
attachmentDownload = (download, customSpecSuffix) =>
serverRequestRaw('Download', download, customSpecSuffix),
/**
* @param {string} type
* @returns {string}
*/
export function serverRequest(type) {
return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/0/';
}
/**
* @param {string} type
* @returns {string}
*/
serverRequest = type => SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/0/',
/**
* @param {string} email
* @returns {string}
*/
export function change(email) {
return serverRequest('Change') + encodeURIComponent(email) + '/';
}
/**
* @param {string} email
* @returns {string}
*/
change = email => serverRequest('Change') + encodeURIComponent(email) + '/',
/**
* @param {string} lang
* @param {boolean} isAdmin
* @returns {string}
*/
export function langLink(lang, isAdmin) {
return SERVER_PREFIX + '/Lang/0/' + (isAdmin ? 'Admin' : 'App') + '/' + encodeURI(lang) + '/' + VERSION + '/';
}
/**
* @param {string} lang
* @param {boolean} isAdmin
* @returns {string}
*/
langLink = (lang, isAdmin) =>
SERVER_PREFIX + '/Lang/0/' + (isAdmin ? 'Admin' : 'App') + '/' + encodeURI(lang) + '/' + VERSION + '/',
/**
* @param {string} path
* @returns {string}
*/
export function staticLink(path) {
return VERSION_PREFIX + 'static/' + path;
}
/**
* @param {string} path
* @returns {string}
*/
staticLink = path => VERSION_PREFIX + 'static/' + path,
/**
* @returns {string}
*/
export function openPgpJs() {
return staticLink('js/min/openpgp.min.js');
}
/**
* @returns {string}
*/
openPgpJs = () => staticLink('js/min/openpgp.min.js'),
/**
* @returns {string}
*/
export function openPgpWorkerJs() {
return staticLink('js/min/openpgp.worker.min.js');
}
/**
* @returns {string}
*/
openPgpWorkerJs = () => staticLink('js/min/openpgp.worker.min.js'),
/**
* @param {string} theme
* @returns {string}
*/
export function themePreviewLink(theme) {
let prefix = VERSION_PREFIX;
if ('@custom' === theme.substr(-7)) {
theme = theme.substr(0, theme.length - 7).trim();
prefix = Settings.app('webPath') || '';
}
/**
* @param {string} theme
* @returns {string}
*/
themePreviewLink = theme => {
let prefix = VERSION_PREFIX;
if ('@custom' === theme.substr(-7)) {
theme = theme.substr(0, theme.length - 7).trim();
prefix = Settings.app('webPath') || '';
}
return prefix + 'themes/' + encodeURI(theme) + '/images/preview.png';
}
return prefix + 'themes/' + encodeURI(theme) + '/images/preview.png';
},
/**
* @param {string} inboxFolderName = 'INBOX'
* @returns {string}
*/
export function mailbox(inboxFolderName = 'INBOX') {
return HASH_PREFIX + 'mailbox/' + inboxFolderName;
}
/**
* @param {string} inboxFolderName = 'INBOX'
* @returns {string}
*/
mailbox = (inboxFolderName = 'INBOX') => HASH_PREFIX + 'mailbox/' + inboxFolderName,
/**
* @param {string=} screenName = ''
* @returns {string}
*/
export function settings(screenName = '') {
return HASH_PREFIX + 'settings' + (screenName ? '/' + screenName : '');
}
/**
* @param {string=} screenName = ''
* @returns {string}
*/
settings = (screenName = '') => HASH_PREFIX + 'settings' + (screenName ? '/' + screenName : ''),
/**
* @param {string} screenName
* @returns {string}
*/
export function admin(screenName) {
let result = HASH_PREFIX;
switch (screenName) {
case 'AdminDomains':
result += 'domains';
break;
case 'AdminSecurity':
result += 'security';
break;
// no default
}
/**
* @param {string=} screenName
* @returns {string}
*/
admin = screenName => HASH_PREFIX + (
'AdminDomains' == screenName ? 'domains'
: 'AdminSecurity' == screenName ? 'security'
: ''
),
return result;
}
/**
* @param {string} folder
* @param {number=} page = 1
* @param {string=} search = ''
* @param {string=} threadUid = ''
* @returns {string}
*/
mailBox = (folder, page = 1, search = '', threadUid = '') => {
page = pInt(page, 1);
search = pString(search);
/**
* @param {string} folder
* @param {number=} page = 1
* @param {string=} search = ''
* @param {string=} threadUid = ''
* @returns {string}
*/
export function mailBox(folder, page = 1, search = '', threadUid = '') {
page = pInt(page, 1);
search = pString(search);
let result = HASH_PREFIX + 'mailbox/';
let result = HASH_PREFIX + 'mailbox/';
if (folder) {
const resultThreadUid = pInt(threadUid);
result += encodeURI(folder) + (0 < resultThreadUid ? '~' + resultThreadUid : '');
}
if (folder) {
const resultThreadUid = pInt(threadUid);
result += encodeURI(folder) + (0 < resultThreadUid ? '~' + resultThreadUid : '');
}
if (1 < page) {
result = result.replace(/\/+$/, '') + '/p' + page;
}
if (1 < page) {
result = result.replace(/\/+$/, '') + '/p' + page;
}
if (search) {
result = result.replace(/\/+$/, '') + '/' + encodeURI(search);
}
return result;
}
if (search) {
result = result.replace(/\/+$/, '') + '/' + encodeURI(search);
}
return result;
};