Skip to content

Commit

Permalink
style: try to remove withUser for all URL (withUser removing step-2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 committed Feb 28, 2025
1 parent 1a09caf commit c977cf6
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 912 deletions.
4 changes: 0 additions & 4 deletions packages/backend/files/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,6 @@ func (i *FileInfo) RealPath() string {
return i.Path
}

// TODO: use constants
//
//nolint:goconst
func (i *FileInfo) detectType(modify, saveContent, readHeader bool) error {
if IsNamedPipe(i.Mode) {
i.Type = "blob"
Expand Down Expand Up @@ -531,7 +528,6 @@ func (i *FileInfo) detectSubtitles() {
ext := filepath.Ext(i.Path)

// detect multiple languages. Base*.vtt
// TODO: give subtitles descriptive names (lang) and track attributes
parentDir := strings.TrimRight(i.Path, i.Name)
dir, err := afero.ReadDir(i.Fs, parentDir)
if err == nil {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/files/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Listing struct {
//nolint:goconst
func (l Listing) ApplySort() {
// Check '.Order' to know how to sort
// TODO: use enum
if !l.Sorting.Asc {
switch l.Sorting.By {
case "name":
Expand Down
16 changes: 6 additions & 10 deletions packages/backend/http/auth.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package http

import (
"net/http"
)

func withUser(fn handleFunc) handleFunc {
return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
d.user, _ = d.store.Users.Get(d.server.Root, uint(1))
return fn(w, r, d)
}
}
//func withUser(fn handleFunc) handleFunc {
// return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
// d.user, _ = d.store.Users.Get(d.server.Root, uint(1))
// return fn(w, r, d)
// }
//}
6 changes: 2 additions & 4 deletions packages/backend/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ func NewHandler(
api.PathPrefix("/resources").Handler(monkey(resourcePostHandler(fileCache), "/api/resources")).Methods("POST")
api.PathPrefix("/resources").Handler(monkey(resourcePutHandler, "/api/resources")).Methods("PUT")
api.PathPrefix("/resources").Handler(monkey(resourcePatchHandler(fileCache), "/api/resources")).Methods("PATCH")
api.PathPrefix("/mount").Handler(monkey(resourceMountHandler(fileCache), "/api/mount")).Methods("POST")
api.PathPrefix("/unmount").Handler(monkey(resourceUnmountHandler(fileCache), "/api/unmount")).Methods("DELETE")
api.PathPrefix("/mount").Handler(monkey(resourceMountHandler, "/api/mount")).Methods("POST")
api.PathPrefix("/unmount").Handler(monkey(resourceUnmountHandler, "/api/unmount")).Methods("DELETE")
// Because /api/resources/AppData is proxied under current arch, new api must be of a different prefix,
// and try to access /api/resources/AppData in the handle func.
api.PathPrefix("/paste").Handler(monkey(resourcePasteHandler(fileCache), "/api/paste")).Methods("PATCH")

api.PathPrefix("/usage").Handler(monkey(diskUsage, "/api/usage")).Methods("GET")

api.PathPrefix("/raw").Handler(monkey(rawHandler, "/api/raw")).Methods("GET")
api.PathPrefix("/md5").Handler(monkey(md5Handler, "/api/md5")).Methods("GET")
api.PathPrefix("/smb_history").Handler(monkey(smbHistoryGetHandler, "/api/smb_history")).Methods("GET")
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/http/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,20 @@ func md5FileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo
return renderJSON(w, r, responseData)
}

var md5Handler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
func md5Handler(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
srcType := r.URL.Query().Get("src")
if srcType == "sync" {
return md5Sync(w, r)
}

if !d.user.Perm.Download {
return http.StatusAccepted, nil
}
//if !d.user.Perm.Download {
// return http.StatusAccepted, nil
//}

file, err := files.NewFileInfo(files.FileOptions{
Fs: d.user.Fs,
Fs: files.DefaultFs, // d.user.Fs,
Path: r.URL.Path,
Modify: d.user.Perm.Modify,
Modify: true, // d.user.Perm.Modify,
Expand: false,
ReadHeader: d.server.TypeDetectionByHeader,
Checker: d,
Expand All @@ -143,4 +143,4 @@ var md5Handler = withUser(func(w http.ResponseWriter, r *http.Request, d *data)
}

return md5FileHandler(w, r, file)
})
}
Loading

0 comments on commit c977cf6

Please sign in to comment.