Skip to content

Commit

Permalink
feat:#1 更新api
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 9, 2022
1 parent 2f44117 commit dd4b233
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ yarn
## dev

```bash
vercel dev
yarn dev
```

or

```bash
yarn vdev
```

## deploy
Expand Down
1 change: 1 addition & 0 deletions lib/platform/metaweblog/customXmlrpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logUtil from "~/lib/logUtil";
// 注意:这里必须带上后缀.js,否则生产环境的vercel会构建失败
// @ts-ignore
import * as Serializer from 'xmlrpc/lib/serializer.js'
import { parse } from 'arraybuffer-xml-parser';
Expand Down
51 changes: 39 additions & 12 deletions lib/platform/siyuan/siYuanApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,48 @@ export class SiYuanApi {
/**
* 分页获取根文档
* @param page 页码
* @param pagesize 数目
* @param keyword 关键字
*/
public async getRootBlocksCount(keyword: string) {
let stmt = `SELECT COUNT(DISTINCT b1.root_id) as count
FROM blocks b1
WHERE 1 = 1
AND ((b1.content LIKE '%${keyword}%') OR (b1.tag LIKE '%${keyword}%')
)`;
let data = await this.sql(stmt)
// logUtil.logError("getRootBlocksCount data=>", data[0].count)
return data[0].count
}

/**
* 分页获取根文档
* @param page 页码
* @param pagesize 数目
*
* select DISTINCT b2.root_id,b2.parent_id,b2.content from blocks b2
* WHERE 1==1
* AND b2.id IN (
* SELECT DISTINCT b1.root_id
* FROM blocks b1
* WHERE 1 = 1
* AND ((b1.content LIKE '%github%') OR (b1.tag LIKE '%github%'))
* ORDER BY b1.updated DESC,b1.created DESC LIMIT 0,10
* )
* ORDER BY b2.updated DESC,b2.created DESC
*/
public async getRootBlocks(page: number, pagesize: number, keyword: string) {
let stmt = `SELECT b.content, tmp.root_id
FROM (SELECT DISTINCT root_id
FROM blocks
WHERE 1 = 1
AND content LIKE '%${keyword}%'
ORDER BY created DESC LIMIT ${page}, ${pagesize}) tmp,
blocks b
WHERE tmp.root_id = b.root_id
AND b.parent_id = ''
ORDER BY b.created DESC`
return await this.sql(stmt)
let stmt = `select DISTINCT b2.root_id,b2.parent_id,b2.content from blocks b2
WHERE 1==1
AND b2.id IN (
SELECT DISTINCT b1.root_id
FROM blocks b1
WHERE 1 = 1
AND ((b1.content LIKE '%${keyword}%') OR (b1.tag LIKE '%${keyword}%'))
ORDER BY b1.updated DESC,b1.created DESC LIMIT ${page},${pagesize}
)
ORDER BY b2.updated DESC,b2.created DESC`
let data = await this.sql(stmt)
return data
}

/**
Expand Down

0 comments on commit dd4b233

Please sign in to comment.