summaryrefslogtreecommitdiff
path: root/frontend/app/api
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-16 16:38:07 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-16 16:38:07 +0100
commita9d86650f40a82a64d1fd8e0525c26422d314d3a (patch)
tree6afbd4a520f557b377096e6bb8a0838c0b725f7e /frontend/app/api
parent6e18c6e4ef6344f92fed99dad9c83484487c32d7 (diff)
make uploads like animism. start audio stuff
Diffstat (limited to 'frontend/app/api')
-rw-r--r--frontend/app/api/crud.upload.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/frontend/app/api/crud.upload.js b/frontend/app/api/crud.upload.js
index 8c1b265..2837dd4 100644
--- a/frontend/app/api/crud.upload.js
+++ b/frontend/app/api/crud.upload.js
@@ -1,4 +1,5 @@
import { as_type } from 'app/api/crud.types'
+import { session } from 'app/session'
export function crud_upload(type, data, dispatch) {
return new Promise( (resolve, reject) => {
@@ -6,9 +7,17 @@ export function crud_upload(type, data, dispatch) {
const { id } = data
const fd = new FormData()
+ if (!data.tag) {
+ data.tag = 'misc'
+ }
Object.keys(data).forEach(key => {
- if (key !== 'id') {
+ if (key.indexOf('__') !== -1) return
+ if (key === 'id') return
+ const fn_key = `__${key}_filename`
+ if (fn_key in data) {
+ fd.append(key, data[key], data[fn_key])
+ } else {
fd.append(key, data[key])
}
})
@@ -23,12 +32,11 @@ export function crud_upload(type, data, dispatch) {
xhr.addEventListener("error", uploadFailed, false)
xhr.addEventListener("abort", uploadCancelled, false)
xhr.open("POST", url)
+ xhr.setRequestHeader("Authorization", "Bearer " + session.get("access_token"))
xhr.send(fd)
dispatch && dispatch({ type: as_type(type, 'upload_loading')})
- let complete = false
-
function uploadProgress (e) {
if (e.lengthComputable) {
const percent = Math.round(e.loaded * 100 / e.total) || 0