vn-verdnaturachat/app/lib/utils.ts

28 lines
966 B
TypeScript
Raw Normal View History

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')) {
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 = (
currentServerVersion: string | null | undefined,
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}`;