2018-03-02 05:21:49 +00:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { uploadMedia } from '../_api/media'
|
|
|
|
import { toast } from '../_utils/toast'
|
|
|
|
|
2018-03-03 01:54:38 +00:00
|
|
|
export async function doMediaUpload (file) {
|
2018-03-02 05:21:49 +00:00
|
|
|
let instanceName = store.get('currentInstance')
|
|
|
|
let accessToken = store.get('accessToken')
|
|
|
|
store.set({uploadingMedia: true})
|
|
|
|
try {
|
|
|
|
let response = await uploadMedia(instanceName, accessToken, file)
|
|
|
|
let mediaToUpload = store.get('mediaToUpload') || []
|
|
|
|
mediaToUpload.push({
|
|
|
|
data: response,
|
|
|
|
file: file
|
|
|
|
})
|
|
|
|
store.set({ mediaToUpload })
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
toast.say('Failed to upload media: ' + (e.message || ''))
|
|
|
|
} finally {
|
|
|
|
store.set({uploadingMedia: false})
|
|
|
|
}
|
2018-03-03 01:54:38 +00:00
|
|
|
}
|