mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-19 06:46:09 +01:00
🎨 Include related assets when exporting the database to CSV https://github.com/siyuan-note/siyuan/issues/16645
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
f2532998e4
commit
f9aa99bff8
1 changed files with 50 additions and 0 deletions
|
|
@ -164,6 +164,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var assets []string
|
||||
rowNum := 1
|
||||
for _, row := range table.Rows {
|
||||
var rowVal []string
|
||||
|
|
@ -204,12 +205,18 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
buf.WriteString("](")
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
if util.IsAssetLinkDest([]byte(a.Content), true) {
|
||||
assets = append(assets, a.Content)
|
||||
}
|
||||
} else if av.AssetTypeFile == a.Type {
|
||||
buf.WriteString("[")
|
||||
buf.WriteString(a.Name)
|
||||
buf.WriteString("](")
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
if util.IsAssetLinkDest([]byte(a.Content), true) {
|
||||
assets = append(assets, a.Content)
|
||||
}
|
||||
} else {
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(" ")
|
||||
|
|
@ -219,6 +226,37 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
}
|
||||
} else if av.KeyTypeLineNumber == cell.Value.Type {
|
||||
val = strconv.Itoa(rowNum)
|
||||
} else if av.KeyTypeRollup == cell.Value.Type {
|
||||
for _, content := range cell.Value.Rollup.Contents {
|
||||
if av.KeyTypeMAsset == content.Type {
|
||||
buf := &bytes.Buffer{}
|
||||
for _, a := range content.MAsset {
|
||||
if av.AssetTypeImage == a.Type {
|
||||
buf.WriteString("
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
if util.IsAssetLinkDest([]byte(a.Content), true) {
|
||||
assets = append(assets, a.Content)
|
||||
}
|
||||
} else if av.AssetTypeFile == a.Type {
|
||||
buf.WriteString("[")
|
||||
buf.WriteString(a.Name)
|
||||
buf.WriteString("](")
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
if util.IsAssetLinkDest([]byte(a.Content), true) {
|
||||
assets = append(assets, a.Content)
|
||||
}
|
||||
} else {
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
}
|
||||
val = strings.TrimSpace(buf.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if "" == val {
|
||||
|
|
@ -237,6 +275,18 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
}
|
||||
writer.Flush()
|
||||
|
||||
for _, asset := range assets {
|
||||
srcAbsPath, getErr := GetAssetAbsPath(asset)
|
||||
if getErr != nil {
|
||||
logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, getErr)
|
||||
continue
|
||||
}
|
||||
targetAbsPath := filepath.Join(exportFolder, asset)
|
||||
if copyErr := filelock.Copy(srcAbsPath, targetAbsPath); copyErr != nil {
|
||||
logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, copyErr)
|
||||
}
|
||||
}
|
||||
|
||||
zipPath = exportFolder + ".db.zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue