2020-08-18 03:57:56 +08:00
|
|
|
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
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
const
|
|
|
|
ROOT = './',
|
2016-06-30 08:02:45 +08:00
|
|
|
HASH_PREFIX = '#/',
|
|
|
|
SERVER_PREFIX = './?',
|
2020-09-04 18:05:17 +08:00
|
|
|
VERSION = Settings.app('version'),
|
2021-04-28 21:56:31 +08:00
|
|
|
VERSION_PREFIX = Settings.app('webVersionPath') || 'snappymail/v/' + VERSION + '/';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2021-01-27 19:02:37 +08:00
|
|
|
export const SUB_QUERY_PREFIX = '&q[]=';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string=} startupUrl
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function root(startupUrl = '') {
|
2016-06-16 07:36:44 +08:00
|
|
|
return HASH_PREFIX + pString(startupUrl);
|
|
|
|
}
|
2016-04-30 07:42:18 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2021-01-27 19:02:37 +08:00
|
|
|
export function logoutLink() {
|
2021-02-23 00:28:54 +08:00
|
|
|
return (rl.adminArea() && !Settings.app('adminHostUse'))
|
|
|
|
? SERVER_PREFIX + (Settings.app('adminPath') || 'admin')
|
|
|
|
: ROOT;
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} type
|
2021-01-27 07:26:31 +08:00
|
|
|
* @param {string} hash
|
2016-06-16 07:36:44 +08:00
|
|
|
* @param {string=} customSpecSuffix
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2021-01-27 07:26:31 +08:00
|
|
|
export function serverRequestRaw(type, hash, customSpecSuffix) {
|
|
|
|
return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/'
|
2021-04-29 03:33:03 +08:00
|
|
|
+ (null == customSpecSuffix ? '0' : customSpecSuffix) + '/'
|
2021-01-27 07:26:31 +08:00
|
|
|
+ (type
|
|
|
|
? type + '/' + (hash ? SUB_QUERY_PREFIX + '/' + hash : '')
|
|
|
|
: '')
|
|
|
|
;
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} download
|
|
|
|
* @param {string=} customSpecSuffix
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function attachmentDownload(download, customSpecSuffix) {
|
2021-01-27 07:26:31 +08:00
|
|
|
return serverRequestRaw('Download', download, customSpecSuffix);
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} type
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function serverRequest(type) {
|
2021-04-29 03:33:03 +08:00
|
|
|
return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/0/';
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} email
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function change(email) {
|
2020-08-12 06:25:36 +08:00
|
|
|
return serverRequest('Change') + encodeURIComponent(email) + '/';
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} hash
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function userBackground(hash) {
|
2021-01-27 07:26:31 +08:00
|
|
|
return serverRequestRaw('UserBackground', hash);
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} lang
|
|
|
|
* @param {boolean} isAdmin
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function langLink(lang, isAdmin) {
|
2020-08-12 06:25:36 +08:00
|
|
|
return SERVER_PREFIX + '/Lang/0/' + (isAdmin ? 'Admin' : 'App') + '/' + encodeURI(lang) + '/' + VERSION + '/';
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} path
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2021-03-17 00:07:29 +08:00
|
|
|
export function staticLink(path) {
|
2020-10-02 18:40:33 +08:00
|
|
|
return VERSION_PREFIX + 'static/' + path;
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function openPgpJs() {
|
2021-03-17 00:07:29 +08:00
|
|
|
return staticLink('js/min/openpgp.min.js');
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function openPgpWorkerJs() {
|
2021-03-17 00:07:29 +08:00
|
|
|
return staticLink('js/min/openpgp.worker.min.js');
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} theme
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function themePreviewLink(theme) {
|
2016-06-16 07:36:44 +08:00
|
|
|
let prefix = VERSION_PREFIX;
|
2019-07-05 03:19:24 +08:00
|
|
|
if ('@custom' === theme.substr(-7)) {
|
2020-09-03 18:51:15 +08:00
|
|
|
theme = theme.substr(0, theme.length - 7).trim();
|
2020-10-02 18:40:33 +08:00
|
|
|
prefix = Settings.app('webPath') || '';
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2020-08-12 06:25:36 +08:00
|
|
|
return prefix + 'themes/' + encodeURI(theme) + '/images/preview.png';
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} inboxFolderName = 'INBOX'
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2021-02-12 21:56:16 +08:00
|
|
|
export function mailbox(inboxFolderName = 'INBOX') {
|
2016-06-16 07:36:44 +08:00
|
|
|
return HASH_PREFIX + 'mailbox/' + inboxFolderName;
|
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string=} screenName = ''
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function settings(screenName = '') {
|
2016-06-16 07:36:44 +08:00
|
|
|
return HASH_PREFIX + 'settings' + (screenName ? '/' + screenName : '');
|
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
/**
|
|
|
|
* @param {string} screenName
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function admin(screenName) {
|
2016-06-16 07:36:44 +08:00
|
|
|
let result = HASH_PREFIX;
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (screenName) {
|
2016-06-16 07:36:44 +08:00
|
|
|
case 'AdminDomains':
|
|
|
|
result += 'domains';
|
|
|
|
break;
|
|
|
|
case 'AdminSecurity':
|
|
|
|
result += 'security';
|
|
|
|
break;
|
2016-06-30 08:02:45 +08:00
|
|
|
// no default
|
2016-06-16 07:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} folder
|
|
|
|
* @param {number=} page = 1
|
|
|
|
* @param {string=} search = ''
|
|
|
|
* @param {string=} threadUid = ''
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {string}
|
2016-06-16 07:36:44 +08:00
|
|
|
*/
|
2019-07-05 03:19:24 +08:00
|
|
|
export function mailBox(folder, page = 1, search = '', threadUid = '') {
|
2020-08-18 03:57:56 +08:00
|
|
|
page = pInt(page, 1);
|
2016-06-16 07:36:44 +08:00
|
|
|
search = pString(search);
|
|
|
|
|
|
|
|
let result = HASH_PREFIX + 'mailbox/';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2020-07-28 23:20:14 +08:00
|
|
|
if (folder) {
|
2016-06-16 07:36:44 +08:00
|
|
|
const resultThreadUid = pInt(threadUid);
|
2020-08-12 06:25:36 +08:00
|
|
|
result += encodeURI(folder) + (0 < resultThreadUid ? '~' + resultThreadUid : '');
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (1 < page) {
|
2021-03-30 17:48:22 +08:00
|
|
|
result = result.replace(/\/+$/, '') + '/p' + page;
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2020-07-28 23:20:14 +08:00
|
|
|
if (search) {
|
2021-03-30 17:48:22 +08:00
|
|
|
result = result.replace(/\/+$/, '') + '/' + encodeURI(search);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2016-06-16 07:36:44 +08:00
|
|
|
return result;
|
|
|
|
}
|
2021-03-30 17:48:22 +08:00
|
|
|
|