2018-03-01 21:21:49 -08:00
|
|
|
import { auth, basename } from './utils'
|
2018-04-09 18:30:15 -07:00
|
|
|
import { postWithTimeout, putWithTimeout } from '../_utils/ajax'
|
2018-03-01 21:21:49 -08:00
|
|
|
|
2018-03-05 22:36:54 -08:00
|
|
|
export async function uploadMedia (instanceName, accessToken, file, description) {
|
2018-03-01 21:21:49 -08:00
|
|
|
let formData = new FormData()
|
|
|
|
formData.append('file', file)
|
2018-04-09 18:30:15 -07:00
|
|
|
if (description) {
|
|
|
|
formData.append('description', description)
|
|
|
|
}
|
2018-03-01 21:21:49 -08:00
|
|
|
let url = `${basename(instanceName)}/api/v1/media`
|
|
|
|
return postWithTimeout(url, formData, auth(accessToken))
|
2018-03-02 17:54:38 -08:00
|
|
|
}
|
2018-04-09 18:30:15 -07:00
|
|
|
|
|
|
|
export async function putMediaDescription (instanceName, accessToken, mediaId, description) {
|
|
|
|
let url = `${basename(instanceName)}/api/v1/media/${mediaId}`
|
|
|
|
return putWithTimeout(url, {description}, auth(accessToken))
|
|
|
|
}
|