-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats_manager.js
More file actions
68 lines (63 loc) · 1.95 KB
/
Copy pathstats_manager.js
File metadata and controls
68 lines (63 loc) · 1.95 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
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* BioOS Global Stats Manager (Powered by Netlify Functions)
*/
export async function logAttempt(cmd, shield, result) {
const entry = {
time: new Date().toLocaleString(),
cmd: cmd,
shield: shield,
result: result
};
// [HU] Szinkronizálás a szerveren keresztül
// [EN] Sync through the server
try {
await fetch('/.netlify/functions/sync_stats', {
method: 'POST',
body: JSON.stringify(entry)
});
} catch (e) {
console.error("[BioOS] Cloud sync failed.", e);
}
}
export async function getStats() {
try {
const response = await fetch('/.netlify/functions/sync_stats');
if (response.ok) {
return await response.json();
}
} catch (e) {
console.error("[BioOS] Error fetching global stats.");
}
return { total: 0, blocked: 0, recent: [] };
}
export async function getSecureProof(data, shieldState, fingerprint) {
try {
const response = await fetch('/.netlify/functions/get_proof', {
method: 'POST',
body: JSON.stringify({
data: data,
shield_state: shieldState,
fingerprint: fingerprint
})
});
const result = await response.json();
return result.verification_dna;
} catch (e) {
return "ERROR_SEC_OFFLINE";
}
}
export async function verifyHash(hash, fingerprint) {
try {
const response = await fetch('/.netlify/functions/check_proof', {
method: 'POST',
body: JSON.stringify({
hash: hash,
fingerprint: fingerprint
})
});
const result = await response.json();
return result; // [HU] Most már a teljes objektumot adjuk vissza (valid, mode)
} catch (e) {
return { valid: false, mode: "NONE" };
}
}