1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-08-17 14:27:32 +00:00

Parse file path from url (#702)

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks 2024-09-19 16:59:35 +08:00 committed by GitHub
parent 8085a65174
commit 6649fada8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 7 deletions

View File

@ -235,14 +235,12 @@ func parseCryptKey(rsp http.ResponseWriter, repoID string, user string, version
func accessV2CB(rsp http.ResponseWriter, r *http.Request) *appError { func accessV2CB(rsp http.ResponseWriter, r *http.Request) *appError {
vars := mux.Vars(r) vars := mux.Vars(r)
repoID := vars["repoid"] repoID := vars["repoid"]
filePath := vars["filepath"]
filePath := r.URL.Query().Get("p")
op := r.URL.Query().Get("op")
if filePath == "" { if filePath == "" {
msg := "No file path\n" msg := "No file path\n"
return &appError{nil, msg, http.StatusBadRequest} return &appError{nil, msg, http.StatusBadRequest}
} }
decPath, err := url.PathUnescape(filePath) decPath, err := url.PathUnescape(filePath)
if err != nil { if err != nil {
msg := fmt.Sprintf("File path %s can't be decoded\n", filePath) msg := fmt.Sprintf("File path %s can't be decoded\n", filePath)
@ -251,6 +249,7 @@ func accessV2CB(rsp http.ResponseWriter, r *http.Request) *appError {
rpath := getCanonPath(decPath) rpath := getCanonPath(decPath)
fileName := filepath.Base(rpath) fileName := filepath.Base(rpath)
op := r.URL.Query().Get("op")
if op != "view" && op != "download" { if op != "view" && op != "download" {
msg := "Operation is neither view or download\n" msg := "Operation is neither view or download\n"
return &appError{nil, msg, http.StatusBadRequest} return &appError{nil, msg, http.StatusBadRequest}

View File

@ -470,7 +470,7 @@ func newHTTPRouter() *mux.Router {
r.Handle("/f/{.*}{slash:\\/?}", appHandler(accessLinkCB)) r.Handle("/f/{.*}{slash:\\/?}", appHandler(accessLinkCB))
//r.Handle("/d/{.*}", appHandler(accessDirLinkCB)) //r.Handle("/d/{.*}", appHandler(accessDirLinkCB))
r.Handle("/repos/{repoid:[\\da-z]{8}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{12}}/files{slash:\\/?}", appHandler(accessV2CB)) r.Handle("/repos/{repoid:[\\da-z]{8}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{12}}/files/{filepath:.*}", appHandler(accessV2CB))
// file syncing api // file syncing api
r.Handle("/repo/{repoid:[\\da-z]{8}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{12}}/permission-check{slash:\\/?}", r.Handle("/repo/{repoid:[\\da-z]{8}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{12}}/permission-check{slash:\\/?}",

View File

@ -1500,8 +1500,8 @@ access_v2_cb(evhtp_request_t *req, void *arg)
GError *error = NULL; GError *error = NULL;
/* Skip the first '/'. */ /* Skip the first '/'. */
char **parts = g_strsplit (req->uri->path->full + 1, "/", 0); char **parts = g_strsplit (req->uri->path->full + 1, "/", 4);
if (!parts || g_strv_length (parts) < 3 || if (!parts || g_strv_length (parts) < 4 ||
strcmp (parts[2], "files") != 0) { strcmp (parts[2], "files") != 0) {
error_str = "Invalid URL\n"; error_str = "Invalid URL\n";
goto out; goto out;
@ -1509,7 +1509,7 @@ access_v2_cb(evhtp_request_t *req, void *arg)
repo_id = parts[1]; repo_id = parts[1];
path = evhtp_kv_find (req->uri->query, "p"); path = parts[3];
if (!path) { if (!path) {
error_str = "No file path\n"; error_str = "No file path\n";
goto out; goto out;