-
Notifications
You must be signed in to change notification settings - Fork 56
/
secret.js
65 lines (54 loc) · 1.53 KB
/
secret.js
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
import config from '../config';
export const createSecret = async (formData = {}, token = '') => {
const options = {
method: 'POST',
cache: 'no-cache',
body: formData,
};
if (token) {
Object.assign(options, {
headers: {
Authorization: `Bearer ${token}`,
},
});
}
try {
const data = await fetch(`${config.get('api.host')}/secret`, options);
const json = await data.json();
return { ...json, statusCode: data.status };
} catch (e) {
console.error(e);
}
};
export const getSecret = async (secretId, encryptionKey, password) => {
const data = await fetch(`${config.get('api.host')}/secret/${secretId}`, {
method: 'POST',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ password, encryptionKey }),
});
if (data.status === 401) {
return {
statusCode: 401,
};
}
return await data.json();
};
export const burnSecret = async (secretId) => {
const data = await fetch(`${config.get('api.host')}/secret/${secretId}/burn`, {
method: 'POST',
cache: 'no-cache',
});
return await data.json();
};
export const secretExists = async (secretId) => {
const data = await fetch(`${config.get('api.host')}/secret/${secretId}/exist`);
if (data.status === 401) {
return {
statusCode: 401,
};
}
return await data.json();
};