2018-03-02 05:21:49 +00:00
|
|
|
import { auth, basename } from './utils'
|
2018-06-13 14:38:36 +00:00
|
|
|
import { post, put, MEDIA_WRITE_TIMEOUT, WRITE_TIMEOUT } from '../_utils/ajax'
|
2018-03-02 05:21:49 +00:00
|
|
|
|
2018-03-06 06:36:54 +00:00
|
|
|
export async function uploadMedia (instanceName, accessToken, file, description) {
|
2018-03-02 05:21:49 +00:00
|
|
|
let formData = new FormData()
|
|
|
|
formData.append('file', file)
|
2018-04-10 01:30:15 +00:00
|
|
|
if (description) {
|
|
|
|
formData.append('description', description)
|
|
|
|
}
|
2018-03-02 05:21:49 +00:00
|
|
|
let url = `${basename(instanceName)}/api/v1/media`
|
2018-08-30 04:42:57 +00:00
|
|
|
return post(url, formData, auth(accessToken), { timeout: MEDIA_WRITE_TIMEOUT })
|
2018-03-03 01:54:38 +00:00
|
|
|
}
|
2018-04-10 01:30:15 +00:00
|
|
|
|
|
|
|
export async function putMediaDescription (instanceName, accessToken, mediaId, description) {
|
|
|
|
let url = `${basename(instanceName)}/api/v1/media/${mediaId}`
|
2018-08-30 04:42:57 +00:00
|
|
|
return put(url, { description }, auth(accessToken), { timeout: WRITE_TIMEOUT })
|
2018-04-10 01:30:15 +00:00
|
|
|
}
|