Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/handles/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func ArchiveProxy(c *gin.Context) {
}
proxy(c, link, file, storage.GetStorage().ProxyRange)
} else {
common.ErrorStrResp(c, "proxy not allowed", 403)
common.ErrorPage(c, errors.New("proxy not allowed"), 403)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/handles/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func Proxy(c *gin.Context) {
}
proxy(c, link, file, storage.GetStorage().ProxyRange)
} else {
common.ErrorStrResp(c, "proxy not allowed", 403)
common.ErrorPage(c, errors.New("proxy not allowed"), 403)
return
}
}
Expand Down
41 changes: 29 additions & 12 deletions server/handles/sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ func SharingDown(c *gin.Context) {
err = errors.New("cannot get sharing root link")
}
}
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
unwrapPath, err := op.GetSharingUnwrapPath(s, path)
if err != nil {
common.ErrorStrResp(c, "failed get sharing unwrap path", 500)
common.ErrorPage(c, errors.New("failed get sharing unwrap path"), 500)
return
}
storage, actualPath, err := op.GetStorageAndActualPath(unwrapPath)
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
if setting.GetBool(conf.ShareForceProxy) || common.ShouldProxy(storage, stdpath.Base(actualPath)) {
Expand All @@ -224,7 +224,7 @@ func SharingDown(c *gin.Context) {
Type: c.Query("type"),
})
if err != nil {
common.ErrorResp(c, errors.WithMessage(err, "failed get sharing link"), 500)
common.ErrorPage(c, errors.WithMessage(err, "failed get sharing link"), 500)
return
}
_ = countAccess(c.ClientIP(), s)
Expand All @@ -237,7 +237,7 @@ func SharingDown(c *gin.Context) {
Redirect: true,
})
if err != nil {
common.ErrorResp(c, errors.WithMessage(err, "failed get sharing link"), 500)
common.ErrorPage(c, errors.WithMessage(err, "failed get sharing link"), 500)
return
}
_ = countAccess(c.ClientIP(), s)
Expand All @@ -247,7 +247,7 @@ func SharingDown(c *gin.Context) {

func SharingArchiveExtract(c *gin.Context) {
if !setting.GetBool(conf.ShareArchivePreview) {
common.ErrorStrResp(c, "sharing archives previewing is not allowed", 403)
common.ErrorPage(c, errors.New("sharing archives previewing is not allowed"), 403)
return
}
sid := c.Request.Context().Value(conf.SharingIDKey).(string)
Expand All @@ -265,16 +265,16 @@ func SharingArchiveExtract(c *gin.Context) {
err = errors.New("cannot extract sharing root")
}
}
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
unwrapPath, err := op.GetSharingUnwrapPath(s, path)
if err != nil {
common.ErrorStrResp(c, "failed get sharing unwrap path", 500)
common.ErrorPage(c, errors.New("failed get sharing unwrap path"), 500)
return
}
storage, actualPath, err := op.GetStorageAndActualPath(unwrapPath)
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
args := model.ArchiveInnerArgs{
Expand All @@ -290,21 +290,21 @@ func SharingArchiveExtract(c *gin.Context) {
if _, ok := storage.(driver.ArchiveReader); ok {
if setting.GetBool(conf.ShareForceProxy) || common.ShouldProxy(storage, stdpath.Base(actualPath)) {
link, obj, err := op.DriverExtract(c.Request.Context(), storage, actualPath, args)
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
proxy(c, link, obj, storage.GetStorage().ProxyRange)
} else {
args.Redirect = true
link, _, err := op.DriverExtract(c.Request.Context(), storage, actualPath, args)
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
redirect(c, link)
}
} else {
rc, size, err := op.InternalExtract(c.Request.Context(), storage, actualPath, args)
if dealError(c, err) {
if dealErrorPage(c, err) {
return
}
fileName := stdpath.Base(innerPath)
Expand All @@ -329,6 +329,23 @@ func dealError(c *gin.Context, err error) bool {
return true
}

func dealErrorPage(c *gin.Context, err error) bool {
if err == nil {
return false
} else if errors.Is(err, errs.SharingNotFound) {
common.ErrorPage(c, errors.New("the share does not exist"), 500)
} else if errors.Is(err, errs.InvalidSharing) {
common.ErrorPage(c, errors.New("the share has expired or is no longer valid"), 500)
} else if errors.Is(err, errs.WrongShareCode) {
common.ErrorPage(c, err, 403)
} else if errors.Is(err, errs.WrongArchivePassword) {
common.ErrorPage(c, err, 202)
} else {
common.ErrorPage(c, err, 500)
}
return true
}

type SharingResp struct {
*model.Sharing
CreatorName string `json:"creator"`
Expand Down