使用Request.Context

This commit is contained in:
j2rong4cn
2025-07-12 22:47:26 +08:00
parent d669a62ccf
commit a0dc472e0e
11 changed files with 54 additions and 54 deletions

View File

@ -12,7 +12,7 @@ import (
) )
func NewAuthnInstance(c *gin.Context) (*webauthn.WebAuthn, error) { func NewAuthnInstance(c *gin.Context) (*webauthn.WebAuthn, error) {
siteUrl, err := url.Parse(common.GetApiUrl(c)) siteUrl, err := url.Parse(common.GetApiUrl(c.Request.Context()))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -17,14 +17,14 @@ func _pprof(g *gin.RouterGroup) {
} }
func debug(g *gin.RouterGroup) { func debug(g *gin.RouterGroup) {
g.GET("/path/*path", middlewares.Down(sign.Verify), func(ctx *gin.Context) { g.GET("/path/*path", middlewares.Down(sign.Verify), func(c *gin.Context) {
rawPath := ctx.Request.Context().Value(conf.PathKey).(string) rawPath := c.Request.Context().Value(conf.PathKey).(string)
ctx.JSON(200, gin.H{ c.JSON(200, gin.H{
"path": rawPath, "path": rawPath,
}) })
}) })
g.GET("/hide_privacy", func(ctx *gin.Context) { g.GET("/hide_privacy", func(c *gin.Context) {
common.ErrorStrResp(ctx, "This is ip: 1.1.1.1", 400) common.ErrorStrResp(c, "This is ip: 1.1.1.1", 400)
}) })
g.GET("/gc", func(c *gin.Context) { g.GET("/gc", func(c *gin.Context) {
runtime.GC() runtime.GC()

View File

@ -106,7 +106,7 @@ func FsArchiveMeta(c *gin.Context) {
}, },
Password: req.ArchivePass, Password: req.ArchivePass,
} }
ret, err := fs.ArchiveMeta(c, reqPath, model.ArchiveMetaArgs{ ret, err := fs.ArchiveMeta(c.Request.Context(), reqPath, model.ArchiveMetaArgs{
ArchiveArgs: archiveArgs, ArchiveArgs: archiveArgs,
Refresh: req.Refresh, Refresh: req.Refresh,
}) })
@ -176,7 +176,7 @@ func FsArchiveList(c *gin.Context) {
common.ErrorStrResp(c, "password is incorrect or you have no permission", 403) common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
return return
} }
objs, err := fs.ArchiveList(c, reqPath, model.ArchiveListArgs{ objs, err := fs.ArchiveList(c.Request.Context(), reqPath, model.ArchiveListArgs{
ArchiveInnerArgs: model.ArchiveInnerArgs{ ArchiveInnerArgs: model.ArchiveInnerArgs{
ArchiveArgs: model.ArchiveArgs{ ArchiveArgs: model.ArchiveArgs{
LinkArgs: model.LinkArgs{ LinkArgs: model.LinkArgs{
@ -260,7 +260,7 @@ func FsArchiveDecompress(c *gin.Context) {
} }
tasks := make([]task.TaskExtensionInfo, 0, len(srcPaths)) tasks := make([]task.TaskExtensionInfo, 0, len(srcPaths))
for _, srcPath := range srcPaths { for _, srcPath := range srcPaths {
t, e := fs.ArchiveDecompress(c, srcPath, dstDir, model.ArchiveDecompressArgs{ t, e := fs.ArchiveDecompress(c.Request.Context(), srcPath, dstDir, model.ArchiveDecompressArgs{
ArchiveInnerArgs: model.ArchiveInnerArgs{ ArchiveInnerArgs: model.ArchiveInnerArgs{
ArchiveArgs: model.ArchiveArgs{ ArchiveArgs: model.ArchiveArgs{
LinkArgs: model.LinkArgs{ LinkArgs: model.LinkArgs{
@ -305,7 +305,7 @@ func ArchiveDown(c *gin.Context) {
ArchiveProxy(c) ArchiveProxy(c)
return return
} else { } else {
link, _, err := fs.ArchiveDriverExtract(c, archiveRawPath, model.ArchiveInnerArgs{ link, _, err := fs.ArchiveDriverExtract(c.Request.Context(), archiveRawPath, model.ArchiveInnerArgs{
ArchiveArgs: model.ArchiveArgs{ ArchiveArgs: model.ArchiveArgs{
LinkArgs: model.LinkArgs{ LinkArgs: model.LinkArgs{
IP: c.ClientIP(), IP: c.ClientIP(),
@ -337,7 +337,7 @@ func ArchiveProxy(c *gin.Context) {
} }
if canProxy(storage, filename) { if canProxy(storage, filename) {
// TODO: Support external download proxy URL // TODO: Support external download proxy URL
link, file, err := fs.ArchiveDriverExtract(c, archiveRawPath, model.ArchiveInnerArgs{ link, file, err := fs.ArchiveDriverExtract(c.Request.Context(), archiveRawPath, model.ArchiveInnerArgs{
ArchiveArgs: model.ArchiveArgs{ ArchiveArgs: model.ArchiveArgs{
LinkArgs: model.LinkArgs{ LinkArgs: model.LinkArgs{
Header: c.Request.Header, Header: c.Request.Header,
@ -362,7 +362,7 @@ func ArchiveInternalExtract(c *gin.Context) {
archiveRawPath := c.Request.Context().Value(conf.PathKey).(string) archiveRawPath := c.Request.Context().Value(conf.PathKey).(string)
innerPath := utils.FixAndCleanPath(c.Query("inner")) innerPath := utils.FixAndCleanPath(c.Query("inner"))
password := c.Query("pass") password := c.Query("pass")
rc, size, err := fs.ArchiveInternalExtract(c, archiveRawPath, model.ArchiveInnerArgs{ rc, size, err := fs.ArchiveInternalExtract(c.Request.Context(), archiveRawPath, model.ArchiveInnerArgs{
ArchiveArgs: model.ArchiveArgs{ ArchiveArgs: model.ArchiveArgs{
LinkArgs: model.LinkArgs{ LinkArgs: model.LinkArgs{
Header: c.Request.Header, Header: c.Request.Header,

View File

@ -35,7 +35,7 @@ func Down(c *gin.Context) {
Proxy(c) Proxy(c)
return return
} else { } else {
link, _, err := fs.Link(c, rawPath, model.LinkArgs{ link, _, err := fs.Link(c.Request.Context(), rawPath, model.LinkArgs{
IP: c.ClientIP(), IP: c.ClientIP(),
Header: c.Request.Header, Header: c.Request.Header,
Type: c.Query("type"), Type: c.Query("type"),
@ -70,7 +70,7 @@ func Proxy(c *gin.Context) {
return return
} }
} }
link, file, err := fs.Link(c, rawPath, model.LinkArgs{ link, file, err := fs.Link(c.Request.Context(), rawPath, model.LinkArgs{
Header: c.Request.Header, Header: c.Request.Header,
Type: c.Query("type"), Type: c.Query("type"),
}) })

View File

@ -54,7 +54,7 @@ func FsRecursiveMove(c *gin.Context) {
} }
common.GinWithValue(c, conf.MetaKey, meta) common.GinWithValue(c, conf.MetaKey, meta)
rootFiles, err := fs.List(c, srcDir, &fs.ListArgs{}) rootFiles, err := fs.List(c.Request.Context(), srcDir, &fs.ListArgs{})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -62,7 +62,7 @@ func FsRecursiveMove(c *gin.Context) {
var existingFileNames []string var existingFileNames []string
if req.ConflictPolicy != OVERWRITE { if req.ConflictPolicy != OVERWRITE {
dstFiles, err := fs.List(c, dstDir, &fs.ListArgs{}) dstFiles, err := fs.List(c.Request.Context(), dstDir, &fs.ListArgs{})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -90,7 +90,7 @@ func FsRecursiveMove(c *gin.Context) {
if movingFile.IsDir() { if movingFile.IsDir() {
// directory, recursive move // directory, recursive move
subFilePath := movingFileName subFilePath := movingFileName
subFiles, err := fs.List(c, movingFileName, &fs.ListArgs{Refresh: true}) subFiles, err := fs.List(c.Request.Context(), movingFileName, &fs.ListArgs{Refresh: true})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -124,7 +124,7 @@ func FsRecursiveMove(c *gin.Context) {
var count = 0 var count = 0
for i, fileName := range movingFileNames { for i, fileName := range movingFileNames {
// move // move
err := fs.Move(c, fileName, dstDir, len(movingFileNames) > i+1) err := fs.Move(c.Request.Context(), fileName, dstDir, len(movingFileNames) > i+1)
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -174,7 +174,7 @@ func FsBatchRename(c *gin.Context) {
continue continue
} }
filePath := fmt.Sprintf("%s/%s", reqPath, renameObject.SrcName) filePath := fmt.Sprintf("%s/%s", reqPath, renameObject.SrcName)
if err := fs.Rename(c, filePath, renameObject.NewName); err != nil { if err := fs.Rename(c.Request.Context(), filePath, renameObject.NewName); err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
} }
@ -221,7 +221,7 @@ func FsRegexRename(c *gin.Context) {
return return
} }
files, err := fs.List(c, reqPath, &fs.ListArgs{}) files, err := fs.List(c.Request.Context(), reqPath, &fs.ListArgs{})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -232,7 +232,7 @@ func FsRegexRename(c *gin.Context) {
if srcRegexp.MatchString(file.GetName()) { if srcRegexp.MatchString(file.GetName()) {
filePath := fmt.Sprintf("%s/%s", reqPath, file.GetName()) filePath := fmt.Sprintf("%s/%s", reqPath, file.GetName())
newFileName := srcRegexp.ReplaceAllString(file.GetName(), req.NewNameRegex) newFileName := srcRegexp.ReplaceAllString(file.GetName(), req.NewNameRegex)
if err := fs.Rename(c, filePath, newFileName); err != nil { if err := fs.Rename(c.Request.Context(), filePath, newFileName); err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
} }

View File

@ -48,7 +48,7 @@ func FsMkdir(c *gin.Context) {
return return
} }
} }
if err := fs.MakeDir(c, reqPath); err != nil { if err := fs.MakeDir(c.Request.Context(), reqPath); err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
} }
@ -90,7 +90,7 @@ func FsMove(c *gin.Context) {
if !req.Overwrite { if !req.Overwrite {
for _, name := range req.Names { for _, name := range req.Names {
if res, _ := fs.Get(c, stdpath.Join(dstDir, name), &fs.GetArgs{NoLog: true}); res != nil { if res, _ := fs.Get(c.Request.Context(), stdpath.Join(dstDir, name), &fs.GetArgs{NoLog: true}); res != nil {
common.ErrorStrResp(c, fmt.Sprintf("file [%s] exists", name), 403) common.ErrorStrResp(c, fmt.Sprintf("file [%s] exists", name), 403)
return return
} }
@ -101,7 +101,7 @@ func FsMove(c *gin.Context) {
// All validation will be done asynchronously in the background // All validation will be done asynchronously in the background
var addedTasks []task.TaskExtensionInfo var addedTasks []task.TaskExtensionInfo
for i, name := range req.Names { for i, name := range req.Names {
t, err := fs.MoveWithTaskAndValidation(c, stdpath.Join(srcDir, name), dstDir, !req.Overwrite, len(req.Names) > i+1) t, err := fs.MoveWithTaskAndValidation(c.Request.Context(), stdpath.Join(srcDir, name), dstDir, !req.Overwrite, len(req.Names) > i+1)
if t != nil { if t != nil {
addedTasks = append(addedTasks, t) addedTasks = append(addedTasks, t)
} }
@ -152,7 +152,7 @@ func FsCopy(c *gin.Context) {
if !req.Overwrite { if !req.Overwrite {
for _, name := range req.Names { for _, name := range req.Names {
if res, _ := fs.Get(c, stdpath.Join(dstDir, name), &fs.GetArgs{NoLog: true}); res != nil { if res, _ := fs.Get(c.Request.Context(), stdpath.Join(dstDir, name), &fs.GetArgs{NoLog: true}); res != nil {
common.ErrorStrResp(c, fmt.Sprintf("file [%s] exists", name), 403) common.ErrorStrResp(c, fmt.Sprintf("file [%s] exists", name), 403)
return return
} }
@ -163,7 +163,7 @@ func FsCopy(c *gin.Context) {
// All validation will be done asynchronously in the background // All validation will be done asynchronously in the background
var addedTasks []task.TaskExtensionInfo var addedTasks []task.TaskExtensionInfo
for i, name := range req.Names { for i, name := range req.Names {
t, err := fs.Copy(c, stdpath.Join(srcDir, name), dstDir, len(req.Names) > i+1) t, err := fs.Copy(c.Request.Context(), stdpath.Join(srcDir, name), dstDir, len(req.Names) > i+1)
if t != nil { if t != nil {
addedTasks = append(addedTasks, t) addedTasks = append(addedTasks, t)
} }
@ -211,13 +211,13 @@ func FsRename(c *gin.Context) {
if !req.Overwrite { if !req.Overwrite {
dstPath := stdpath.Join(stdpath.Dir(reqPath), req.Name) dstPath := stdpath.Join(stdpath.Dir(reqPath), req.Name)
if dstPath != reqPath { if dstPath != reqPath {
if res, _ := fs.Get(c, dstPath, &fs.GetArgs{NoLog: true}); res != nil { if res, _ := fs.Get(c.Request.Context(), dstPath, &fs.GetArgs{NoLog: true}); res != nil {
common.ErrorStrResp(c, fmt.Sprintf("file [%s] exists", req.Name), 403) common.ErrorStrResp(c, fmt.Sprintf("file [%s] exists", req.Name), 403)
return return
} }
} }
} }
if err := fs.Rename(c, reqPath, req.Name); err != nil { if err := fs.Rename(c.Request.Context(), reqPath, req.Name); err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
} }
@ -250,7 +250,7 @@ func FsRemove(c *gin.Context) {
return return
} }
for _, name := range req.Names { for _, name := range req.Names {
err := fs.Remove(c, stdpath.Join(reqDir, name)) err := fs.Remove(c.Request.Context(), stdpath.Join(reqDir, name))
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -291,7 +291,7 @@ func FsRemoveEmptyDirectory(c *gin.Context) {
} }
common.GinWithValue(c, conf.MetaKey, meta) common.GinWithValue(c, conf.MetaKey, meta)
rootFiles, err := fs.List(c, srcDir, &fs.ListArgs{}) rootFiles, err := fs.List(c.Request.Context(), srcDir, &fs.ListArgs{})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -322,7 +322,7 @@ func FsRemoveEmptyDirectory(c *gin.Context) {
continue continue
} }
subFiles, err := fs.List(c, removingFilePath, &fs.ListArgs{Refresh: true}) subFiles, err := fs.List(c.Request.Context(), removingFilePath, &fs.ListArgs{Refresh: true})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -330,7 +330,7 @@ func FsRemoveEmptyDirectory(c *gin.Context) {
if len(subFiles) == 0 { if len(subFiles) == 0 {
// remove empty directory // remove empty directory
err = fs.Remove(c, removingFilePath) err = fs.Remove(c.Request.Context(), removingFilePath)
removedFiles[removingFilePath] = true removedFiles[removingFilePath] = true
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
@ -384,7 +384,7 @@ func Link(c *gin.Context) {
}) })
return return
} }
link, _, err := fs.Link(c, rawPath, model.LinkArgs{IP: c.ClientIP(), Header: c.Request.Header, Redirect: true}) link, _, err := fs.Link(c.Request.Context(), rawPath, model.LinkArgs{IP: c.ClientIP(), Header: c.Request.Header, Redirect: true})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return

View File

@ -85,7 +85,7 @@ func FsList(c *gin.Context) {
common.ErrorStrResp(c, "Refresh without permission", 403) common.ErrorStrResp(c, "Refresh without permission", 403)
return return
} }
objs, err := fs.List(c, reqPath, &fs.ListArgs{Refresh: req.Refresh}) objs, err := fs.List(c.Request.Context(), reqPath, &fs.ListArgs{Refresh: req.Refresh})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -139,7 +139,7 @@ func FsDirs(c *gin.Context) {
common.ErrorStrResp(c, "password is incorrect or you have no permission", 403) common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
return return
} }
objs, err := fs.List(c, reqPath, &fs.ListArgs{}) objs, err := fs.List(c.Request.Context(), reqPath, &fs.ListArgs{})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -267,7 +267,7 @@ func FsGet(c *gin.Context) {
common.ErrorStrResp(c, "password is incorrect or you have no permission", 403) common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
return return
} }
obj, err := fs.Get(c, reqPath, &fs.GetArgs{}) obj, err := fs.Get(c.Request.Context(), reqPath, &fs.GetArgs{})
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return
@ -306,7 +306,7 @@ func FsGet(c *gin.Context) {
rawURL = url rawURL = url
} else { } else {
// if storage is not proxy, use raw url by fs.Link // if storage is not proxy, use raw url by fs.Link
link, _, err := fs.Link(c, reqPath, model.LinkArgs{ link, _, err := fs.Link(c.Request.Context(), reqPath, model.LinkArgs{
IP: c.ClientIP(), IP: c.ClientIP(),
Header: c.Request.Header, Header: c.Request.Header,
Redirect: true, Redirect: true,
@ -322,7 +322,7 @@ func FsGet(c *gin.Context) {
} }
var related []model.Obj var related []model.Obj
parentPath := stdpath.Dir(reqPath) parentPath := stdpath.Dir(reqPath)
sameLevelFiles, err := fs.List(c, parentPath, &fs.ListArgs{}) sameLevelFiles, err := fs.List(c.Request.Context(), parentPath, &fs.ListArgs{})
if err == nil { if err == nil {
related = filterRelated(sameLevelFiles, obj) related = filterRelated(sameLevelFiles, obj)
} }
@ -395,7 +395,7 @@ func FsOther(c *gin.Context) {
common.ErrorStrResp(c, "password is incorrect or you have no permission", 403) common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
return return
} }
res, err := fs.Other(c, req.FsOtherArgs) res, err := fs.Other(c.Request.Context(), req.FsOtherArgs)
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
return return

View File

@ -50,7 +50,7 @@ func FsStream(c *gin.Context) {
return return
} }
if !overwrite { if !overwrite {
if res, _ := fs.Get(c, path, &fs.GetArgs{NoLog: true}); res != nil { if res, _ := fs.Get(c.Request.Context(), path, &fs.GetArgs{NoLog: true}); res != nil {
common.ErrorStrResp(c, "file exists", 403) common.ErrorStrResp(c, "file exists", 403)
return return
} }
@ -92,9 +92,9 @@ func FsStream(c *gin.Context) {
} }
var t task.TaskExtensionInfo var t task.TaskExtensionInfo
if asTask { if asTask {
t, err = fs.PutAsTask(c, dir, s) t, err = fs.PutAsTask(c.Request.Context(), dir, s)
} else { } else {
err = fs.PutDirectly(c, dir, s, true) err = fs.PutDirectly(c.Request.Context(), dir, s, true)
} }
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)
@ -131,7 +131,7 @@ func FsForm(c *gin.Context) {
return return
} }
if !overwrite { if !overwrite {
if res, _ := fs.Get(c, path, &fs.GetArgs{NoLog: true}); res != nil { if res, _ := fs.Get(c.Request.Context(), path, &fs.GetArgs{NoLog: true}); res != nil {
common.ErrorStrResp(c, "file exists", 403) common.ErrorStrResp(c, "file exists", 403)
return return
} }
@ -187,9 +187,9 @@ func FsForm(c *gin.Context) {
s.Reader = struct { s.Reader = struct {
io.Reader io.Reader
}{f} }{f}
t, err = fs.PutAsTask(c, dir, s) t, err = fs.PutAsTask(c.Request.Context(), dir, s)
} else { } else {
err = fs.PutDirectly(c, dir, s, true) err = fs.PutDirectly(c.Request.Context(), dir, s, true)
} }
if err != nil { if err != nil {
common.ErrorResp(c, err, 500) common.ErrorResp(c, err, 500)

View File

@ -17,7 +17,7 @@ type SSHKeyAddReq struct {
} }
func AddMyPublicKey(c *gin.Context) { func AddMyPublicKey(c *gin.Context) {
userObj, ok := c.Value(conf.UserKey).(*model.User) userObj, ok := c.Request.Context().Value(conf.UserKey).(*model.User)
if !ok || userObj.IsGuest() { if !ok || userObj.IsGuest() {
common.ErrorStrResp(c, "user invalid", 401) common.ErrorStrResp(c, "user invalid", 401)
return return
@ -48,7 +48,7 @@ func AddMyPublicKey(c *gin.Context) {
} }
func ListMyPublicKey(c *gin.Context) { func ListMyPublicKey(c *gin.Context) {
userObj, ok := c.Value(conf.UserKey).(*model.User) userObj, ok := c.Request.Context().Value(conf.UserKey).(*model.User)
if !ok || userObj.IsGuest() { if !ok || userObj.IsGuest() {
common.ErrorStrResp(c, "user invalid", 401) common.ErrorStrResp(c, "user invalid", 401)
return return
@ -57,7 +57,7 @@ func ListMyPublicKey(c *gin.Context) {
} }
func DeleteMyPublicKey(c *gin.Context) { func DeleteMyPublicKey(c *gin.Context) {
userObj, ok := c.Value(conf.UserKey).(*model.User) userObj, ok := c.Request.Context().Value(conf.UserKey).(*model.User)
if !ok || userObj.IsGuest() { if !ok || userObj.IsGuest() {
common.ErrorStrResp(c, "user invalid", 401) common.ErrorStrResp(c, "user invalid", 401)
return return

View File

@ -38,7 +38,7 @@ func CreateStorage(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return return
} }
if id, err := op.CreateStorage(c, req); err != nil { if id, err := op.CreateStorage(c.Request.Context(), req); err != nil {
common.ErrorWithDataResp(c, err, 500, gin.H{ common.ErrorWithDataResp(c, err, 500, gin.H{
"id": id, "id": id,
}, true) }, true)
@ -55,7 +55,7 @@ func UpdateStorage(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return return
} }
if err := op.UpdateStorage(c, req); err != nil { if err := op.UpdateStorage(c.Request.Context(), req); err != nil {
common.ErrorResp(c, err, 500, true) common.ErrorResp(c, err, 500, true)
} else { } else {
common.SuccessResp(c) common.SuccessResp(c)
@ -69,7 +69,7 @@ func DeleteStorage(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return return
} }
if err := op.DeleteStorageById(c, uint(id)); err != nil { if err := op.DeleteStorageById(c.Request.Context(), uint(id)); err != nil {
common.ErrorResp(c, err, 500, true) common.ErrorResp(c, err, 500, true)
return return
} }
@ -83,7 +83,7 @@ func DisableStorage(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return return
} }
if err := op.DisableStorage(c, uint(id)); err != nil { if err := op.DisableStorage(c.Request.Context(), uint(id)); err != nil {
common.ErrorResp(c, err, 500, true) common.ErrorResp(c, err, 500, true)
return return
} }
@ -97,7 +97,7 @@ func EnableStorage(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return return
} }
if err := op.EnableStorage(c, uint(id)); err != nil { if err := op.EnableStorage(c.Request.Context(), uint(id)); err != nil {
common.ErrorResp(c, err, 500, true) common.ErrorResp(c, err, 500, true)
return return
} }

View File

@ -70,7 +70,7 @@ func argsContains[T comparable](v T, slice ...T) bool {
} }
func getUserInfo(c *gin.Context) (bool, uint, bool) { func getUserInfo(c *gin.Context) (bool, uint, bool) {
if user, ok := c.Value(conf.UserKey).(*model.User); ok { if user, ok := c.Request.Context().Value(conf.UserKey).(*model.User); ok {
return user.IsAdmin(), user.ID, true return user.IsAdmin(), user.ID, true
} else { } else {
return false, 0, false return false, 0, false