/
upload.ts
45 lines (42 loc) · 1.08 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
import { AxiosInstance } from 'axios'
import * as raw from './raw'
import { Stream } from 'stream'
import { GetSpaceEnvironmentParams } from './common-types'
export const create = (
http: AxiosInstance,
params: GetSpaceEnvironmentParams,
data: { file: string | ArrayBuffer | Stream }
) => {
const { file } = data
if (!file) {
return Promise.reject(new Error('Unable to locate a file to upload.'))
}
return raw.post(
http,
`/spaces/${params.spaceId}/environments/${params.environmentId}/uploads`,
file,
{
headers: {
'Content-Type': 'application/octet-stream',
},
}
)
}
export const del = (
http: AxiosInstance,
params: GetSpaceEnvironmentParams & { uploadId: string }
) => {
return raw.del(
http,
`/spaces/${params.spaceId}/environments/${params.environmentId}/uploads/${params.uploadId}`
)
}
export const get = (
http: AxiosInstance,
params: GetSpaceEnvironmentParams & { uploadId: string }
) => {
return raw.get(
http,
`/spaces/${params.spaceId}/environments/${params.environmentId}/uploads/${params.uploadId}`
)
}