-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a kernel API /api/filetree/moveDocsByID
#13247
Comments
需要讨论一下参数,麻烦描述一下。 |
麻烦看到的话补充讨论下,我先关闭了。 |
移动文档 public static async 移动(文档ID: string, 新父ID: string) {
const 笔记本ID = await this.根据ID获取笔记本ID(新父ID);
const 原路径 = await this.根据ID获取路径(文档ID);
const 新路径 = await this.根据ID获取路径(新父ID);
await fetchSyncPost(EAPI.移动文档, {
toNotebook: 笔记本ID,
fromPaths: [原路径],
toPath: 新路径,
});
} 这是我写插件时自己实现的一个函数,希望思源可以提供一个官方的API,毕竟对于插件开发来讲,一些高频的API,每次开发一个新的插件就要写一遍还是不太合理的 我自己开发中常用的其他自己实现的API //#region 公共
public static 通过Markdown创建(
笔记本ID: string,
文档路径: string,
markdown: string
)
public static async 检验文档是否存在(文档ID: string): Promise<boolean> {
const { data } = await fetchSyncPost("/api/query/sql", {
stmt: `SELECT * FROM blocks WHERE id='${文档ID}'`,
});
}
public static async 根据ID获取笔记本ID(ID: string): Promise<string> {
const { data } = await fetchSyncPost("/api/query/sql", {
stmt: `SELECT * FROM blocks WHERE id='${ID}'`,
});
return data[0].box;
}
public static async 根据ID获取路径(ID: string): Promise<string> {
const { data } = await fetchSyncPost("/api/query/sql", {
stmt: `SELECT * FROM blocks WHERE id='${ID}'`,
});
return data[0].path;
}
public static async 根据ID获取文档的父文档ID(ID: string): Promise<string> {
const { data } = await fetchSyncPost("/api/query/sql", {
stmt: `SELECT * FROM blocks WHERE id='${ID}'`,
});
return data[0].path.slice(1, 23);
}
public static async 重命名(笔记本ID: string, ID: string, 新名称: string) {
const 路径 = await this.根据ID获取路径(ID);
await fetchSyncPost(EAPI.重命名文档, {
notebook: 笔记本ID,
path: 路径,
title: 新名称,
});
}
public static async 移动(文档ID: string, 新父ID: string) {
const 笔记本ID = await this.根据ID获取笔记本ID(新父ID);
const 原路径 = await this.根据ID获取路径(文档ID);
const 新路径 = await this.根据ID获取路径(新父ID);
await fetchSyncPost(EAPI.移动文档, {
toNotebook: 笔记本ID,
fromPaths: [原路径],
toPath: 新路径,
});
}
//#endregion
//#region 日记
public static async 获取日记根文档(
笔记本ID: string
): Promise<{ id: string }> {
const value = await SY笔记本.获取笔记本配置(笔记本ID);
const 日记文档名称 = value.data.conf.dailyNoteSavePath.split("/")[1];
const { data } = await SQLer.获取日记根文档(笔记本ID, 日记文档名称);
if (data.length === 0) {
return {
id: (await this.通过Markdown创建(笔记本ID, `/${日记文档名称}`, ""))
.data,
};
}
return data[0];
}
public static async 获取对应日期的日记文档(
笔记本ID: string,
日期: Dayjs
): Promise<{ id: string }> {
const value = await SY笔记本.获取笔记本配置(笔记本ID);
const 日记文档保存路径 = value.data.conf.dailyNoteSavePath;
const 日记文档名称 = 日记文档保存路径.split("/")[1];
const 日期日记路径 = `/${日记文档名称}/${日期.format(
"YYYY/MM/YYYY-MM-DD"
)}`;
const { data } = await SQLer.获取日期对应的日记文档(笔记本ID, 日期日记路径);
if (data.length === 0) {
const 文档ID = await this.通过Markdown创建(
笔记本ID,
日期日记路径,
""
).then(async ({ data }) => {
const 日期字符串 = dayjs(日期).format("YYYYMMDD");
await SY块.设置块属性({
id: data,
attrs: {
[E块属性名称.日记前缀 + 日期字符串]: 日期字符串,
},
});
return data;
});
return {
id: 文档ID,
};
}
return data[0];
} |
看上去基础 API 只有移动这个需要加一下 by ID 的方式,其他接口暂时不加了,谢谢。 通过
|
88250
changed the title
可以将移动文档所需参数从path转换成ID吗
Add a kernel API Dec 5, 2024
/api/filetree/moveDocsByID
88250
added a commit
that referenced
this issue
Dec 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以将移动文档所需参数从path转换成ID吗
In what scenarios do you need this feature?
目前的移动文档需要获取当前path和移动到的path,根据ID的话可以减少一些数据库查询
如果可以的话建议新增也加一个根据ID创建,毕竟插入子块跟创建文档其实差不多
Describe the optimal solution
希望增加新的API来增加开发的便捷性
Describe the candidate solution
No response
Other information
No response
The text was updated successfully, but these errors were encountered: