Skip to content

Commit

Permalink
Parse file path from url
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Sep 19, 2024
1 parent 8085a65 commit 5cde16d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,12 @@ func parseCryptKey(rsp http.ResponseWriter, repoID string, user string, version
func accessV2CB(rsp http.ResponseWriter, r *http.Request) *appError {
vars := mux.Vars(r)
repoID := vars["repoid"]
filePath := vars["filepath"]

filePath := r.URL.Query().Get("p")
op := r.URL.Query().Get("op")
if filePath == "" {
msg := "No file path\n"
return &appError{nil, msg, http.StatusBadRequest}
}

decPath, err := url.PathUnescape(filePath)
if err != nil {
msg := fmt.Sprintf("File path %s can't be decoded\n", filePath)
Expand All @@ -251,6 +249,7 @@ func accessV2CB(rsp http.ResponseWriter, r *http.Request) *appError {
rpath := getCanonPath(decPath)
fileName := filepath.Base(rpath)

op := r.URL.Query().Get("op")
if op != "view" && op != "download" {
msg := "Operation is neither view or download\n"
return &appError{nil, msg, http.StatusBadRequest}
Expand Down
2 changes: 1 addition & 1 deletion fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func newHTTPRouter() *mux.Router {
r.Handle("/f/{.*}{slash:\\/?}", appHandler(accessLinkCB))
//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
r.Handle("/repo/{repoid:[\\da-z]{8}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{4}-[\\da-z]{12}}/permission-check{slash:\\/?}",
Expand Down
6 changes: 3 additions & 3 deletions server/access-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,16 +1500,16 @@ access_v2_cb(evhtp_request_t *req, void *arg)
GError *error = NULL;

/* Skip the first '/'. */
char **parts = g_strsplit (req->uri->path->full + 1, "/", 0);
if (!parts || g_strv_length (parts) < 3 ||
char **parts = g_strsplit (req->uri->path->full + 1, "/", 4);
if (!parts || g_strv_length (parts) < 4 ||
strcmp (parts[2], "files") != 0) {
error_str = "Invalid URL\n";
goto out;
}

repo_id = parts[1];

path = evhtp_kv_find (req->uri->query, "p");
path = parts[3];
if (!path) {
error_str = "No file path\n";
goto out;
Expand Down

0 comments on commit 5cde16d

Please sign in to comment.