2025-10-22 01:36:18 +03:00
|
|
|
import { IncomingHttpHeaders } from 'node:http';
|
|
|
|
|
import { UAParser } from 'ua-parser-js';
|
|
|
|
|
|
2024-05-02 15:42:26 -04:00
|
|
|
export const fromChecksum = (checksum: string): Buffer => {
|
|
|
|
|
return Buffer.from(checksum, checksum.length === 28 ? 'base64' : 'hex');
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-29 12:14:03 -04:00
|
|
|
export const fromMaybeArray = <T>(param: T | T[]) => (Array.isArray(param) ? param[0] : param);
|
2025-10-22 01:36:18 +03:00
|
|
|
|
|
|
|
|
const getAppVersionFromUA = (ua: string) =>
|
|
|
|
|
ua.match(/^Immich_(?:Android|iOS)_(?<appVersion>.+)$/)?.groups?.appVersion ?? null;
|
|
|
|
|
|
|
|
|
|
export const getUserAgentDetails = (headers: IncomingHttpHeaders) => {
|
|
|
|
|
const userAgent = UAParser(headers['user-agent']);
|
|
|
|
|
const appVersion = getAppVersionFromUA(headers['user-agent'] ?? '');
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
deviceType: userAgent.browser.name || userAgent.device.type || (headers['devicemodel'] as string) || '',
|
|
|
|
|
deviceOS: userAgent.os.name || (headers['devicetype'] as string) || '',
|
|
|
|
|
appVersion,
|
|
|
|
|
};
|
|
|
|
|
};
|