commit c10d229fa083bc96b7f14e27dbea6718d82e8c83
parent 754c75f03d23802bec2fc84a64aa0832e9f9d667
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 3 Feb 2023 17:20:57 -0800
handle errors
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4484,7 +4484,11 @@ func FileDropDkfDownloadHandler(c echo.Context) error {
}
maxChunkSize := int64(2 << 20) // 2MB
- f, _ := os.Open(filepath.Join(config.Global.ProjectFiledropPath(), filedrop.FileName))
+ f, err := os.Open(filepath.Join(config.Global.ProjectFiledropPath(), filedrop.FileName))
+ if err != nil {
+ logrus.Error(err)
+ return c.NoContent(http.StatusInternalServerError)
+ }
init := c.Request().PostFormValue("init")
if init != "" {
@@ -4516,11 +4520,13 @@ func FileDropDkfDownloadHandler(c echo.Context) error {
n, err := f.ReadAt(buf, chunkNum*maxChunkSize)
if err != nil {
logrus.Error(err)
+ return c.NoContent(http.StatusInternalServerError)
}
c.Response().Header().Set(echo.HeaderContentDisposition, fmt.Sprintf("attachment; filename=chunk_%d", chunkNum))
if _, err := io.Copy(c.Response().Writer, bytes.NewReader(buf[:n])); err != nil {
logrus.Error(err)
+ return c.NoContent(http.StatusInternalServerError)
}
c.Response().Flush()
return nil