mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 12:16:24 +08:00
chore: standardize context keys with custom ContextKey type (#697)
* chore: standardize context keys with custom ContextKey type * fix bug * 使用Request.Context
This commit is contained in:
@ -77,7 +77,7 @@ func FsArchiveMeta(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
user := c.MustGet("user").(*model.User)
|
||||
user := c.Request.Context().Value(conf.UserKey).(*model.User)
|
||||
if !user.CanReadArchives() {
|
||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||
return
|
||||
@ -94,7 +94,7 @@ func FsArchiveMeta(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
c.Set("meta", meta)
|
||||
common.GinWithValue(c, conf.MetaKey, meta)
|
||||
if !common.CanAccess(user, meta, reqPath, req.Password) {
|
||||
common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
|
||||
return
|
||||
@ -106,7 +106,7 @@ func FsArchiveMeta(c *gin.Context) {
|
||||
},
|
||||
Password: req.ArchivePass,
|
||||
}
|
||||
ret, err := fs.ArchiveMeta(c, reqPath, model.ArchiveMetaArgs{
|
||||
ret, err := fs.ArchiveMeta(c.Request.Context(), reqPath, model.ArchiveMetaArgs{
|
||||
ArchiveArgs: archiveArgs,
|
||||
Refresh: req.Refresh,
|
||||
})
|
||||
@ -154,7 +154,7 @@ func FsArchiveList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
req.Validate()
|
||||
user := c.MustGet("user").(*model.User)
|
||||
user := c.Request.Context().Value(conf.UserKey).(*model.User)
|
||||
if !user.CanReadArchives() {
|
||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||
return
|
||||
@ -171,12 +171,12 @@ func FsArchiveList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
c.Set("meta", meta)
|
||||
common.GinWithValue(c, conf.MetaKey, meta)
|
||||
if !common.CanAccess(user, meta, reqPath, req.Password) {
|
||||
common.ErrorStrResp(c, "password is incorrect or you have no permission", 403)
|
||||
return
|
||||
}
|
||||
objs, err := fs.ArchiveList(c, reqPath, model.ArchiveListArgs{
|
||||
objs, err := fs.ArchiveList(c.Request.Context(), reqPath, model.ArchiveListArgs{
|
||||
ArchiveInnerArgs: model.ArchiveInnerArgs{
|
||||
ArchiveArgs: model.ArchiveArgs{
|
||||
LinkArgs: model.LinkArgs{
|
||||
@ -239,7 +239,7 @@ func FsArchiveDecompress(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
user := c.MustGet("user").(*model.User)
|
||||
user := c.Request.Context().Value(conf.UserKey).(*model.User)
|
||||
if !user.CanDecompress() {
|
||||
common.ErrorResp(c, errs.PermissionDenied, 403)
|
||||
return
|
||||
@ -260,7 +260,7 @@ func FsArchiveDecompress(c *gin.Context) {
|
||||
}
|
||||
tasks := make([]task.TaskExtensionInfo, 0, len(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{
|
||||
ArchiveArgs: model.ArchiveArgs{
|
||||
LinkArgs: model.LinkArgs{
|
||||
@ -292,7 +292,7 @@ func FsArchiveDecompress(c *gin.Context) {
|
||||
}
|
||||
|
||||
func ArchiveDown(c *gin.Context) {
|
||||
archiveRawPath := c.MustGet("path").(string)
|
||||
archiveRawPath := c.Request.Context().Value(conf.PathKey).(string)
|
||||
innerPath := utils.FixAndCleanPath(c.Query("inner"))
|
||||
password := c.Query("pass")
|
||||
filename := stdpath.Base(innerPath)
|
||||
@ -305,7 +305,7 @@ func ArchiveDown(c *gin.Context) {
|
||||
ArchiveProxy(c)
|
||||
return
|
||||
} else {
|
||||
link, _, err := fs.ArchiveDriverExtract(c, archiveRawPath, model.ArchiveInnerArgs{
|
||||
link, _, err := fs.ArchiveDriverExtract(c.Request.Context(), archiveRawPath, model.ArchiveInnerArgs{
|
||||
ArchiveArgs: model.ArchiveArgs{
|
||||
LinkArgs: model.LinkArgs{
|
||||
IP: c.ClientIP(),
|
||||
@ -326,7 +326,7 @@ func ArchiveDown(c *gin.Context) {
|
||||
}
|
||||
|
||||
func ArchiveProxy(c *gin.Context) {
|
||||
archiveRawPath := c.MustGet("path").(string)
|
||||
archiveRawPath := c.Request.Context().Value(conf.PathKey).(string)
|
||||
innerPath := utils.FixAndCleanPath(c.Query("inner"))
|
||||
password := c.Query("pass")
|
||||
filename := stdpath.Base(innerPath)
|
||||
@ -337,7 +337,7 @@ func ArchiveProxy(c *gin.Context) {
|
||||
}
|
||||
if canProxy(storage, filename) {
|
||||
// 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{
|
||||
LinkArgs: model.LinkArgs{
|
||||
Header: c.Request.Header,
|
||||
@ -359,10 +359,10 @@ func ArchiveProxy(c *gin.Context) {
|
||||
}
|
||||
|
||||
func ArchiveInternalExtract(c *gin.Context) {
|
||||
archiveRawPath := c.MustGet("path").(string)
|
||||
archiveRawPath := c.Request.Context().Value(conf.PathKey).(string)
|
||||
innerPath := utils.FixAndCleanPath(c.Query("inner"))
|
||||
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{
|
||||
LinkArgs: model.LinkArgs{
|
||||
Header: c.Request.Header,
|
||||
|
Reference in New Issue
Block a user