Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse file path from url #702

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading