2022-02-07 18:44:04 +00:00
|
|
|
import { coerce, gt, gte, lt, lte, SemVer } from 'semver';
|
|
|
|
|
2022-03-21 20:44:06 +00:00
|
|
|
export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: string, token: string, server: string): string => {
|
|
|
|
if (attachmentUrl && attachmentUrl.startsWith('http')) {
|
2022-02-07 18:44:04 +00:00
|
|
|
if (attachmentUrl.includes('rc_token')) {
|
|
|
|
return encodeURI(attachmentUrl);
|
|
|
|
}
|
|
|
|
return encodeURI(`${attachmentUrl}?rc_uid=${userId}&rc_token=${token}`);
|
|
|
|
}
|
|
|
|
return encodeURI(`${server}${attachmentUrl}?rc_uid=${userId}&rc_token=${token}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const methods = {
|
|
|
|
lowerThan: lt,
|
|
|
|
lowerThanOrEqualTo: lte,
|
|
|
|
greaterThan: gt,
|
|
|
|
greaterThanOrEqualTo: gte
|
|
|
|
};
|
|
|
|
|
|
|
|
export const compareServerVersion = (
|
2022-03-15 17:33:29 +00:00
|
|
|
currentServerVersion: string | null | undefined,
|
2022-02-07 18:44:04 +00:00
|
|
|
method: keyof typeof methods,
|
|
|
|
versionToCompare: string
|
|
|
|
): boolean =>
|
|
|
|
(currentServerVersion && methods[method](coerce(currentServerVersion) as string | SemVer, versionToCompare)) as boolean;
|
|
|
|
|
|
|
|
export const generateLoadMoreId = (id: string): string => `load-more-${id}`;
|