This commit is contained in:
Liang Ding 2023-01-02 21:28:50 +08:00
parent 8fc5ea2bdf
commit 448fed5532
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 101 additions and 6 deletions

View file

@ -1043,6 +1043,7 @@
"177": "Exit application",
"178": "Access Authorization - SiYuan",
"179": "The disk space may be insufficient. It is recommended to keep the free space of the disk where the workspace is located at more than twice the size of data",
"180": "Search content block does not exist"
"180": "Search content block does not exist",
"181": "The document has been shared to Liandi, <a href=\"%s\" target=\"_blank\">click to view</a>"
}
}

View file

@ -1043,6 +1043,7 @@
"177": "Salir de la aplicación",
"178": "Autorización de acceso - SiYuan",
"179": "El espacio en disco puede ser insuficiente. Se recomienda mantener el espacio libre del disco donde se encuentra el espacio de trabajo en más del doble del tamaño de los datos",
"180": "El bloque de contenido de búsqueda no existe"
"180": "El bloque de contenido de búsqueda no existe",
"181": "El documento ha sido compartido con Liandi, <a href=\"%s\" target=\"_blank\">haga clic para ver</a>"
}
}

View file

@ -1043,6 +1043,7 @@
"177": "Quitter l'application",
"178": "Autorisation d'accès - SiYuan",
"179": "L'espace disque peut être insuffisant. Il est recommandé de conserver l'espace libre du disque où se trouve l'espace de travail à plus de deux fois la taille des données",
"180": "Le bloc de contenu de recherche n'existe pas"
"180": "Le bloc de contenu de recherche n'existe pas",
"181": "Le document a été partagé avec Liandi, <a href=\"%s\" target=\"_blank\">cliquez pour afficher</a>"
}
}

View file

@ -1043,6 +1043,7 @@
"177": "退出應用",
"178": "訪問授權 - 思源筆記",
"179": "磁碟空間可能不足,建議保持工作空間所在磁碟可用空間為 data 大小的 2 倍以上",
"180": "不存在符合條件的內容塊"
"180": "不存在符合條件的內容塊",
"181": "已分享文檔到鏈滴,<a href=\"%s\" target=\"_blank\">點擊查看</a>"
}
}

View file

@ -1043,6 +1043,7 @@
"177": "退出应用",
"178": "访问授权 - 思源笔记",
"179": "磁盘空间可能不足,建议保持工作空间所在磁盘可用空间为 data 大小的 2 倍以上",
"180": "不存在符合条件的内容块"
"180": "不存在符合条件的内容块",
"181": "已分享文档到链滴,<a href=\"%s\" target=\"_blank\">点击查看</a>"
}
}

View file

@ -20,6 +20,9 @@ import (
"bytes"
"errors"
"fmt"
"github.com/imroc/req/v3"
"github.com/siyuan-note/httpclient"
"net/http"
"net/url"
"os"
"os/exec"
@ -48,6 +51,87 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func Export2Liandi(id string) (err error) {
tree, err := loadTreeByBlockID(id)
if nil != err {
logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
return
}
// 判断帖子是否已经存在,存在则使用更新接口
foundArticle := false
articleId := tree.Root.IALAttr("liandiArticleId")
if "" != articleId {
var result = map[string]interface{}{}
request := httpclient.NewCloudRequest30s()
resp, getErr := request.
SetResult(result).
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
Get(util.LiandiServer + "/api/v2/article/update/" + articleId)
if nil != getErr {
logging.LogErrorf("get liandi article info failed: %s", getErr)
return getErr
}
switch resp.StatusCode {
case 200:
foundArticle = true
case 404:
foundArticle = false
default:
msg := fmt.Sprintf("get liandi article info failed [sc=%d]", resp.StatusCode)
err = errors.New(msg)
return
}
}
apiURL := util.LiandiServer + "/api/v2/article"
if foundArticle {
apiURL += "/" + articleId
}
title := path.Base(tree.HPath)
tags := tree.Root.IALAttr("tags")
content := exportMarkdownContent0(tree)
var result = map[string]interface{}{}
request := httpclient.NewCloudRequest30s()
request = request.
SetResult(result).
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
SetBody(map[string]interface{}{
"title": title,
"tags": tags,
"content": content})
var resp *req.Response
var sendErr error
if foundArticle {
resp, sendErr = request.Put(apiURL)
} else {
resp, sendErr = request.Post(apiURL)
}
if nil != sendErr {
logging.LogErrorf("send article to liandi failed: %s", err)
return err
}
if 200 != resp.StatusCode {
msg := fmt.Sprintf("send article to liandi failed [sc=%d]", resp.StatusCode)
logging.LogErrorf(msg)
return errors.New(msg)
}
if !foundArticle {
articleId = result["data"].(string)
tree.Root.SetIALAttr("liandiArticleId", articleId)
if err = writeJSONQueue(tree); nil != err {
return
}
}
msg := fmt.Sprintf(Conf.Language(181), util.LiandiServer+"/article/"+articleId)
util.PushMsg(msg, 7000)
return
}
func ExportSystemLog() (zipPath string) {
exportFolder := filepath.Join(util.TempDir, "export", "system-log")
os.RemoveAll(exportFolder)
@ -1043,12 +1127,17 @@ func ExportMarkdownContent(id string) (hPath, exportedMd string) {
func exportMarkdownContent(id string) (hPath, exportedMd string) {
tree, _ := loadTreeByBlockID(id)
hPath = tree.HPath
exportedMd = exportMarkdownContent0(tree)
return
}
func exportMarkdownContent0(tree *parse.Tree) (ret string) {
tree = exportTree(tree, false, true, false)
luteEngine := NewLute()
luteEngine.SetFootnotes(true)
luteEngine.SetKramdownIAL(false)
renderer := render.NewProtyleExportMdRenderer(tree, luteEngine.RenderOptions)
exportedMd = gulu.Str.FromBytes(renderer.Render())
ret = gulu.Str.FromBytes(renderer.Render())
return
}

View file

@ -40,6 +40,7 @@ const (
SiYuanSyncServer = "https://siyuan-data.b3logfile.com/" // 云端数据同步服务地址,七牛云 OSS用于数据同步文件上传、下载
BazaarStatServer = "http://bazaar.b3logfile.com" // 集市包统计服务地址,直接对接 Bucket 没有 CDN 缓存
BazaarOSSServer = "https://oss.b3logfile.com" // 云端对象存储地址,七牛云,仅用于读取集市包
LiandiServer = "https://ld246.com" // 链滴服务地址,用于分享发布帖子
)
func ShortPathForBootingDisplay(p string) string {