-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_meta.js
More file actions
26 lines (24 loc) · 790 Bytes
/
_meta.js
File metadata and controls
26 lines (24 loc) · 790 Bytes
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
import { Singleton, Calculate } from './index.js';
const callback;
const trigger = (data, meta, path) => {
const payload =
{
time: Date.now(),
auth: Singleton.auth.uid || null,
path: path || null,
size: Calculate(data) || null,
meta: typeof meta =="string"? meta: JSON.stringify(meta) || null,
};
if (Singleton)
return await fetch(Singleton.dbUrl + `/tracker/meta.json`, {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
method: "POST",
})
else {
if (callback && typeof callback == "function") callback(payload);
else return payload;
}
}
const setCallback = (func) => callback = func;
export default { trigger, setCallback }