This commit is contained in:
Liang Ding 2023-01-04 11:26:26 +08:00
parent e4b9feb4f6
commit e109869239
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 12 additions and 6 deletions

View file

@ -281,11 +281,16 @@ func UploadAssets2Cloud(rootID string) (err error) {
}
sqlAssets := sql.QueryRootBlockAssets(rootID)
err = uploadCloud(sqlAssets)
err = uploadAssets2Cloud(sqlAssets, "5")
return
}
func uploadCloud(sqlAssets []*sql.Asset) (err error) {
// uploadAssets2Cloud 将资源文件上传到云端图床。
// metaType 为服务端 Filemeta.FILEMETA_TYPE这里只有两个值
//
// 5: SiYuan表示为 SiYuan 上传图床
// 4: Client表示作为客户端分享发布帖子时上传的文件
func uploadAssets2Cloud(sqlAssets []*sql.Asset, metaType string) (err error) {
syncedAssets := readWorkspaceAssets()
var unSyncAssets []string
for _, sqlAsset := range sqlAssets {
@ -355,6 +360,7 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
SetResult(requestResult).
SetFile("file[]", absAsset).
SetCookies(&http.Cookie{Name: "symphony", Value: uploadToken}).
SetHeader("meta-type", metaType).
Post(util.AliyunServer + "/apis/siyuan/upload?ver=" + util.Ver)
if nil != reqErr {
logging.LogErrorf("upload assets failed: %s", reqErr)

View file

@ -59,7 +59,7 @@ func Export2Liandi(id string) (err error) {
}
sqlAssets := sql.QueryRootBlockAssets(id)
err = uploadCloud(sqlAssets)
err = uploadAssets2Cloud(sqlAssets, "4")
if nil != err {
return
}
@ -100,7 +100,7 @@ func Export2Liandi(id string) (err error) {
title := path.Base(tree.HPath)
tags := tree.Root.IALAttr("tags")
content := exportMarkdownContent0(tree, "https://b3logfile.com/siyuan/", true,
content := exportMarkdownContent0(tree, "https://b3logfile.com/file/"+time.Now().Format("2006/01")+"/siyuan/"+Conf.User.UserId+"/", true,
4, 1, 0,
"#", "#",
"", "",
@ -728,7 +728,7 @@ func ExportStdMarkdown(id string) string {
cloudAssetsBase := ""
if IsSubscriber() {
cloudAssetsBase = "https://assets.b3logfile.com/siyuan/"
cloudAssetsBase = "https://assets.b3logfile.com/siyuan/" + Conf.User.UserId + "/"
}
return exportMarkdownContent0(tree, cloudAssetsBase, false,
Conf.Export.BlockRefMode, Conf.Export.BlockEmbedMode, Conf.Export.FileAnnotationRefMode,
@ -1190,7 +1190,7 @@ func exportMarkdownContent0(tree *parse.Tree, cloudAssetsBase string, assetsDest
luteEngine.SetFootnotes(true)
luteEngine.SetKramdownIAL(false)
if "" != cloudAssetsBase {
luteEngine.RenderOptions.LinkBase = cloudAssetsBase + Conf.User.UserId + "/"
luteEngine.RenderOptions.LinkBase = cloudAssetsBase
}
if assetsDestSpace2Underscore { // 上传到社区图床的资源文件会将空格转为下划线,所以这里也需要将文档内容做相应的转换
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {