mirror of
https://github.com/AlistGo/alist.git
synced 2025-06-18 10:22:30 +08:00
feat: token and reset
This commit is contained in:
@ -1,13 +1,35 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/utils/random"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ResetToken(c *gin.Context) {
|
||||
token := random.Token()
|
||||
item := model.SettingItem{Key: "token", Value: token, Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE}
|
||||
if err := db.SaveSettingItem(item); err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, token)
|
||||
}
|
||||
|
||||
func GetSetting(c *gin.Context) {
|
||||
key := c.Query("key")
|
||||
item, err := db.GetSettingItemByKey(key)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, item)
|
||||
}
|
||||
|
||||
func SaveSettings(c *gin.Context) {
|
||||
var req []model.SettingItem
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
|
Reference in New Issue
Block a user