mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-29 00:55:51 +08:00
fix (zip): handle offline edge case
This commit is contained in:
@ -783,19 +783,21 @@ func FileDownloader(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||
if strings.HasSuffix(backendPath, "/") == false {
|
||||
// Process File
|
||||
zipPath := strings.TrimPrefix(backendPath, zipRoot)
|
||||
file, err := ctx.Backend.Cat(backendPath)
|
||||
if err != nil {
|
||||
*errList = append(*errList, fmt.Sprintf("downloader::cat %s %s\n", zipPath, err.Error()))
|
||||
if err == ErrNotReachable {
|
||||
return nil
|
||||
}
|
||||
Log.Debug("downloader::cat backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error())
|
||||
return err
|
||||
}
|
||||
zipFile, err := zw.Create(zipPath)
|
||||
if err != nil {
|
||||
*errList = append(*errList, fmt.Sprintf("downloader::create %s %s\n", zipPath, err.Error()))
|
||||
Log.Debug("downloader::create backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error())
|
||||
return err
|
||||
}
|
||||
file, err := ctx.Backend.Cat(backendPath)
|
||||
if err != nil {
|
||||
*errList = append(*errList, fmt.Sprintf("downloader::cat %s %s\n", zipPath, err.Error()))
|
||||
Log.Debug("downloader::cat backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error())
|
||||
io.Copy(zipFile, strings.NewReader(""))
|
||||
return err
|
||||
}
|
||||
if _, err = io.Copy(zipFile, file); err != nil {
|
||||
*errList = append(*errList, fmt.Sprintf("downloader::copy %s %s\n", zipPath, err.Error()))
|
||||
Log.Debug("downloader::copy backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error())
|
||||
|
||||
@ -282,6 +282,8 @@ func (this S3Backend) Cat(path string) (io.ReadCloser, error) {
|
||||
return nil, NewError("This file is encrypted file, you need the correct key!", 400)
|
||||
} else if awsErr.Code() == "AccessDenied" {
|
||||
return nil, ErrNotAllowed
|
||||
} else if awsErr.Code() == "InvalidObjectState" {
|
||||
return nil, ErrNotReachable
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user