@@ -1,5 +1,19 @@
|
||||
<script context="module">
|
||||
|
||||
export const fs_create_bucket = async (name) => {
|
||||
const form = new FormData()
|
||||
form.append("name", name)
|
||||
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem",
|
||||
{ method: "POST", body: form }
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(resp.text());
|
||||
}
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
export const fs_get_buckets = async () => {
|
||||
const resp = await fetch(window.api_endpoint+"/filesystem");
|
||||
if(resp.status >= 400) {
|
||||
@@ -8,6 +22,18 @@ export const fs_get_buckets = async () => {
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
export const fs_delete_bucket = async (id, recursive) => {
|
||||
let uri = window.api_endpoint+"/filesystem/"+encodeURIComponent(id)
|
||||
if (recursive) {
|
||||
uri += "?recursive"
|
||||
}
|
||||
|
||||
const resp = await fetch(uri, { method: "DELETE" });
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(resp.text());
|
||||
}
|
||||
}
|
||||
|
||||
export const fs_create_directory = async (bucket, path, dir_name) => {
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path
|
||||
@@ -16,12 +42,12 @@ export const fs_create_directory = async (bucket, path, dir_name) => {
|
||||
const form = new FormData()
|
||||
form.append("type", "dir")
|
||||
|
||||
const resp=await fetch(
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path+"/"+dir_name),
|
||||
{ method: "POST", body: form }
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(resp.text());
|
||||
throw new Error(resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +60,9 @@ export const fs_get_node = async (bucket, path) => {
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path)+"?stat"
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(resp.text());
|
||||
throw new Error(resp.text())
|
||||
}
|
||||
return resp.json();
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
export const fs_get_file_url = (bucket, path) => {
|
||||
@@ -56,9 +82,9 @@ export const fs_rename_node = async (bucket, old_path, new_path) => {
|
||||
const resp=await fetch(
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(old_path),
|
||||
{ method: "PUT", body: form }
|
||||
);
|
||||
)
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(resp.text());
|
||||
throw new Error(resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +98,7 @@ export const fs_delete_node = async (bucket, path) => {
|
||||
{ method: "DELETE" }
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(resp.text());
|
||||
throw new Error(resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user