implemented user file upload and project file upload
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -42,8 +42,7 @@
|
||||
method: 'POST'
|
||||
});
|
||||
if (res.ok) {
|
||||
yikes();
|
||||
loadChildren(window.location.pathname);
|
||||
handleDirectory(res);
|
||||
new_dir = null;
|
||||
} else {
|
||||
error(res);
|
||||
@@ -51,6 +50,14 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async function handleDirectory(res){
|
||||
let json = await res.json();
|
||||
if (json.dirs) children.dirs = json.dirs;
|
||||
if (json.files) children.files = json.files;
|
||||
if (json.title) children.title = json.title;
|
||||
yikes();
|
||||
}
|
||||
|
||||
async function loadChildren(p){
|
||||
p = p.substring(6);
|
||||
if (p == '') p = '/';
|
||||
@@ -67,14 +74,10 @@
|
||||
const url = api(`files${p}`);
|
||||
const res = await fetch(url,{credentials:'include'});
|
||||
if (res.ok){
|
||||
let json = await res.json();
|
||||
if (json.dirs) children.dirs = json.dirs;
|
||||
if (json.files) children.files = json.files;
|
||||
if (json.title) children.title = json.title;
|
||||
parent = p.substring(0, p.lastIndexOf("/"));
|
||||
if (parent == '/user'||p=='/project'||p=='/company') parent = '/';
|
||||
form = !(p=='/company'||p=='/project'||p=='/user');
|
||||
yikes();
|
||||
handleDirectory(res);
|
||||
} else {
|
||||
error(res);
|
||||
}
|
||||
@@ -98,18 +101,18 @@
|
||||
|
||||
async function upload_file(ev){
|
||||
ev.preventDefault();
|
||||
console.log(files);
|
||||
const dataArray = new FormData();
|
||||
dataArray.append("uploadFile", files);
|
||||
const url = api('files'+path);
|
||||
const resp = fetch(url, {
|
||||
const url = api('files'+path+'/'+files[0].name);
|
||||
const resp = await fetch(url, {
|
||||
credentials: 'include',
|
||||
method: 'POST',
|
||||
headers: [["Content-Type", "multipart/form-data"]],
|
||||
body: dataArray
|
||||
headers: {
|
||||
"Content-Type": "application/unknown",
|
||||
},
|
||||
body: files[0]
|
||||
});
|
||||
if (resp.ok){
|
||||
yikes();
|
||||
handleDirectory(resp);
|
||||
files = null;
|
||||
} else {
|
||||
error(resp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user