-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
18 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ func ConvertPandoc(args ...string) (err error) { | |
|
||
pandoc := exec.Command(PandocBinPath, args...) | ||
gulu.CmdAttr(pandoc) | ||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc") | ||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc", gulu.Rand.String(7)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
terwer
Contributor
|
||
if err = os.MkdirAll(dir, 0755); nil != err { | ||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err) | ||
return | ||
|
@@ -50,31 +50,38 @@ func ConvertPandoc(args ...string) (err error) { | |
return | ||
} | ||
|
||
func Pandoc(from, to, o, content string) (ret string, err error) { | ||
func Pandoc(from, to, o, content string) (err error) { | ||
if "" == from || "" == to || "md" == to { | ||
ret = content | ||
return | ||
} | ||
|
||
dir := filepath.Join(WorkspaceDir, "temp", "convert", "pandoc", gulu.Rand.String(7)) | ||
if err = os.MkdirAll(dir, 0755); nil != err { | ||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err) | ||
return | ||
} | ||
tmpPath := filepath.Join(dir, gulu.Rand.String(7)) | ||
if err = os.WriteFile(tmpPath, []byte(content), 0644); nil != err { | ||
logging.LogErrorf("write file failed: [%s]", err) | ||
return | ||
} | ||
|
||
args := []string{ | ||
tmpPath, | ||
"--from", from, | ||
"--to", to, | ||
"--resource-path", filepath.Dir(o), | ||
"-s", | ||
} | ||
|
||
if "" != o { | ||
args = append(args, "-o", o) | ||
"-o", o, | ||
} | ||
|
||
pandoc := exec.Command(PandocBinPath, args...) | ||
gulu.CmdAttr(pandoc) | ||
pandoc.Stdin = bytes.NewBufferString(content) | ||
output, err := pandoc.CombinedOutput() | ||
if nil != err { | ||
logging.LogErrorf("pandoc convert output [%s], error [%s]", string(output), err) | ||
return | ||
} | ||
ret = string(output) | ||
return | ||
} | ||
|
||
|
这里是 /api/convert/pandoc 的处理函数, 此处新建了一个目录作为 pandoc 的工作目录, 但是没有任何该目录的相关信息, 导致 API 调用后无法对其进行后续处理
优化方案一
/api/convert/pandoc 请求体新增一个可选参数
pathName
, 该参数指定目录名称, 若未设置则使用随机的目录名, pandoc 使用workspace/temp/convert/pandoc/pathName
作为其工作目录, 同时将该目录相对于思源工作空间根目录的相对路径作为响应体data.path
返回优化方案二
/api/convert/pandoc 请求体新增一个可选参数
path
, 该参数指定相对于思源工作空间目录的相对目录, 若未设置则使用workspace/temp/convert/pandoc/随机目录名
目录, pandoc 使用该目录作为其工作目录, 同时将该目录相对于思源工作空间根目录的相对路径作为响应体data.path
返回