Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
66584d8a8a
2 changed files with 76 additions and 26 deletions
|
@ -806,38 +806,47 @@ func updateAttributeViewColRelation(operation *Operation) (err error) {
|
|||
}
|
||||
|
||||
for _, keyValues := range srcAv.KeyValues {
|
||||
if keyValues.Key.ID == operation.KeyID {
|
||||
// 已经设置过双向关联的话需要先断开双向关联
|
||||
if nil != keyValues.Key.Relation && keyValues.Key.Relation.IsTwoWay {
|
||||
oldDestAv, parseErr := av.ParseAttributeView(keyValues.Key.Relation.AvID)
|
||||
if nil == parseErr {
|
||||
isOldSameAv := oldDestAv.ID == destAv.ID
|
||||
if isOldSameAv {
|
||||
oldDestAv = destAv
|
||||
}
|
||||
if keyValues.Key.ID != operation.KeyID {
|
||||
continue
|
||||
}
|
||||
|
||||
oldDestKey, _ := oldDestAv.GetKey(keyValues.Key.Relation.BackKeyID)
|
||||
if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay {
|
||||
oldDestKey.Relation.IsTwoWay = false
|
||||
oldDestKey.Relation.BackKeyID = ""
|
||||
}
|
||||
srcRel := keyValues.Key.Relation
|
||||
// 已经设置过双向关联的话需要先断开双向关联
|
||||
if nil != srcRel && srcRel.IsTwoWay {
|
||||
oldDestAv, _ := av.ParseAttributeView(srcRel.AvID)
|
||||
if nil != oldDestAv {
|
||||
isOldSameAv := oldDestAv.ID == destAv.ID
|
||||
if isOldSameAv {
|
||||
oldDestAv = destAv
|
||||
}
|
||||
|
||||
if !isOldSameAv {
|
||||
err = av.SaveAttributeView(oldDestAv)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
oldDestKey, _ := oldDestAv.GetKey(srcRel.BackKeyID)
|
||||
if nil != oldDestKey && nil != oldDestKey.Relation && oldDestKey.Relation.AvID == srcAv.ID && oldDestKey.Relation.IsTwoWay {
|
||||
oldDestKey.Relation.IsTwoWay = false
|
||||
oldDestKey.Relation.BackKeyID = ""
|
||||
}
|
||||
|
||||
if !isOldSameAv {
|
||||
err = av.SaveAttributeView(oldDestAv)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
keyValues.Key.Relation = &av.Relation{
|
||||
AvID: operation.ID,
|
||||
IsTwoWay: operation.IsTwoWay,
|
||||
BackKeyID: operation.BackRelationKeyID,
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
srcRel = &av.Relation{
|
||||
AvID: operation.ID,
|
||||
IsTwoWay: operation.IsTwoWay,
|
||||
}
|
||||
|
||||
if operation.IsTwoWay {
|
||||
srcRel.BackKeyID = operation.BackRelationKeyID
|
||||
} else {
|
||||
srcRel.BackKeyID = ""
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
destAdded := false
|
||||
|
|
|
@ -818,6 +818,7 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
|
|||
|
||||
processPDFBookmarks(pdfCtx, headings)
|
||||
processPDFLinkEmbedAssets(pdfCtx, assetDests, removeAssets)
|
||||
// processPDFWatermark(pdfCtx, "text", "Test", "")
|
||||
|
||||
pdfcpu.VersionStr = "SiYuan v" + util.Ver
|
||||
if writeErr := api.WriteContextFile(pdfCtx, p); nil != writeErr {
|
||||
|
@ -827,6 +828,46 @@ func ProcessPDF(id, p string, merge, removeAssets bool) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func processPDFWatermark(pdfCtx *pdfcpu.Context, mode, watermark, desc string) {
|
||||
// Support adding the watermark on export PDF https://github.com/siyuan-note/siyuan/issues/9961
|
||||
// https://pdfcpu.io/core/watermark
|
||||
|
||||
if !IsPaidUser() {
|
||||
return
|
||||
}
|
||||
|
||||
if "" == watermark {
|
||||
return
|
||||
}
|
||||
|
||||
if "text" != mode && "image" != mode && "pdf" != mode {
|
||||
logging.LogErrorf("invalid watermark type: %s", mode)
|
||||
return
|
||||
}
|
||||
|
||||
var wm *pdfcpu.Watermark
|
||||
var err error
|
||||
switch mode {
|
||||
case "text":
|
||||
wm, err = pdfcpu.ParseTextWatermarkDetails(watermark, desc, false, pdfcpu.POINTS)
|
||||
case "image":
|
||||
wm, err = pdfcpu.ParseImageWatermarkDetails(watermark, desc, false, pdfcpu.POINTS)
|
||||
case "pdf":
|
||||
wm, err = pdfcpu.ParsePDFWatermarkDetails(watermark, desc, false, pdfcpu.POINTS)
|
||||
}
|
||||
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse watermark failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = pdfCtx.AddWatermarks(nil, wm)
|
||||
if nil != err {
|
||||
logging.LogErrorf("add watermark failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func processPDFBookmarks(pdfCtx *pdfcpu.Context, headings []*ast.Node) {
|
||||
links, err := api.ListToCLinks(pdfCtx)
|
||||
if nil != err {
|
||||
|
|
Loading…
Add table
Reference in a new issue