From cd6eee0b60084ef00009f8e316f102767cf95ddb Mon Sep 17 00:00:00 2001 From: Darren Yu <62318640+YUDONGLING@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:34:49 -0500 Subject: [PATCH] Fix: doc preview src of local storage policy starts with ":/" (#1842) (#1844) * Fix: doc preview src of local storage policy starts with ":/" * Fix: doc preview src of local storage policy starts with ":/" --- service/explorer/file.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/service/explorer/file.go b/service/explorer/file.go index 177e46d..1c9d870 100644 --- a/service/explorer/file.go +++ b/service/explorer/file.go @@ -227,8 +227,14 @@ func (service *FileIDService) CreateDocPreviewSession(ctx context.Context, c *gi return serializer.Err(serializer.CodeNotSet, err.Error(), err) } + // For newer version of Cloudreve - Local Policy + // When do not use a cdn, the downloadURL withouts hosts, like "/api/v3/file/download/xxx" if strings.HasPrefix(downloadURL, "/") { - downloadURL = path.Join(model.GetSiteURL().String(), downloadURL) + downloadURI, err := url.Parse(downloadURL) + if err != nil { + return serializer.Err(serializer.CodeNotSet, err.Error(), err) + } + downloadURL = model.GetSiteURL().ResolveReference(downloadURI).String() } var resp serializer.DocPreviewSession