snappymail/dev/Common/Links.js

142 lines
3.2 KiB
JavaScript
Raw Normal View History

import { pString, pInt } from 'Common/Utils';
2021-04-28 21:56:31 +08:00
import { Settings } from 'Common/Globals';
2015-11-15 08:23:16 +08:00
const
ROOT = './',
2016-06-30 08:02:45 +08:00
HASH_PREFIX = '#/',
SERVER_PREFIX = './?',
VERSION = Settings.app('version'),
VERSION_PREFIX = Settings.app('webVersionPath') || 'snappymail/v/' + VERSION + '/',
adminPath = () => rl.adminArea() && !Settings.app('adminHostUse'),
prefix = () => SERVER_PREFIX + (adminPath() ? Settings.app('adminPath') : '');
2015-11-15 08:23:16 +08:00
2021-08-20 21:40:07 +08:00
export const
SUB_QUERY_PREFIX = '&q[]=',
/**
* @param {string=} startupUrl
* @returns {string}
*/
root = (startupUrl = '') => HASH_PREFIX + pString(startupUrl),
/**
* @returns {string}
*/
logoutLink = () => adminPath() ? prefix() : ROOT,
2021-08-20 21:40:07 +08:00
/**
* @param {string} type
* @param {string} hash
* @param {string=} customSpecSuffix
* @returns {string}
*/
2021-08-23 22:40:28 +08:00
serverRequestRaw = (type, hash) =>
2021-08-20 21:40:07 +08:00
SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/'
2021-08-23 22:40:28 +08:00
+ '0/' // AuthAccountHash ?
+ (type
? type + '/' + (hash ? SUB_QUERY_PREFIX + '/' + hash : '')
2021-08-20 21:40:07 +08:00
: ''),
/**
* @param {string} download
* @param {string=} customSpecSuffix
* @returns {string}
*/
attachmentDownload = (download, customSpecSuffix) =>
serverRequestRaw('Download', download, customSpecSuffix),
/**
* @param {string} type
* @returns {string}
*/
serverRequest = type => prefix() + '/' + type + '/' + SUB_QUERY_PREFIX + '/0/',
2021-08-20 21:40:07 +08:00
/**
* @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}
*/
staticLink = path => VERSION_PREFIX + 'static/' + path,
/**
* @returns {string}
*/
openPgpJs = () => staticLink('js/min/openpgp.min.js'),
/**
* @returns {string}
*/
openPgpWorkerJs = () => staticLink('js/min/openpgp.worker.min.js'),
/**
* @param {string} theme
* @returns {string}
*/
themePreviewLink = theme => {
let prefix = VERSION_PREFIX;
if ('@custom' === theme.slice(-7)) {
theme = theme.slice(0, theme.length - 7).trim();
2021-08-20 21:40:07 +08:00
prefix = Settings.app('webPath') || '';
}
return prefix + 'themes/' + encodeURI(theme) + '/images/preview.png';
},
/**
* @param {string} inboxFolderName = 'INBOX'
* @returns {string}
*/
mailbox = (inboxFolderName = 'INBOX') => HASH_PREFIX + 'mailbox/' + inboxFolderName,
/**
* @param {string=} screenName = ''
* @returns {string}
*/
settings = (screenName = '') => HASH_PREFIX + 'settings' + (screenName ? '/' + screenName : ''),
/**
* @param {string=} screenName
* @returns {string}
*/
admin = screenName => HASH_PREFIX + (
'AdminDomains' == screenName ? 'domains'
: 'AdminSecurity' == screenName ? 'security'
: ''
),
/**
* @param {string} folder
* @param {number=} page = 1
* @param {string=} search = ''
2021-09-10 22:28:29 +08:00
* @param {number=} threadUid = 0
2021-08-20 21:40:07 +08:00
* @returns {string}
*/
2021-12-07 23:52:05 +08:00
mailBox = (folder, page, search, threadUid) => {
let result = [HASH_PREFIX + 'mailbox'];
2021-08-20 21:40:07 +08:00
if (folder) {
2021-12-07 23:52:05 +08:00
result.push(folder + (threadUid ? '~' + threadUid : ''));
2021-08-20 21:40:07 +08:00
}
2021-12-08 00:22:56 +08:00
page = pInt(page, 1);
2021-08-20 21:40:07 +08:00
if (1 < page) {
2021-12-07 23:52:05 +08:00
result.push('p' + page);
2021-08-20 21:40:07 +08:00
}
2021-12-08 00:22:56 +08:00
search = pString(search);
2021-08-20 21:40:07 +08:00
if (search) {
2021-12-07 23:52:05 +08:00
result.push(encodeURI(search));
2021-08-20 21:40:07 +08:00
}
2021-12-07 23:52:05 +08:00
return result.join('/');
2021-08-20 21:40:07 +08:00
};