2022-10-10 19:52:56 +08:00
|
|
|
import { pInt } from 'Common/Utils';
|
2023-01-19 23:46:39 +08:00
|
|
|
import { doc, Settings } from 'Common/Globals';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
const
|
2023-01-19 23:46:39 +08:00
|
|
|
BASE = doc.location.pathname.replace(/\/+$/,'') + '/',
|
2016-06-30 08:02:45 +08:00
|
|
|
HASH_PREFIX = '#/',
|
2022-01-11 22:55:48 +08:00
|
|
|
|
|
|
|
adminPath = () => rl.adminArea() && !Settings.app('adminHostUse'),
|
|
|
|
|
2023-01-19 23:46:39 +08:00
|
|
|
prefix = () => BASE + '?' + (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}
|
|
|
|
*/
|
2022-02-25 18:33:08 +08:00
|
|
|
root = () => HASH_PREFIX,
|
2021-08-20 21:40:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2023-01-19 23:46:39 +08:00
|
|
|
logoutLink = () => adminPath() ? prefix() : BASE,
|
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) =>
|
2023-01-19 23:46:39 +08:00
|
|
|
BASE + '?/Raw/' + SUB_QUERY_PREFIX + '/'
|
2022-11-01 00:10:04 +08:00
|
|
|
+ '0/' // Settings.get('AccountHash') ?
|
2021-01-27 07:26:31 +08:00
|
|
|
+ (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),
|
|
|
|
|
2022-02-02 20:02:48 +08:00
|
|
|
proxy = url =>
|
2023-01-19 23:46:39 +08:00
|
|
|
BASE + '?/ProxyExternal/'
|
2022-04-19 16:33:21 +08:00
|
|
|
+ btoa(url.replace(/ /g, '%20')).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
2022-12-28 17:59:47 +08:00
|
|
|
// + b64EncodeJSONSafe(url.replace(/ /g, '%20')),
|
2022-02-02 20:02:48 +08:00
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
/**
|
|
|
|
* @param {string} type
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-01-11 22:55:48 +08:00
|
|
|
serverRequest = type => prefix() + '/' + type + '/' + SUB_QUERY_PREFIX + '/0/',
|
2021-08-20 21:40:07 +08:00
|
|
|
|
2023-01-19 23:46:39 +08:00
|
|
|
// Is '?/Css/0/Admin' needed?
|
|
|
|
cssLink = theme => BASE + '?/Css/0/User/-/' + encodeURI(theme) + '/-/' + Date.now() + '/Hash/-/Json/',
|
|
|
|
|
2021-08-20 21:40:07 +08:00
|
|
|
/**
|
|
|
|
* @param {string} lang
|
|
|
|
* @param {boolean} isAdmin
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
langLink = (lang, isAdmin) =>
|
2023-01-19 23:46:39 +08:00
|
|
|
BASE + '?/Lang/0/' + (isAdmin ? 'Admin' : 'App')
|
2022-11-04 23:56:43 +08:00
|
|
|
+ '/' + encodeURI(lang)
|
|
|
|
+ '/' + Settings.app('version') + '/',
|
2021-08-20 21:40:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} path
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-11-04 23:56:43 +08:00
|
|
|
staticLink = path => Settings.app('webVersionPath') + 'static/' + path,
|
2021-08-20 21:40:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} theme
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
themePreviewLink = theme => {
|
2022-11-04 23:56:43 +08:00
|
|
|
let path = 'webVersionPath';
|
2022-10-26 22:38:39 +08:00
|
|
|
if (theme.endsWith('@custom')) {
|
2021-12-08 18:35:41 +08:00
|
|
|
theme = theme.slice(0, theme.length - 7).trim();
|
2022-11-04 23:56:43 +08:00
|
|
|
path = 'webPath';
|
2021-08-20 21:40:07 +08:00
|
|
|
}
|
2022-11-04 23:56:43 +08:00
|
|
|
return Settings.app(path) + 'themes/' + encodeURI(theme) + '/images/preview.png';
|
2021-08-20 21:40:07 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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}
|
|
|
|
*/
|
2022-10-14 16:20:41 +08:00
|
|
|
mailBox = (folder, page, search, threadUid, messageUid) => {
|
2021-12-07 23:52:05 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-14 16:20:41 +08:00
|
|
|
if (messageUid) {
|
|
|
|
result.push('m' + messageUid);
|
|
|
|
} else {
|
|
|
|
page = pInt(page, 1);
|
|
|
|
if (1 < page) {
|
|
|
|
result.push('p' + page);
|
|
|
|
}
|
|
|
|
search && result.push(encodeURI(search));
|
2021-08-20 21:40:07 +08:00
|
|
|
}
|
|
|
|
|
2021-12-07 23:52:05 +08:00
|
|
|
return result.join('/');
|
2022-10-14 16:20:41 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
mailBoxMessage = (folder, messageUid) => mailBox(folder, 1, '', 0, pInt(messageUid));
|