chore: fixes

This commit is contained in:
Simon Ding
2024-07-15 09:49:56 +08:00
parent ffa94c9357
commit 53a0c7d471
8 changed files with 52 additions and 24 deletions

View File

@@ -32,7 +32,7 @@ func (s *Server) authModdleware(c *gin.Context) {
auth = strings.TrimPrefix(auth, "Bearer ")
log.Infof("current token: %v", auth)
token, err := jwt.ParseWithClaims(auth, &jwt.RegisteredClaims{}, func(t *jwt.Token) (interface{}, error) {
return []byte(secretKey), nil
return []byte(s.jwtSerect), nil
})
if err != nil {
log.Errorf("parse token error: %v", err)
@@ -60,7 +60,6 @@ type LoginIn struct {
Password string `json:"password"`
}
const secretKey = "r1OF7nhpNjnYiGKtTLuKEVq7YznzT"
func (s *Server) Login(c *gin.Context) (interface{}, error) {
var in LoginIn
@@ -89,7 +88,7 @@ func (s *Server) Login(c *gin.Context) (interface{}, error) {
IssuedAt: jwt.NewNumericDate(time.Now()),
NotBefore: jwt.NewNumericDate(time.Now()),
})
sig, err := token.SignedString([]byte(secretKey))
sig, err := token.SignedString([]byte(s.jwtSerect))
if err != nil {
return nil, errors.Wrap(err, "sign")
}

View File

@@ -31,11 +31,13 @@ type Server struct {
cron *cron.Cron
language string
tasks map[int]*Task
jwtSerect string
}
func (s *Server) Serve() error {
s.scheduler()
s.reloadTasks()
s.jwtSerect = s.db.GetSetting(db.JwtSerectKey)
//st, _ := fs.Sub(ui.Web, "build/web")
s.r.Use(static.Serve("/", static.EmbedFolder(ui.Web, "build/web")))

View File

@@ -154,5 +154,6 @@ func (s *Server) DeleteFromWatchlist(c *gin.Context) (interface{}, error) {
if err := s.db.DeleteSeries(id); err != nil {
return nil, errors.Wrap(err, "delete db")
}
os.RemoveAll(filepath.Join(db.ImgPath, ids)) //delete image related
return "success", nil
}