mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-02 00:36:38 +00:00
format device approval message
This commit is contained in:
67
src/lib/formatDeviceFingerprint.ts
Normal file
67
src/lib/formatDeviceFingerprint.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
type DeviceFingerprint = {
|
||||
platform: string | null;
|
||||
osVersion: string | null;
|
||||
kernelVersion?: string | null;
|
||||
arch: string | null;
|
||||
deviceModel: string | null;
|
||||
serialNumber: string | null;
|
||||
username: string | null;
|
||||
hostname: string | null;
|
||||
} | null;
|
||||
|
||||
/**
|
||||
* Formats a platform string to a human-readable format
|
||||
*/
|
||||
export function formatPlatform(platform: string | null | undefined): string {
|
||||
if (!platform) return "-";
|
||||
const platformMap: Record<string, string> = {
|
||||
macos: "macOS",
|
||||
windows: "Windows",
|
||||
linux: "Linux",
|
||||
ios: "iOS",
|
||||
android: "Android",
|
||||
unknown: "Unknown"
|
||||
};
|
||||
return platformMap[platform.toLowerCase()] || platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats device fingerprint information into a human-readable string
|
||||
*
|
||||
* @param fingerprint - The device fingerprint object
|
||||
* @param t - Translation function from next-intl
|
||||
* @returns Formatted string with device information
|
||||
*/
|
||||
export function formatFingerprintInfo(
|
||||
fingerprint: DeviceFingerprint,
|
||||
t: (key: string) => string
|
||||
): string {
|
||||
if (!fingerprint) return "";
|
||||
const parts: string[] = [];
|
||||
|
||||
if (fingerprint.platform) {
|
||||
parts.push(
|
||||
`${t("platform")}: ${formatPlatform(fingerprint.platform)}`
|
||||
);
|
||||
}
|
||||
if (fingerprint.deviceModel) {
|
||||
parts.push(`${t("deviceModel")}: ${fingerprint.deviceModel}`);
|
||||
}
|
||||
if (fingerprint.osVersion) {
|
||||
parts.push(`${t("osVersion")}: ${fingerprint.osVersion}`);
|
||||
}
|
||||
if (fingerprint.arch) {
|
||||
parts.push(`${t("architecture")}: ${fingerprint.arch}`);
|
||||
}
|
||||
if (fingerprint.hostname) {
|
||||
parts.push(`${t("hostname")}: ${fingerprint.hostname}`);
|
||||
}
|
||||
if (fingerprint.username) {
|
||||
parts.push(`${t("username")}: ${fingerprint.username}`);
|
||||
}
|
||||
if (fingerprint.serialNumber) {
|
||||
parts.push(`${t("serialNumber")}: ${fingerprint.serialNumber}`);
|
||||
}
|
||||
|
||||
return parts.join("\n");
|
||||
}
|
||||
@@ -342,6 +342,17 @@ export type ApprovalItem = {
|
||||
username: string;
|
||||
email: string | null;
|
||||
};
|
||||
deviceName: string | null;
|
||||
fingerprint: {
|
||||
platform: string | null;
|
||||
osVersion: string | null;
|
||||
kernelVersion: string | null;
|
||||
arch: string | null;
|
||||
deviceModel: string | null;
|
||||
serialNumber: string | null;
|
||||
username: string | null;
|
||||
hostname: string | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export const approvalQueries = {
|
||||
|
||||
Reference in New Issue
Block a user