-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.ts
34 lines (28 loc) · 929 Bytes
/
upload.ts
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
import axios from 'axios';
export async function upload(file: File, language: string){
const formData = new FormData();
formData.append('file', file);
formData.append('language', language);
let resp = await axios.post("/upload", formData, {
headers: {
'content-type': 'multipart/form-data'
}
});
if (resp.status != 200){
throw new Error(`Ran into error: http:${resp.status} ${resp.statusText} details:${resp.data}`);
}
return resp.data;
}
export async function update(code: string, language: string){
const formData = new FormData();
formData.append('code', code);
formData.append('language', language);
let resp = await axios.post("/update", formData, {
headers: {
}
});
if (resp.status != 200){
throw new Error(`Ran into error: http:${resp.status} ${resp.statusText} details:${resp.data}`);
}
return resp.data;
}