From fa84e37df200db13ce5bb476cb6c35250e38edfe Mon Sep 17 00:00:00 2001 From: Mickael Kerjean Date: Tue, 13 Sep 2022 12:51:27 +1000 Subject: [PATCH] refactor (api): move rm/mv/touch/mkdir to http post --- client/helpers/ajax.js | 2 +- client/model/files.js | 10 +++++----- server/main.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client/helpers/ajax.js b/client/helpers/ajax.js index e51c2e17..75cf0601 100644 --- a/client/helpers/ajax.js +++ b/client/helpers/ajax.js @@ -49,7 +49,7 @@ export function http_post(url, data, type = "json", params) { xhr.open("POST", url, true); xhr.withCredentials = true; xhr.setRequestHeader("X-Requested-With", "XmlHttpRequest"); - if (type === "json") { + if (data && type === "json") { data = JSON.stringify(data); xhr.setRequestHeader("Content-Type", "application/json"); } diff --git a/client/model/files.js b/client/model/files.js index c573dd27..720de696 100644 --- a/client/model/files.js +++ b/client/model/files.js @@ -134,7 +134,7 @@ class FileSystem { return this._replace(path, "loading") .then((res) => this.current_path === dirname(path) ? this._ls_from_cache(dirname(path)) : Promise.resolve(res)) - .then(() => http_get(url)) + .then(() => http_post(url)) .then((res) => { return cache.remove(cache.FILE_CONTENT, [currentShare(), path]) .then(cache.remove(cache.FILE_CONTENT, [currentShare(), path], false)) @@ -228,7 +228,7 @@ class FileSystem { const action_execute = (part_of_a_batch_operation = false) => { if (part_of_a_batch_operation === true) { - return http_get(url) + return http_post(url) .then(() => { return this._replace(destination_path, null, "loading") .then(() => this._refresh(destination_path)); @@ -240,7 +240,7 @@ class FileSystem { }); } - return http_get(url) + return http_post(url) .then(() => { return this._replace(destination_path, null, "loading") .then(() => origin_path !== destination_path ? @@ -325,7 +325,7 @@ class FileSystem { return http_post(url, file, "blob", params); } else { 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") .then(this._add(destination_path, "loading")) .then(() => this._refresh(origin_path, destination_path)) - .then(() => http_get(url)) + .then(() => http_post(url)) .then((res) => { return this._remove(origin_path, "loading") .then(() => this._replace(destination_path, null, "loading")) diff --git a/server/main.go b/server/main.go index 77bee2ba..75c15fae 100644 --- a/server/main.go +++ b/server/main.go @@ -67,10 +67,10 @@ func Init(a App) { files.HandleFunc("/cat", NewMiddlewareChain(FileAccess, middlewares, a)).Methods("OPTIONS") files.HandleFunc("/cat", NewMiddlewareChain(FileSave, middlewares, a)).Methods("POST") files.HandleFunc("/ls", NewMiddlewareChain(FileLs, middlewares, a)).Methods("GET") - files.HandleFunc("/mv", NewMiddlewareChain(FileMv, middlewares, a)).Methods("GET") - files.HandleFunc("/rm", NewMiddlewareChain(FileRm, middlewares, a)).Methods("GET") - files.HandleFunc("/mkdir", NewMiddlewareChain(FileMkdir, middlewares, a)).Methods("GET") - files.HandleFunc("/touch", NewMiddlewareChain(FileTouch, middlewares, a)).Methods("GET") + files.HandleFunc("/mv", NewMiddlewareChain(FileMv, middlewares, a)).Methods("POST") + files.HandleFunc("/rm", NewMiddlewareChain(FileRm, middlewares, a)).Methods("POST") + files.HandleFunc("/mkdir", NewMiddlewareChain(FileMkdir, middlewares, a)).Methods("POST") + files.HandleFunc("/touch", NewMiddlewareChain(FileTouch, middlewares, a)).Methods("POST") middlewares = []Middleware{ApiHeaders, SessionStart, LoggedInOnly} files.HandleFunc("/search", NewMiddlewareChain(FileSearch, middlewares, a)).Methods("GET")