import { PluginFileAPI, PluginCommAPI } from 'sn-plugin-lib';
/**
* 创建笔记的示例(使用系统模版)。
*/
export async function exampleCreateNote() {
const notePath = '/storage/emulated/0/Note/new.note';
// 获取系统模版列表并选择一个模版名称(Template.name)
const tplRes = await PluginCommAPI.getNoteSystemTemplates();
if (!tplRes.success) {
throw new Error(tplRes.error?.message ?? 'getNoteSystemTemplates 调用失败');
}
const templates = (tplRes.result ?? []) as any[];
const templateName = templates[0]?.name;
if (!templateName) {
throw new Error('未获取到系统模版名称');
}
const res = await PluginFileAPI.createNote({
notePath,
template: templateName,
mode: 0,
isPortrait: true,
});
if (!res.success) {
throw new Error(res.error?.message ?? 'createNote 调用失败');
}
return res.result;
}