Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Fix embedding assets in exported PDFs with local HTTPS https://github.com/siyuan-note/siyuan/issues/17822

Daniela33a1d8c9527
diff --git a/kernel/model/export.go b/kernel/model/export.go
index 25c49eb977..7d45faaa8d 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -1793,10 +1793,13 @@ func processPDFLinkEmbedAssets(pdfCtx *model.Context, assetDests []string, boxID
attachmentMap := map[int][]*types.IndirectRef{}
now := types.StringLiteral(types.DateString(time.Now()))
for _, link := range assetLinks {
- link.URI = strings.ReplaceAll(link.URI, "http://"+util.LocalHost+":"+util.ServerPort+"/export/temp/", "")
- link.URI = strings.ReplaceAll(link.URI, "http://"+util.LocalHost+":6806/export/temp/", "")
- link.URI = strings.ReplaceAll(link.URI, "http://"+util.LocalHost+":"+util.ServerPort+"/", "") // Exporting PDF embedded asset files as attachments fails https://github.com/siyuan-note/siyuan/issues/7414#issuecomment-1704573557
- link.URI = strings.ReplaceAll(link.URI, "http://"+util.LocalHost+":6806/", "")
+ for _, scheme := range []string{"http", "https"} {
+ link.URI = strings.ReplaceAll(link.URI, scheme+"://"+util.LocalHost+":"+util.ServerPort+"/export/temp/", "")
+ link.URI = strings.ReplaceAll(link.URI, scheme+"://"+util.LocalHost+":6806/export/temp/", "")
+ // 将本地资源 URL 转换为导出目录中的相对路径。
+ link.URI = strings.ReplaceAll(link.URI, scheme+"://"+util.LocalHost+":"+util.ServerPort+"/", "")
+ link.URI = strings.ReplaceAll(link.URI, scheme+"://"+util.LocalHost+":6806/", "")
+ }
link.URI, _ = url.PathUnescape(link.URI)
sourceURI := link.URI
if idx := strings.Index(link.URI, "?"); 0 < idx {
diff --git a/kernel/model/pdf.go b/kernel/model/pdf.go
index c782f199ec..9b0026123b 100644
--- a/kernel/model/pdf.go
+++ b/kernel/model/pdf.go
@@ -30,7 +30,8 @@ func PdfListLinks(ctx *model.Context) (assets, others []model.LinkAnnotation, er
link := va.ContentString()
l := va.(model.LinkAnnotation)
l.Page = pg
- if strings.HasPrefix(link, "http://127.0.0.1:") && strings.Contains(link, "/assets/") {
+ if (strings.HasPrefix(link, "http://127.0.0.1:") ||
+ strings.HasPrefix(link, "https://127.0.0.1:")) && strings.Contains(link, "/assets/") {
assets = append(assets, l)
} else {
others = append(others, l)