2020-11-17 23:39:27 +01:00
|
|
|
<script context="module">
|
|
|
|
|
2020-12-01 23:01:21 +01:00
|
|
|
export const fs_get_buckets = async () => {
|
|
|
|
const resp = await fetch(window.api_endpoint+"/filesystem");
|
|
|
|
if(resp.status >= 400) {
|
|
|
|
throw new Error(resp.text());
|
|
|
|
}
|
|
|
|
return resp.json();
|
|
|
|
}
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
export const fs_create_directory = async (bucket, path, dir_name) => {
|
2020-11-17 23:39:27 +01:00
|
|
|
if (!path.startsWith("/")) {
|
|
|
|
path = "/" + path
|
|
|
|
}
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
const form = new FormData()
|
2020-11-17 23:39:27 +01:00
|
|
|
form.append("type", "dir")
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
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());
|
|
|
|
}
|
2020-11-17 23:39:27 +01:00
|
|
|
}
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
export const fs_get_node = async (bucket, path) => {
|
2020-11-17 23:39:27 +01:00
|
|
|
if (!path.startsWith("/")) {
|
|
|
|
path = "/" + path
|
|
|
|
}
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
const resp = await fetch(
|
|
|
|
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path)+"?stat"
|
|
|
|
);
|
|
|
|
if(resp.status >= 400) {
|
|
|
|
throw new Error(resp.text());
|
|
|
|
}
|
|
|
|
return resp.json();
|
2020-11-17 23:39:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const fs_get_file_url = (bucket, path) => {
|
|
|
|
if (!path.startsWith("/")) {
|
|
|
|
path = "/" + path
|
|
|
|
}
|
|
|
|
return window.api_endpoint + "/filesystem/" + bucket + encodeURIComponent(path)
|
|
|
|
}
|
|
|
|
|
2020-12-01 23:01:21 +01:00
|
|
|
export const fs_rename_node = async (bucket, old_path, new_path) => {
|
|
|
|
if (!old_path.startsWith("/")) { old_path = "/" + old_path }
|
|
|
|
if (!new_path.startsWith("/")) { new_path = "/" + new_path }
|
|
|
|
|
|
|
|
const form = new FormData()
|
|
|
|
form.append("move_to", 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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
export const fs_delete_node = async (bucket, path) => {
|
2020-11-17 23:39:27 +01:00
|
|
|
if (!path.startsWith("/")) {
|
|
|
|
path = "/" + path
|
|
|
|
}
|
|
|
|
|
2020-11-26 11:13:27 +01:00
|
|
|
const resp = await fetch(
|
2020-12-01 23:01:21 +01:00
|
|
|
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path)+"?recursive",
|
2020-11-26 11:13:27 +01:00
|
|
|
{ method: "DELETE" }
|
|
|
|
);
|
|
|
|
if(resp.status >= 400) {
|
|
|
|
throw new Error(resp.text());
|
|
|
|
}
|
2020-11-17 23:39:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|