semaphore/src/routes/_api/media.js

18 lines
772 B
JavaScript
Raw Normal View History

import { auth, basename } from './utils.js'
import { post, put, MEDIA_WRITE_TIMEOUT, WRITE_TIMEOUT } from '../_utils/ajax.js'
2018-03-02 05:21:49 +00:00
2018-03-06 06:36:54 +00:00
export async function uploadMedia (instanceName, accessToken, file, description) {
2019-08-03 21:49:37 +01:00
const formData = new FormData()
2018-03-02 05:21:49 +00:00
formData.append('file', file)
if (description) {
formData.append('description', description)
}
2019-08-03 21:49:37 +01:00
const url = `${basename(instanceName)}/api/v1/media`
return post(url, formData, auth(accessToken), { timeout: MEDIA_WRITE_TIMEOUT })
2018-03-03 01:54:38 +00:00
}
export async function putMediaMetadata (instanceName, accessToken, mediaId, description, focus) {
2019-08-03 21:49:37 +01:00
const url = `${basename(instanceName)}/api/v1/media/${mediaId}`
return put(url, { description, focus: (focus && focus.join(',')) }, auth(accessToken), { timeout: WRITE_TIMEOUT })
}