-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendSourceMap.js
28 lines (25 loc) · 960 Bytes
/
sendSourceMap.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
const API_HOST = 'https://www.handsomelai.shop';
const SOURCE_MAP_ENDPOINT = '/api/1.0/sourceMap';
const sendSourceMap = async (map, userKey, clientToken) => {
if (!map || !userKey || !clientToken) {
throw new Error('Missing required parameters');
}
// send multi-form request
const formData = new FormData();
// The contentType is set to application/octet-stream, which is a generic binary stream.
const blob = new Blob([map]);
formData.append('map', blob, 'bundle.js.map');
formData.append('userKey', userKey);
formData.append('clientToken', clientToken);
const res = await fetch(`${API_HOST}${SOURCE_MAP_ENDPOINT}`, {
method: 'POST',
body: formData,
});
if (!res.ok && `${res.status}`.startsWith('4')) {
const errorMessage = await res.text();
const msg = JSON.parse(errorMessage);
throw new Error(`Failed to upload source map: ${msg.data}`);
}
return await res.json();
};
export default sendSourceMap;