refactor (api): move rm/mv/touch/mkdir to http post

This commit is contained in:
Mickael Kerjean
2022-09-13 12:51:27 +10:00
parent 0acf94ce0c
commit fa84e37df2
3 changed files with 10 additions and 10 deletions

View File

@ -49,7 +49,7 @@ export function http_post(url, data, type = "json", params) {
xhr.open("POST", url, true); xhr.open("POST", url, true);
xhr.withCredentials = true; xhr.withCredentials = true;
xhr.setRequestHeader("X-Requested-With", "XmlHttpRequest"); xhr.setRequestHeader("X-Requested-With", "XmlHttpRequest");
if (type === "json") { if (data && type === "json") {
data = JSON.stringify(data); data = JSON.stringify(data);
xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("Content-Type", "application/json");
} }

View File

@ -134,7 +134,7 @@ class FileSystem {
return this._replace(path, "loading") return this._replace(path, "loading")
.then((res) => this.current_path === dirname(path) ? .then((res) => this.current_path === dirname(path) ?
this._ls_from_cache(dirname(path)) : Promise.resolve(res)) this._ls_from_cache(dirname(path)) : Promise.resolve(res))
.then(() => http_get(url)) .then(() => http_post(url))
.then((res) => { .then((res) => {
return cache.remove(cache.FILE_CONTENT, [currentShare(), path]) return cache.remove(cache.FILE_CONTENT, [currentShare(), path])
.then(cache.remove(cache.FILE_CONTENT, [currentShare(), path], false)) .then(cache.remove(cache.FILE_CONTENT, [currentShare(), path], false))
@ -228,7 +228,7 @@ class FileSystem {
const action_execute = (part_of_a_batch_operation = false) => { const action_execute = (part_of_a_batch_operation = false) => {
if (part_of_a_batch_operation === true) { if (part_of_a_batch_operation === true) {
return http_get(url) return http_post(url)
.then(() => { .then(() => {
return this._replace(destination_path, null, "loading") return this._replace(destination_path, null, "loading")
.then(() => this._refresh(destination_path)); .then(() => this._refresh(destination_path));
@ -240,7 +240,7 @@ class FileSystem {
}); });
} }
return http_get(url) return http_post(url)
.then(() => { .then(() => {
return this._replace(destination_path, null, "loading") return this._replace(destination_path, null, "loading")
.then(() => origin_path !== destination_path ? .then(() => origin_path !== destination_path ?
@ -325,7 +325,7 @@ class FileSystem {
return http_post(url, file, "blob", params); return http_post(url, file, "blob", params);
} else { } else {
const url = appendShareToUrl("/api/files/touch?path=" + prepare(path)); const url = appendShareToUrl("/api/files/touch?path=" + prepare(path));
return http_get(url); return http_post(url);
} }
} }
}; };
@ -347,7 +347,7 @@ class FileSystem {
return this._replace(origin_path, "loading") return this._replace(origin_path, "loading")
.then(this._add(destination_path, "loading")) .then(this._add(destination_path, "loading"))
.then(() => this._refresh(origin_path, destination_path)) .then(() => this._refresh(origin_path, destination_path))
.then(() => http_get(url)) .then(() => http_post(url))
.then((res) => { .then((res) => {
return this._remove(origin_path, "loading") return this._remove(origin_path, "loading")
.then(() => this._replace(destination_path, null, "loading")) .then(() => this._replace(destination_path, null, "loading"))

View File

@ -67,10 +67,10 @@ func Init(a App) {
files.HandleFunc("/cat", NewMiddlewareChain(FileAccess, middlewares, a)).Methods("OPTIONS") files.HandleFunc("/cat", NewMiddlewareChain(FileAccess, middlewares, a)).Methods("OPTIONS")
files.HandleFunc("/cat", NewMiddlewareChain(FileSave, middlewares, a)).Methods("POST") files.HandleFunc("/cat", NewMiddlewareChain(FileSave, middlewares, a)).Methods("POST")
files.HandleFunc("/ls", NewMiddlewareChain(FileLs, middlewares, a)).Methods("GET") files.HandleFunc("/ls", NewMiddlewareChain(FileLs, middlewares, a)).Methods("GET")
files.HandleFunc("/mv", NewMiddlewareChain(FileMv, middlewares, a)).Methods("GET") files.HandleFunc("/mv", NewMiddlewareChain(FileMv, middlewares, a)).Methods("POST")
files.HandleFunc("/rm", NewMiddlewareChain(FileRm, middlewares, a)).Methods("GET") files.HandleFunc("/rm", NewMiddlewareChain(FileRm, middlewares, a)).Methods("POST")
files.HandleFunc("/mkdir", NewMiddlewareChain(FileMkdir, middlewares, a)).Methods("GET") files.HandleFunc("/mkdir", NewMiddlewareChain(FileMkdir, middlewares, a)).Methods("POST")
files.HandleFunc("/touch", NewMiddlewareChain(FileTouch, middlewares, a)).Methods("GET") files.HandleFunc("/touch", NewMiddlewareChain(FileTouch, middlewares, a)).Methods("POST")
middlewares = []Middleware{ApiHeaders, SessionStart, LoggedInOnly} middlewares = []Middleware{ApiHeaders, SessionStart, LoggedInOnly}
files.HandleFunc("/search", NewMiddlewareChain(FileSearch, middlewares, a)).Methods("GET") files.HandleFunc("/search", NewMiddlewareChain(FileSearch, middlewares, a)).Methods("GET")