diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-19 16:50:04 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-08-19 16:50:04 +0200 |
commit | 2857052a38c9ad2c5946f6101bf7d37d63235df8 (patch) | |
tree | 8c80c37560336171b5b0e550a0244ebbcfc1e160 /pkg | |
parent | 6531b1c0a720a63ee3127f9a09f14ba861838b01 (diff) | |
download | lens-2857052a38c9ad2c5946f6101bf7d37d63235df8.tar.gz lens-2857052a38c9ad2c5946f6101bf7d37d63235df8.tar.bz2 lens-2857052a38c9ad2c5946f6101bf7d37d63235df8.zip |
fix: Fix various linting error
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/ext/middleware.go | 10 | ||||
-rw-r--r-- | pkg/ext/responses.go | 2 | ||||
-rw-r--r-- | pkg/list/list.go | 1 | ||||
-rw-r--r-- | pkg/service/auth.go | 15 | ||||
-rw-r--r-- | pkg/view/album.go | 3 | ||||
-rw-r--r-- | pkg/view/auth.go | 4 | ||||
-rw-r--r-- | pkg/view/filesystem.go | 2 | ||||
-rw-r--r-- | pkg/view/media.go | 2 | ||||
-rw-r--r-- | pkg/worker/scanner/album_scanner.go | 1 |
9 files changed, 21 insertions, 19 deletions
diff --git a/pkg/ext/middleware.go b/pkg/ext/middleware.go index fe2d185..2cf70cf 100644 --- a/pkg/ext/middleware.go +++ b/pkg/ext/middleware.go @@ -56,7 +56,7 @@ func NewAuthMiddleware(key []byte, log *logrus.Entry) *AuthMiddleware { func (a *AuthMiddleware) LoggedIn(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - path := string(r.URL.Path) + path := r.URL.Path if path == "/login" || path == "/initial" { next(w, r) return @@ -82,7 +82,7 @@ func (a *AuthMiddleware) LoggedIn(next http.HandlerFunc) http.HandlerFunc { http.Redirect(w, r, redirectLogin, http.StatusTemporaryRedirect) return } - r = r.WithContext(context.WithValue(r.Context(), "token", token)) + r = r.WithContext(context.WithValue(r.Context(), service.TokenKey, token)) a.entry. WithField("userID", token.UserID). WithField("username", token.Username). @@ -91,8 +91,8 @@ func (a *AuthMiddleware) LoggedIn(next http.HandlerFunc) http.HandlerFunc { } } -func GetTokenFromCtx(w http.ResponseWriter, r *http.Request) *service.Token { - tokenValue := r.Context().Value("token") +func GetTokenFromCtx(r *http.Request) *service.Token { + tokenValue := r.Context().Value(service.TokenKey) if token, ok := tokenValue.(*service.Token); ok { return token } @@ -112,7 +112,7 @@ func NewInitialSetupMiddleware(userRepository repository.UserRepository) *Initia func (i *InitialSetupMiddleware) Check(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { // if user has been set to context it is logged in already - token := GetTokenFromCtx(w, r) + token := GetTokenFromCtx(r) if token == nil { next(w, r) return diff --git a/pkg/ext/responses.go b/pkg/ext/responses.go index ba58dd5..34e5f27 100644 --- a/pkg/ext/responses.go +++ b/pkg/ext/responses.go @@ -7,7 +7,7 @@ import ( "git.sr.ht/~gabrielgio/img/templates" ) -func NotFound(w http.ResponseWriter, r *http.Request) { +func NotFound(w http.ResponseWriter) { templates.WritePageTemplate(w, &templates.ErrorPage{ Err: "Not Found", }) diff --git a/pkg/list/list.go b/pkg/list/list.go index b6b6b89..482e5bf 100644 --- a/pkg/list/list.go +++ b/pkg/list/list.go @@ -26,7 +26,6 @@ func Distribuite[T any](slice []T, size int) [][]T { chuncks[x] = append(chuncks[x], slice[end]) } - } return chuncks diff --git a/pkg/service/auth.go b/pkg/service/auth.go index f27cf88..30e574a 100644 --- a/pkg/service/auth.go +++ b/pkg/service/auth.go @@ -105,7 +105,7 @@ func (u *AuthController) Upsert( ) error { if id != nil { if err := u.userRepository.Update(ctx, *id, &repository.UpdateUser{ - Username: string(username), + Username: username, Name: name, IsAdmin: isAdmin, Path: path, @@ -140,10 +140,15 @@ func (u *AuthController) Upsert( return err } -type Token struct { - UserID uint - Username string -} +type ( + AuthKey string + Token struct { + UserID uint + Username string + } +) + +const TokenKey AuthKey = "token" func ReadToken(data []byte, key []byte) (*Token, error) { block, err := aes.NewCipher(key) diff --git a/pkg/view/album.go b/pkg/view/album.go index 9e70b4b..b19e381 100644 --- a/pkg/view/album.go +++ b/pkg/view/album.go @@ -30,7 +30,7 @@ func NewAlbumView( func (self *AlbumView) Index(w http.ResponseWriter, r *http.Request) error { p := getPagination(r) - token := ext.GetTokenFromCtx(w, r) + token := ext.GetTokenFromCtx(r) // TODO: optmize call, GetPathFromUserID may no be necessary userPath, err := self.userRepository.GetPathFromUserID(r.Context(), token.UserID) @@ -67,7 +67,6 @@ func (self *AlbumView) Index(w http.ResponseWriter, r *http.Request) error { if err != nil { return err } - } medias, err := self.mediaRepository.List(r.Context(), p) diff --git a/pkg/view/auth.go b/pkg/view/auth.go index 2a4b95e..1b87235 100644 --- a/pkg/view/auth.go +++ b/pkg/view/auth.go @@ -19,7 +19,7 @@ func NewAuthView(userController *service.AuthController) *AuthView { } } -func (v *AuthView) LoginView(w http.ResponseWriter, r *http.Request) error { +func (v *AuthView) LoginView(w http.ResponseWriter, _ *http.Request) error { templates.WritePageTemplate(w, &templates.LoginPage{}) return nil } @@ -72,7 +72,7 @@ func Index(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/login", http.StatusTemporaryRedirect) } -func (v *AuthView) InitialRegisterView(w http.ResponseWriter, r *http.Request) error { +func (v *AuthView) InitialRegisterView(w http.ResponseWriter, _ *http.Request) error { templates.WritePageTemplate(w, &templates.RegisterPage{}) return nil } diff --git a/pkg/view/filesystem.go b/pkg/view/filesystem.go index d49ad4f..24f0ce6 100644 --- a/pkg/view/filesystem.go +++ b/pkg/view/filesystem.go @@ -34,7 +34,7 @@ func NewFileSystemView( func (self *FileSystemView) Index(w http.ResponseWriter, r *http.Request) error { var ( pathValue = r.FormValue("path") - token = ext.GetTokenFromCtx(w, r) + token = ext.GetTokenFromCtx(r) ) page, err := self.fsService.GetPage(r.Context(), token.UserID, pathValue) diff --git a/pkg/view/media.go b/pkg/view/media.go index f490ce1..3041998 100644 --- a/pkg/view/media.go +++ b/pkg/view/media.go @@ -71,7 +71,7 @@ func NewMediaView( func (self *MediaView) Index(w http.ResponseWriter, r *http.Request) error { p := getPagination(r) - token := ext.GetTokenFromCtx(w, r) + token := ext.GetTokenFromCtx(r) userPath, err := self.userRepository.GetPathFromUserID(r.Context(), token.UserID) if err != nil { diff --git a/pkg/worker/scanner/album_scanner.go b/pkg/worker/scanner/album_scanner.go index 04af9bc..6413cb1 100644 --- a/pkg/worker/scanner/album_scanner.go +++ b/pkg/worker/scanner/album_scanner.go @@ -85,7 +85,6 @@ func (e *AlbumScanner) GetAndCreateNestedAlbuns(ctx context.Context, paths []str Name: filepath.Base(paths[0]), Path: paths[0], }) - } func FanInwards(paths []string) []string { |