snappymail/dev/Common/Links.js

373 lines
7.3 KiB
JavaScript
Raw Normal View History

import { pString, pInt } from 'Common/Utils';
2015-11-15 08:23:16 +08:00
const
Settings = rl.settings,
ROOT = './',
2016-06-30 08:02:45 +08:00
HASH_PREFIX = '#/',
SERVER_PREFIX = './?',
SUB_QUERY_PREFIX = '&q[]=',
VERSION = Settings.app('version'),
WEB_PREFIX = Settings.app('webPath') || '',
VERSION_PREFIX = Settings.app('webVersionPath') || 'rainloop/v/' + VERSION + '/',
2016-06-30 08:02:45 +08:00
STATIC_PREFIX = VERSION_PREFIX + 'static/',
ADMIN_HOST_USE = !!Settings.app('adminHostUse'),
ADMIN_PATH = Settings.app('adminPath') || 'admin',
2016-06-16 07:36:44 +08:00
getHash = () => Settings.get('AuthAccountHash') || '0';
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 subQueryPrefix() {
2016-06-16 07:36:44 +08:00
return SUB_QUERY_PREFIX;
}
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
*/
2019-07-05 03:19:24 +08:00
export function rootAdmin() {
2016-06-16 07:36:44 +08:00
return ADMIN_HOST_USE ? ROOT : SERVER_PREFIX + ADMIN_PATH;
}
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
*/
2019-07-05 03:19:24 +08:00
export function rootUser() {
return 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
* @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 attachmentRaw(type, download, customSpecSuffix) {
customSpecSuffix = undefined === customSpecSuffix ? getHash() : customSpecSuffix;
2019-07-05 03:19:24 +08:00
return (
SERVER_PREFIX +
'/Raw/' +
SUB_QUERY_PREFIX +
'/' +
customSpecSuffix +
'/' +
type +
'/' +
SUB_QUERY_PREFIX +
'/' +
download
);
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) {
2016-06-16 07:36:44 +08:00
return attachmentRaw('Download', download, customSpecSuffix);
}
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 attachmentPreview(download, customSpecSuffix) {
2016-06-16 07:36:44 +08:00
return attachmentRaw('View', download, customSpecSuffix);
}
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 attachmentThumbnailPreview(download, customSpecSuffix) {
2016-06-16 07:36:44 +08:00
return attachmentRaw('ViewThumbnail', download, customSpecSuffix);
}
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 attachmentPreviewAsPlain(download, customSpecSuffix) {
2016-06-16 07:36:44 +08:00
return attachmentRaw('ViewAsPlain', download, customSpecSuffix);
}
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 attachmentFramed(download, customSpecSuffix) {
2016-06-16 07:36:44 +08:00
return attachmentRaw('FramedView', download, customSpecSuffix);
}
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) {
return SERVER_PREFIX + '/' + type + '/' + SUB_QUERY_PREFIX + '/' + getHash() + '/';
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 upload() {
2016-06-16 07:36:44 +08:00
return serverRequest('Upload');
}
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 uploadContacts() {
2016-06-16 07:36:44 +08:00
return serverRequest('UploadContacts');
}
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 uploadBackground() {
2016-06-16 07:36:44 +08:00
return serverRequest('UploadBackground');
}
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 append() {
2016-06-16 07:36:44 +08:00
return serverRequest('Append');
}
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) {
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} requestHash
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 messageViewLink(requestHash) {
return (
SERVER_PREFIX +
'/Raw/' +
SUB_QUERY_PREFIX +
'/' +
getHash() +
2019-07-05 03:19:24 +08:00
'/ViewAsPlain/' +
SUB_QUERY_PREFIX +
'/' +
requestHash
);
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} requestHash
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 messageDownloadLink(requestHash) {
return (
SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/' + getHash() + '/Download/' + SUB_QUERY_PREFIX + '/' + requestHash
2019-07-05 03:19:24 +08:00
);
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 avatarLink(email) {
return SERVER_PREFIX + '/Raw/0/Avatar/' + 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 publicLink(hash) {
2016-06-16 07:36:44 +08:00
return SERVER_PREFIX + '/Raw/0/Public/' + hash + '/';
}
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) {
return (
SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/' + getHash() + '/UserBackground/' + SUB_QUERY_PREFIX + '/' + hash
2019-07-05 03:19:24 +08:00
);
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) {
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
/**
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 exportContactsVcf() {
return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/' + getHash() + '/ContactsVcf/';
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 exportContactsCsv() {
return SERVER_PREFIX + '/Raw/' + SUB_QUERY_PREFIX + '/' + getHash() + '/ContactsCsv/';
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
*/
2019-07-05 03:19:24 +08:00
export function staticPrefix(path) {
2016-06-16 07:36:44 +08:00
return STATIC_PREFIX + path;
}
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 emptyContactPic() {
2016-06-16 07:36:44 +08:00
return staticPrefix('css/images/empty-contact.png');
}
2015-11-15 08:23:16 +08:00
2016-06-16 07:36:44 +08:00
/**
* @param {string} fileName
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 sound(fileName) {
2016-06-16 07:36:44 +08:00
return staticPrefix('sounds/' + fileName);
}
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 notificationMailIcon() {
return staticPrefix('css/images/icon-message-notification.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
/**
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() {
2016-06-16 07:36:44 +08:00
return staticPrefix('js/min/openpgp.min.js');
}
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() {
2016-06-16 07:36:44 +08:00
return staticPrefix('js/min/openpgp.worker.min.js');
}
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 openPgpWorkerPath() {
2016-06-16 07:36:44 +08:00
return staticPrefix('js/min/');
}
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)) {
theme = theme.substr(0, theme.length - 7).trim();
2016-06-16 07:36:44 +08:00
prefix = WEB_PREFIX;
2015-11-15 08:23:16 +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
*/
2019-07-05 03:19:24 +08:00
export function inbox(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
/**
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 about() {
2016-06-16 07:36:44 +08:00
return HASH_PREFIX + 'about';
}
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 = '') {
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
if (folder) {
2016-06-16 07:36:44 +08:00
const resultThreadUid = pInt(threadUid);
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) {
result = result.replace(/[/]+$/, '');
2016-06-16 07:36:44 +08:00
result += '/p' + page;
2015-11-15 08:23:16 +08:00
}
if (search) {
2019-07-05 03:19:24 +08:00
result = result.replace(/[/]+$/, '');
result += '/' + encodeURI(search);
2015-11-15 08:23:16 +08:00
}
2016-06-16 07:36:44 +08:00
return result;
}