From b90fdf11d2782bfc4264febea9f39bfaa4abcb03 Mon Sep 17 00:00:00 2001 From: terwer Date: Mon, 12 Jun 2023 00:17:04 +0800 Subject: [PATCH] docs: update deps --- README.md | 5 +-- README_zh_CN.md | 3 +- libs/zhi-siyuan-api/CHANGELOG.md | 12 +++++++ libs/zhi-siyuan-api/package.json | 2 +- .../src/lib/kernel/siyuanKernelApi.spec.ts | 33 ++++++++----------- .../src/lib/kernel/siyuanKernelApi.ts | 19 +++++++++-- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a8dc29e7..0f77992a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ - [ ] [zhi-yuque-api](https://github.com/terwer/zhi/tree/main/libs/zhi-yuque-api) - [ ] [zhi-liandi-api](https://github.com/terwer/zhi/tree/main/libs/zhi-liandi-api) - [ ] [zhi-kms-api](https://github.com/terwer/zhi/tree/main/libs/zhi-kms-api) - - [ ] [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api) + - [X] [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api) - [ ] [zhi-wechat-api](https://github.com/terwer/zhi/tree/main/libs/zhi-wechat-api) - [ ] [zhi-http-api](https://github.com/terwer/zhi/tree/main/libs/zhi-http-api) - [ ] [zhi-zhihu-api](https://github.com/terwer/zhi/tree/main/libs/zhi-zhihu-api) @@ -66,4 +66,5 @@ - [siyuan-plugin-custom-slug](https://github.com/terwer/siyuan-plugin-custom-slug) - Document alias, a new alias index for document titles, convenient for quick search Available - [siyuan-plugin-code-block](https://github.com/terwer/siyuan-plugin-code-block) - Code block beautification, imitating Mac style code block style Available - [siyuan-plugin-2md](https://github.com/terwer/siyuan-plugin-2md) - Markdown batch conversion, batch conversion of documents of Siyuan notes into Markdown files, support conversion properties for Hexo, HUGO, Vitepress, Obsidian and other platforms corresponding to FrontFormatter In progress -- [siyuan-plugin-random-doc](https://github.com/terwer/siyuan-plugin-random-doc) - Random Doc In progress \ No newline at end of file +- [siyuan-plugin-random-doc](https://github.com/terwer/siyuan-plugin-random-doc) - Random Doc In progress +- [siyuan-plugin-picgo](https://github.com/terwer/siyuan-plugin-picgo) - PocGo In progress diff --git a/README_zh_CN.md b/README_zh_CN.md index ccd4a0a5..46853f09 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -34,7 +34,7 @@ - [ ] [zhi-yuque-api](https://github.com/terwer/zhi/tree/main/libs/zhi-yuque-api) - [ ] [zhi-liandi-api](https://github.com/terwer/zhi/tree/main/libs/zhi-liandi-api) - [ ] [zhi-kms-api](https://github.com/terwer/zhi/tree/main/libs/zhi-kms-api) - - [ ] [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api) + - [X] [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api) - [ ] [zhi-wechat-api](https://github.com/terwer/zhi/tree/main/libs/zhi-wechat-api) - [ ] [zhi-http-api](https://github.com/terwer/zhi/tree/main/libs/zhi-http-api) - [ ] [zhi-zhihu-api](https://github.com/terwer/zhi/tree/main/libs/zhi-zhihu-api) @@ -67,3 +67,4 @@ - [siyuan-plugin-code-block](https://github.com/terwer/siyuan-plugin-code-block) - 代码块美化,模仿Mac风格的代码块风格 已上架 - [siyuan-plugin-2md](https://github.com/terwer/siyuan-plugin-2md) - Markdown批量转换,将思源笔记的文档批量转换为Markdown文件,支持转换属性为Hexo、HUGO、Vitepress、Obsidian等平台对应的FrontFormatter 进行中 - [siyuan-plugin-random-doc](https://github.com/terwer/siyuan-plugin-random-doc) - 文档漫游 进行中 +- [siyuan-plugin-picgo](https://github.com/terwer/siyuan-plugin-picgo) - PocGo图床 进行中 diff --git a/libs/zhi-siyuan-api/CHANGELOG.md b/libs/zhi-siyuan-api/CHANGELOG.md index 20ddc9f0..0bf60d22 100644 --- a/libs/zhi-siyuan-api/CHANGELOG.md +++ b/libs/zhi-siyuan-api/CHANGELOG.md @@ -1,5 +1,17 @@ # zhi-siyuan-api +## 1.9.1 + +### Patch Changes + +- add get image blocks + +## 1.9.0 + +### Minor Changes + +- remove unused appinstance + ## 1.8.0 ### Minor Changes diff --git a/libs/zhi-siyuan-api/package.json b/libs/zhi-siyuan-api/package.json index b52256a7..8a315ec9 100644 --- a/libs/zhi-siyuan-api/package.json +++ b/libs/zhi-siyuan-api/package.json @@ -1,6 +1,6 @@ { "name": "zhi-siyuan-api", - "version": "1.8.0", + "version": "1.9.1", "type": "module", "description": "a siyuan-note api including both kernel and client", "main": "./dist/index.js", diff --git a/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.spec.ts b/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.spec.ts index fff216e6..0297ac20 100644 --- a/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.spec.ts +++ b/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.spec.ts @@ -26,84 +26,77 @@ import { describe, it } from "vitest" import SiyuanKernelApi from "./siyuanKernelApi" import SiyuanConfig from "../config/siyuanConfig" -import path from "path" describe("SiyuanKernelApi", async () => { - // appInstance - const appInstance: any = {} - const projectBase = path.resolve(__dirname, "../../..") - const moduleBase = path.resolve(__dirname, "../../../../..") - console.log(path.join(moduleBase, "libs/zhi-common/dist/index.js")) - // lute // require(path.join(moduleBase, "libs/zhi-common/public/libs/lute/lute-1.7.5-20230410.min.cjs")) it("sql using siyuanConfig", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.sql("select 1 from blocks limit 1") console.log("result=>", result) }) it("getRootBlocksCount", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.getRootBlocksCount("") console.log("result=>", result) }) it("lsNotebooks", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.lsNotebooks() console.log("result=>", result) }) it("openNotebook", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.openNotebook("20220718062546-2nbmy21") console.log("result=>", result) }) it("closeNotebook", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.closeNotebook("20220718062546-2nbmy21") console.log("result=>", result) }) it("renameNotebook", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.renameNotebook("20220621105123-dlyn6nl", "临时文档") console.log("result=>", result) }) it("createNotebook", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.createNotebook("临时文档3") console.log("result=>", result) }) it("removeNotebook", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.removeNotebook("20230401225851-4zgh677") console.log("result=>", result) }) it("getNotebookConf", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.getNotebookConf("20220621105123-dlyn6nl") console.log("result=>", result) }) it("setNotebookConf", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.setNotebookConf({ notebook: "20220621105123-dlyn6nl", conf: { @@ -120,7 +113,7 @@ describe("SiyuanKernelApi", async () => { it("pushMsg", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.pushMsg({ msg: "测试消息", }) @@ -129,7 +122,7 @@ describe("SiyuanKernelApi", async () => { it("pushErrMsg", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.pushErrMsg({ msg: "测试错误消息", }) @@ -138,7 +131,7 @@ describe("SiyuanKernelApi", async () => { it("getRootBlocks", async () => { const siyuanConfig = new SiyuanConfig("http://127.0.0.1:6806", "") - const kernelApi = new SiyuanKernelApi(appInstance, siyuanConfig) + const kernelApi = new SiyuanKernelApi(siyuanConfig) const result = await kernelApi.getRootBlocks(0, 10, "") console.log("result=>", result) }) diff --git a/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.ts b/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.ts index 7b3e2d22..49a5544e 100644 --- a/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.ts +++ b/libs/zhi-siyuan-api/src/lib/kernel/siyuanKernelApi.ts @@ -55,10 +55,9 @@ class SiyuanKernelApi implements ISiyuanKernelApi { /** * 初始化思源服务端 API * - * @param appInstance - 应用实例 * @param cfg -配置项 */ - constructor(appInstance: any, cfg: SiyuanConfig) { + constructor(cfg: SiyuanConfig) { this.VERSION = "1.0.0" this.siyuanConfig = cfg @@ -515,6 +514,22 @@ class SiyuanKernelApi implements ISiyuanKernelApi { public async uploadAsset(formData: any): Promise { return await this.siyuanRequestForm("/api/asset/upload", formData) } + + /** + * 以id获取所有图片块 + * + * @param blockId - 块ID + */ + public async getImageBlocksByID(blockId: string): Promise { + const stmt = `select * + from blocks + where root_id = '${blockId}' and markdown like '%![%'` + const data = await this.sql(stmt) + if (!data) { + throw new Error("通过ID查询图片块信息失败") + } + return data as any[] + } } export default SiyuanKernelApi