Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
f382c66fa0
15 changed files with 184 additions and 9 deletions
44
API.md
44
API.md
|
@ -44,6 +44,8 @@
|
|||
* [List files](#List-files)
|
||||
* [Export](#Export)
|
||||
* [Export Markdown](#Export-Markdown)
|
||||
* [Conversion](#Conversion)
|
||||
* [Pandoc](#Pandoc)
|
||||
* [Notification](#Notification)
|
||||
* [Push message](#Push-message)
|
||||
* [Push error message](#Push-error-message)
|
||||
|
@ -710,9 +712,10 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
|||
}
|
||||
```
|
||||
|
||||
* `id`: Block ID to move
|
||||
* `previousID`: The ID of the previous block, used to anchor the insertion position
|
||||
* `parentID`: The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot be empty at the same time, if they exist at the same time, `previousID` will be used first
|
||||
* `id`: Block ID to move
|
||||
* `previousID`: The ID of the previous block, used to anchor the insertion position
|
||||
* `parentID`: The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot
|
||||
be empty at the same time, if they exist at the same time, `previousID` will be used first
|
||||
* Return value
|
||||
|
||||
```json
|
||||
|
@ -1014,6 +1017,41 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
|||
* `hPath`: human-readable path
|
||||
* `content`: Markdown content
|
||||
|
||||
## Conversion
|
||||
|
||||
### Pandoc
|
||||
|
||||
* `/api/convert/pandoc`
|
||||
* Working directory
|
||||
* Executing the pandoc command will set the working directory to `workspace/temp/convert/pandoc/`
|
||||
* API [`Put file`](#put-file) can be used to write the file to be converted to this directory first
|
||||
* Then call the API for conversion, and the converted file will also be written to this directory
|
||||
* Finally, call the API [`Get file`](#get-file) to get the converted file
|
||||
* Or call the API [Create a document with Markdown](#Create-a-document-with-Markdown)
|
||||
* Or call the internal API `importStdMd` to import the converted folder directly
|
||||
* Parameters
|
||||
|
||||
```json
|
||||
{
|
||||
"args": [
|
||||
"--to", "markdown_strict-raw_html",
|
||||
"foo.epub",
|
||||
"-o", "foo.md"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
* `args`: Pandoc command line parameters
|
||||
* Return value
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"msg": "",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
## Notification
|
||||
|
||||
### Push message
|
||||
|
|
37
API_zh_CN.md
37
API_zh_CN.md
|
@ -44,6 +44,8 @@
|
|||
* [列出文件](#列出文件)
|
||||
* [导出](#导出)
|
||||
* [导出 Markdown 文本](#导出-markdown-文本)
|
||||
* [转换](#转换)
|
||||
* [Pandoc](#Pandoc)
|
||||
* [通知](#通知)
|
||||
* [推送消息](#推送消息)
|
||||
* [推送报错消息](#推送报错消息)
|
||||
|
@ -1008,6 +1010,41 @@
|
|||
* `hPath`:人类可读的路径
|
||||
* `content`:Markdown 内容
|
||||
|
||||
## 转换
|
||||
|
||||
### Pandoc
|
||||
|
||||
* `/api/convert/pandoc`
|
||||
* 工作目录
|
||||
* 执行调用 pandoc 命令时工作目录会被设置在 `工作空间/temp/convert/pandoc/` 下
|
||||
* 可先通过 API [`写入文件`](#写入文件) 将待转换文件写入该目录
|
||||
* 然后再调用该 API 进行转换,转换后的文件也会被写入该目录
|
||||
* 最后调用 API [`获取文件`](#获取文件) 获取转换后的文件内容
|
||||
* 或者调用 API [`通过 Markdown 创建文档`](#通过-markdown-创建文档)
|
||||
* 或者调用内部 API `importStdMd` 将转换后的文件夹直接导入
|
||||
* 参数
|
||||
|
||||
```json
|
||||
{
|
||||
"args": [
|
||||
"--to", "markdown_strict-raw_html",
|
||||
"foo.epub",
|
||||
"-o", "foo.md"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
* `args`:Pandoc 命令行参数
|
||||
* 返回值
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"msg": "",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
## 通知
|
||||
|
||||
### 推送消息
|
||||
|
|
|
@ -574,7 +574,7 @@
|
|||
"kernelFault1": "Your data should be safe, please check whether the network connection and kernel process are normal, and then restart SiYuan",
|
||||
"kernelFault2": "If the problem persists, please look for help or report bugs <a href=\"https://github.com/siyuan-note/siyuan/issues\" target=\"_blank\">here</a>",
|
||||
"fontSize": "Font Size",
|
||||
"fontSizeTip": "The default font size is 16px, this setting affects the editor and exported PDF/HTML font size display",
|
||||
"fontSizeTip": "The default font size is <code class='fn__code'>16</code>, this setting affects the editor and exported PDF/HTML font size display",
|
||||
"font1": "This setting only affects the font family display in the editor, choose <code class='fn__code'>Default</code> to use the theme's font family",
|
||||
"newNameFile": "The name of the new subdocument is",
|
||||
"newNameSettingFile": "The name of the new document is",
|
||||
|
|
|
@ -574,7 +574,7 @@
|
|||
"kernelFault1": "Sus datos deben estar seguros, verifique si la conexión de red y el proceso del kernel son normales y luego reinicie SiYuan",
|
||||
"kernelFault2": "Si el problema persiste, busque ayuda o informe de errores <a href=\"https://github.com/siyuan-note/siyuan/issues\" target=\"_blank\">aquí</a>",
|
||||
"fontSize": "Tamaño de la fuente",
|
||||
"fontSizeTip": "El tamaño de fuente predeterminado es 16px, esta configuración afecta el editor y la visualización del tamaño de fuente PDF/HTML exportado",
|
||||
"fontSizeTip": "El tamaño de fuente predeterminado es <code class='fn__code'>16</code>, esta configuración afecta el editor y la visualización del tamaño de fuente PDF/HTML exportado",
|
||||
"font1": "Este ajuste sólo afecta a la visualización de la familia de fuentes en el editor, elija <code class='fn__code'>Por defecto</code> para utilizar la familia de fuentes del tema",
|
||||
"newNameFile": "El nombre del nuevo subdocumento es",
|
||||
"newNameSettingFile": "El nombre del nuevo documento es",
|
||||
|
|
|
@ -574,7 +574,7 @@
|
|||
"kernelFault1": "Vos données doivent être en sécurité, veuillez vérifier si la connexion réseau et le processus du noyau sont normaux, puis redémarrez SiYuan",
|
||||
"kernelFault2": "Si le problème persiste, veuillez rechercher de l'aide ou signaler les bogues <a href=\"https://github.com/siyuan-note/siyuan/issues\" target=\"_blank\">ici</a>",
|
||||
"fontSize": "Taille de la police",
|
||||
"fontSizeTip": "La taille de police par défaut est de 16px, ce paramètre affecte l'éditeur et l'affichage de la taille de police PDF/HTML exportée",
|
||||
"fontSizeTip": "La taille de police par défaut est de <code class='fn__code'>16</code>, ce paramètre affecte l'éditeur et l'affichage de la taille de police PDF/HTML exportée",
|
||||
"font1": "Ce paramètre n'affecte que l'affichage de la famille de polices dans l'éditeur, choisissez <code class='fn__code'>Default</code> pour utiliser la famille de polices du thème.",
|
||||
"newNameFile": "Le nom du nouveau sous-document est",
|
||||
"newNameSettingFile": "Le nom du nouveau document est",
|
||||
|
|
|
@ -574,7 +574,7 @@
|
|||
"kernelFault1": "你的數據應該是安全的,請檢查網絡連接和內核進程是否正常,然後重新啟動思源",
|
||||
"kernelFault2": "如果仍然出現該問題,請在<a href=\"https://ld246.com/article/1649901726096\" target=\"_blank\">這裡</a>尋求幫助或者報告缺陷",
|
||||
"fontSize": "字型大小",
|
||||
"fontSizeTip": "字號默認為 16px,該設置影響編輯器和導出 PDF/HTML 字體大小顯示",
|
||||
"fontSizeTip": "字號默認為 <code class='fn__code'>16</code>,該設置影響編輯器和導出 PDF/HTML 字體大小顯示",
|
||||
"font1": "該設置僅影響編輯器內字體顯示,選擇 <code class='fn__code'>預設</code> 則使用主題自帶字體",
|
||||
"newNameFile": "新建子文檔名為",
|
||||
"newNameSettingFile": "新建文檔名為",
|
||||
|
|
|
@ -574,7 +574,7 @@
|
|||
"kernelFault1": "你的数据应该是安全的,请检查网络连接和内核进程是否正常,然后重新启动思源",
|
||||
"kernelFault2": "如果仍然出现该问题,请在<a href=\"https://ld246.com/article/1649901726096\" target=\"_blank\">这里</a>寻求帮助或者报告缺陷",
|
||||
"fontSize": "字号",
|
||||
"fontSizeTip": "字号默认为 16px,该设置影响编辑器和导出 PDF/HTML 字体大小显示",
|
||||
"fontSizeTip": "字号默认为 <code class='fn__code'>16</code>,该设置影响编辑器和导出 PDF/HTML 字体大小显示",
|
||||
"font1": "该设置仅影响编辑器内字体显示,选择 <code class='fn__code'>默认</code> 则使用主题自带字体",
|
||||
"newNameFile": "新建子文档名为",
|
||||
"newNameSettingFile": "新建文档名为",
|
||||
|
|
|
@ -528,6 +528,14 @@ func getDocCreateSavePath(c *gin.Context) {
|
|||
if "" == docCreateSavePathTpl {
|
||||
docCreateSavePathTpl = model.Conf.FileTree.DocCreateSavePath
|
||||
}
|
||||
docCreateSavePathTpl = strings.TrimSpace(docCreateSavePathTpl)
|
||||
if "../" == docCreateSavePathTpl {
|
||||
docCreateSavePathTpl = "../Untitled"
|
||||
}
|
||||
for strings.HasSuffix(docCreateSavePathTpl, "/") {
|
||||
docCreateSavePathTpl = strings.TrimSuffix(docCreateSavePathTpl, "/")
|
||||
docCreateSavePathTpl = strings.TrimSpace(docCreateSavePathTpl)
|
||||
}
|
||||
|
||||
p, err := model.RenderGoTemplate(docCreateSavePathTpl)
|
||||
if nil != err {
|
||||
|
|
|
@ -300,6 +300,15 @@ func setNotebookConf(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
boxConf.DocCreateSavePath = strings.TrimSpace(boxConf.DocCreateSavePath)
|
||||
if "../" == boxConf.DocCreateSavePath {
|
||||
boxConf.DocCreateSavePath = "../Untitled"
|
||||
}
|
||||
for strings.HasSuffix(boxConf.DocCreateSavePath, "/") {
|
||||
boxConf.DocCreateSavePath = strings.TrimSuffix(boxConf.DocCreateSavePath, "/")
|
||||
boxConf.DocCreateSavePath = strings.TrimSpace(boxConf.DocCreateSavePath)
|
||||
}
|
||||
|
||||
box.SaveConf(boxConf)
|
||||
ret.Data = boxConf
|
||||
}
|
||||
|
|
49
kernel/api/pandoc.go
Normal file
49
kernel/api/pandoc.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
// SiYuan - Build Your Eternal Digital Garden
|
||||
// Copyright (c) 2020-present, b3log.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func pandoc(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
pandocArgs := arg["args"].([]interface{})
|
||||
var args []string
|
||||
for _, v := range pandocArgs {
|
||||
args = append(args, v.(string))
|
||||
}
|
||||
|
||||
err := util.ConvertPandoc(args...)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
|
@ -259,6 +259,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/import/importData", model.CheckAuth, model.CheckReadonly, importData)
|
||||
ginServer.Handle("POST", "/api/import/importSY", model.CheckAuth, model.CheckReadonly, importSY)
|
||||
|
||||
ginServer.Handle("POST", "/api/convert/pandoc", model.CheckAuth, model.CheckReadonly, pandoc)
|
||||
|
||||
ginServer.Handle("POST", "/api/template/render", model.CheckAuth, renderTemplate)
|
||||
ginServer.Handle("POST", "/api/template/docSaveAsTemplate", model.CheckAuth, model.CheckReadonly, docSaveAsTemplate)
|
||||
ginServer.Handle("POST", "/api/template/renderSprig", model.CheckAuth, model.CheckReadonly, renderSprig)
|
||||
|
|
|
@ -265,6 +265,9 @@ func setFiletree(c *gin.Context) {
|
|||
}
|
||||
|
||||
fileTree.DocCreateSavePath = strings.TrimSpace(fileTree.DocCreateSavePath)
|
||||
if "../" == fileTree.DocCreateSavePath {
|
||||
fileTree.DocCreateSavePath = "../Untitled"
|
||||
}
|
||||
for strings.HasSuffix(fileTree.DocCreateSavePath, "/") {
|
||||
fileTree.DocCreateSavePath = strings.TrimSuffix(fileTree.DocCreateSavePath, "/")
|
||||
fileTree.DocCreateSavePath = strings.TrimSpace(fileTree.DocCreateSavePath)
|
||||
|
|
|
@ -19,6 +19,8 @@ package conf
|
|||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
type AI struct {
|
||||
|
@ -37,6 +39,7 @@ type OpenAI struct {
|
|||
func NewAI() *AI {
|
||||
openAI := &OpenAI{
|
||||
APITimeout: 30,
|
||||
APIModel: openai.GPT3Dot5Turbo,
|
||||
APIBaseURL: "https://api.openai.com/v1",
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,9 @@ func InitConf() {
|
|||
Conf.FileTree.MaxOpenTabCount = 32
|
||||
}
|
||||
Conf.FileTree.DocCreateSavePath = strings.TrimSpace(Conf.FileTree.DocCreateSavePath)
|
||||
if "../" == Conf.FileTree.DocCreateSavePath {
|
||||
Conf.FileTree.DocCreateSavePath = "../Untitled"
|
||||
}
|
||||
for strings.HasSuffix(Conf.FileTree.DocCreateSavePath, "/") {
|
||||
Conf.FileTree.DocCreateSavePath = strings.TrimSuffix(Conf.FileTree.DocCreateSavePath, "/")
|
||||
Conf.FileTree.DocCreateSavePath = strings.TrimSpace(Conf.FileTree.DocCreateSavePath)
|
||||
|
@ -339,7 +342,7 @@ func InitConf() {
|
|||
Conf.AI = conf.NewAI()
|
||||
}
|
||||
if "" == Conf.AI.OpenAI.APIModel {
|
||||
Conf.AI.OpenAI.APIModel = openai.GPT4
|
||||
Conf.AI.OpenAI.APIModel = openai.GPT3Dot5Turbo
|
||||
}
|
||||
|
||||
if "" != Conf.AI.OpenAI.APIKey {
|
||||
|
|
|
@ -18,6 +18,8 @@ package util
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -26,6 +28,27 @@ import (
|
|||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func ConvertPandoc(args ...string) (err error) {
|
||||
if "" == PandocBinPath || ContainerStd != Container {
|
||||
return errors.New("not found executable pandoc")
|
||||
}
|
||||
|
||||
pandoc := exec.Command(PandocBinPath, args...)
|
||||
gulu.CmdAttr(pandoc)
|
||||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc")
|
||||
if err = os.MkdirAll(dir, 0755); nil != err {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err)
|
||||
return
|
||||
}
|
||||
pandoc.Dir = dir
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
logging.LogErrorf("pandoc convert output [%s]", string(output))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Pandoc(from, to, o, content string) (ret string, err error) {
|
||||
if "" == from || "" == to || "md" == to {
|
||||
ret = content
|
||||
|
|
Loading…
Add table
Reference in a new issue