diff --git a/pkg/ext/middleware.go b/pkg/ext/middleware.go
index fe2d185be75a28df5f686dabb664b237f85d56ae..2cf70cf0567b5348c7bc2cd459340d233c1db35d 100644
--- a/pkg/ext/middleware.go
+++ b/pkg/ext/middleware.go
@@ -56,7 +56,7 @@ }
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 @@ a.entry.Error(err)
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 @@ next(w, r)
}
}
-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 (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 ba58dd5d54d2a7d27a5a3a0c241240d3ec747614..34e5f278bf1d8e22dc9af9a9fd2584060b81abb1 100644
--- a/pkg/ext/responses.go
+++ b/pkg/ext/responses.go
@@ -7,7 +7,7 @@
"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 b6b6b89135839693af2eb32d797c76492381af2c..482e5bfeb2622dd890a125085cf3ad7e0e676b44 100644
--- a/pkg/list/list.go
+++ b/pkg/list/list.go
@@ -26,7 +26,6 @@ }
chuncks[x] = append(chuncks[x], slice[end])
}
-
}
return chuncks
diff --git a/pkg/service/auth.go b/pkg/service/auth.go
index f27cf885dc73e0bd3b3ff706a129388ea0b65a9a..30e574a9690f2c33f6a89f08fa089f8776020102 100644
--- a/pkg/service/auth.go
+++ b/pkg/service/auth.go
@@ -105,7 +105,7 @@ path string,
) 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 @@
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 9e70b4b7b832bae74032c8d9ca67cfac613de5b8..b19e381bb5008ca4468fc6bd5f7b492ab07d8148 100644
--- a/pkg/view/album.go
+++ b/pkg/view/album.go
@@ -30,7 +30,7 @@ }
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 @@ albums, err = self.mediaRepository.ListAlbums(r.Context(), *p.AlbumID)
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 2a4b95e77f23249aaa99b9c644ae39e6926029db..1b87235ed7a45f011cc695a650c793d3d493bc91 100644
--- a/pkg/view/auth.go
+++ b/pkg/view/auth.go
@@ -19,7 +19,7 @@ userController: userController,
}
}
-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 d49ad4ff02e0b62f151c8570ed4598b73d504cde..24f0ce61e6d169b2406b7081feeb965377b63036 100644
--- a/pkg/view/filesystem.go
+++ b/pkg/view/filesystem.go
@@ -34,7 +34,7 @@
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 f490ce1e77f979d19c995e17be7b382a34aee3d1..3041998f465d49976d644a3a8b83f292ebe8cb87 100644
--- a/pkg/view/media.go
+++ b/pkg/view/media.go
@@ -71,7 +71,7 @@ }
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 04af9bceac2ed534d76640f3682c558ade815986..6413cb194b5dcf2605fb8c3c6656309bc2f404df 100644
--- a/pkg/worker/scanner/album_scanner.go
+++ b/pkg/worker/scanner/album_scanner.go
@@ -85,7 +85,6 @@ ParentID: &a.ID,
Name: filepath.Base(paths[0]),
Path: paths[0],
})
-
}
func FanInwards(paths []string) []string {