-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathindex.ts
More file actions
55 lines (45 loc) · 1.51 KB
/
Copy pathindex.ts
File metadata and controls
55 lines (45 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { AssetItem, RawAssetData } from "~/types/index";
export function transformAssetData(rawData: RawAssetData): AssetItem {
const item: AssetItem = {
id: rawData.id,
name: rawData.name || "-",
address: rawData.address || "-",
zone: rawData.zone?.name || "-",
comment: rawData.comment || "-",
type: rawData.type?.value || "-",
platform: rawData.platform?.name || "-",
category: rawData.category?.value || "-",
isActive: rawData.is_active ?? false,
permedAccounts: rawData.permedAccounts || [],
permedProtocols: rawData.permedProtocols || []
};
return item;
}
export function transformAssetsData(rawDataArray: RawAssetData[]): AssetItem[] {
const data: AssetItem[] = [];
for (let i = 0; i < rawDataArray.length; i++) {
const item = rawDataArray[i];
if (item) {
const transformedItem = transformAssetData(item);
data.push(transformedItem);
}
}
return data;
}
/**
* @description 获取操作系统的语言
*/
export async function resolveLanguageFromCookies(): Promise<"zh" | "en"> {
const normalize = (lang: string | null | undefined) => {
if (!lang) return "en" as const;
const normalized = lang.toLowerCase();
if (normalized.includes("zh")) return "zh" as const;
return "en" as const;
};
const locale = await useTauriOsLocale();
if (locale) {
return normalize(locale);
}
const fallback = (typeof navigator !== "undefined" && (navigator.language || navigator.languages?.[0])) || "";
return normalize(fallback);
}