refactor: preview router use regex

This commit is contained in:
liwei 2020-06-24 09:14:05 +08:00
parent 3543eab26b
commit 07b23027c1
2 changed files with 2 additions and 5 deletions

View File

@ -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")

View File

@ -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,