From 07b23027c195abae2ad88bc06ed25a34740239d8 Mon Sep 17 00:00:00 2001 From: liwei Date: Wed, 24 Jun 2020 09:14:05 +0800 Subject: [PATCH] refactor: preview router use regex --- http/http.go | 2 +- http/preview.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/http/http.go b/http/http.go index 0dba44c0..c4b99918 100644 --- a/http/http.go +++ b/http/http.go @@ -59,7 +59,7 @@ func NewHandler(store *storage.Storage, server *settings.Server) (http.Handler, api.Handle("/settings", monkey(settingsPutHandler, "")).Methods("PUT") api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET") - api.PathPrefix("/preview/{size}").Handler(monkey(previewHandler, "/api/preview")).Methods("GET") + api.PathPrefix("/preview/{size}/{path:.*}").Handler(monkey(previewHandler, "/api/preview")).Methods("GET") api.PathPrefix("/command").Handler(monkey(commandsHandler, "/api/command")).Methods("GET") api.PathPrefix("/search").Handler(monkey(searchHandler, "/api/search")).Methods("GET") diff --git a/http/preview.go b/http/preview.go index c869a955..87ccf3d7 100644 --- a/http/preview.go +++ b/http/preview.go @@ -6,7 +6,6 @@ import ( "io" "net/http" "net/url" - "strings" "github.com/disintegration/imaging" "github.com/gorilla/mux" @@ -31,11 +30,9 @@ var previewHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *da return http.StatusNotImplemented, nil } - // Resolve file path from URL - path := "/" + strings.Join(strings.Split(r.URL.Path, "/")[2:], "/") file, err := files.NewFileInfo(files.FileOptions{ Fs: d.user.Fs, - Path: path, + Path: "/" + vars["path"], Modify: d.user.Perm.Modify, Expand: true, Checker: d,