Skip to content
Open
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
27 changes: 22 additions & 5 deletions server/handles/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
stdpath "path"
"strconv"
"strings"

"github.com/OpenListTeam/OpenList/v4/internal/conf"
"github.com/OpenListTeam/OpenList/v4/internal/driver"
Expand Down Expand Up @@ -71,12 +72,18 @@ func Proxy(c *gin.Context) {
common.ErrorPage(c, err, 500)
return
}
proxy(c, link, file, storage.GetStorage().ProxyRange)
} else {
common.ErrorPage(c, errors.New("proxy not allowed"), 403)
return
// Disable browser caching for local storage downloads.
if isLocalDriver(storage) {
c.Header("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
c.Header("Pragma", "no-cache")
c.Header("Expires", "0")
}
proxy(c, link, file, storage.GetStorage().ProxyRange)
} else {
common.ErrorPage(c, errors.New("proxy not allowed"), 403)
return
}
}
}

func redirect(c *gin.Context, link *model.Link) {
defer link.Close()
Expand Down Expand Up @@ -175,3 +182,13 @@ func canProxy(storage driver.Driver, filename string) bool {
}
return false
}

func isLocalDriver(storage driver.Driver) bool {
if storage == nil || storage.GetStorage() == nil {
return false
}
if strings.EqualFold(storage.Config().Name, "Local") {
return true
}
return strings.EqualFold(storage.GetStorage().Driver, "Local")
}