mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-12 18:28:03 +01:00
parent
00c6aa1843
commit
e714004aca
@ -1,17 +1,41 @@
|
|||||||
import { auth, basename } from './utils.js'
|
import { auth, basename } from './utils.js'
|
||||||
import { post, put, MEDIA_WRITE_TIMEOUT, WRITE_TIMEOUT } from '../_utils/ajax.js'
|
import { post, put, MEDIA_WRITE_TIMEOUT, WRITE_TIMEOUT } from '../_utils/ajax.js'
|
||||||
|
|
||||||
export async function uploadMedia (instanceName, accessToken, file, description) {
|
async function doUploadMedia (version, instanceName, accessToken, file, description) {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', file)
|
formData.append('file', file)
|
||||||
if (description) {
|
if (description) {
|
||||||
formData.append('description', description)
|
formData.append('description', description)
|
||||||
}
|
}
|
||||||
const url = `${basename(instanceName)}/api/v1/media`
|
const url = `${basename(instanceName)}/api/${version}/media`
|
||||||
return post(url, formData, auth(accessToken), { timeout: MEDIA_WRITE_TIMEOUT })
|
return post(url, formData, auth(accessToken), { timeout: MEDIA_WRITE_TIMEOUT })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function putMediaMetadata (instanceName, accessToken, mediaId, description, focus) {
|
async function doPutMediaMetadata (version, instanceName, accessToken, mediaId, description, focus) {
|
||||||
const url = `${basename(instanceName)}/api/v1/media/${mediaId}`
|
const url = `${basename(instanceName)}/api/${version}/media/${mediaId}`
|
||||||
return put(url, { description, focus: (focus && focus.join(',')) }, auth(accessToken), { timeout: WRITE_TIMEOUT })
|
return put(url, { description, focus: (focus && focus.join(',')) }, auth(accessToken), { timeout: WRITE_TIMEOUT })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function uploadMedia (instanceName, accessToken, file, description) {
|
||||||
|
try {
|
||||||
|
return (await doUploadMedia('v2', instanceName, accessToken, file, description))
|
||||||
|
} catch (err) {
|
||||||
|
if (err && err.status === 404) { // fall back to old search API
|
||||||
|
return doUploadMedia('v1', instanceName, accessToken, file, description)
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function putMediaMetadata (instanceName, accessToken, mediaId, description, focus) {
|
||||||
|
try {
|
||||||
|
return (await doPutMediaMetadata('v2', instanceName, accessToken, mediaId, description, focus))
|
||||||
|
} catch (err) {
|
||||||
|
if (err && err.status === 404) { // fall back to old search API
|
||||||
|
return doPutMediaMetadata('v1', instanceName, accessToken, mediaId, description, focus)
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user