Parcourir la source

Merge remote-tracking branch 'origin/dev' into dev

Vanessa il y a 2 ans
Parent
commit
3fced58e30

+ 5 - 5
app/guide/20210808180117-czj9bvb/20200813093015-u6bopdt.sy

@@ -7,7 +7,7 @@
 		"id": "20200813093015-u6bopdt",
 		"title": "常见问题",
 		"type": "doc",
-		"updated": "20230103223722"
+		"updated": "20230104134309"
 	},
 	"Children": [
 		{
@@ -372,7 +372,7 @@
 			"ListData": {},
 			"Properties": {
 				"id": "20210428213927-rbcfx2y",
-				"updated": "20230103223722"
+				"updated": "20230104134309"
 			},
 			"Children": [
 				{
@@ -501,7 +501,7 @@
 					},
 					"Properties": {
 						"id": "20221202214653-s19pmcp",
-						"updated": "20230103223722"
+						"updated": "20230104134309"
 					},
 					"Children": [
 						{
@@ -509,7 +509,7 @@
 							"Type": "NodeParagraph",
 							"Properties": {
 								"id": "20221202214653-trmmieq",
-								"updated": "20230103223722"
+								"updated": "20230104134309"
 							},
 							"Children": [
 								{
@@ -528,7 +528,7 @@
 								{
 									"Type": "NodeTextMark",
 									"TextMarkType": "block-ref",
-									"TextMarkBlockRefID": "20221223111348-4xpodkj",
+									"TextMarkBlockRefID": "20221223215557-o6gfsoy",
 									"TextMarkBlockRefSubtype": "s",
 									"TextMarkTextContent": "闪卡"
 								},

+ 22 - 2
kernel/model/assets.go

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

+ 4 - 4
kernel/model/export.go

@@ -59,7 +59,7 @@ func Export2Liandi(id string) (err error) {
 	}
 
 	sqlAssets := sql.QueryRootBlockAssets(id)
-	err = uploadCloud(sqlAssets)
+	err = uploadAssets2Cloud(sqlAssets, bizTypeExport2Liandi)
 	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 {

+ 5 - 0
kernel/model/storage.go

@@ -17,6 +17,7 @@
 package model
 
 import (
+	"errors"
 	"os"
 	"path/filepath"
 	"sync"
@@ -206,6 +207,10 @@ func RemoveCriterion(name string) (err error) {
 }
 
 func SetCriterion(criterion *Criterion) (err error) {
+	if "" == criterion.Name {
+		return errors.New(Conf.Language(142))
+	}
+
 	criteriaLock.Lock()
 	defer criteriaLock.Unlock()