Skip to content

增加一个设置笔记本与文档排序的内核 API #15776

@TCOTC

Description

@TCOTC

传入数组(顺序与排序无关):

[
  {
    id: "20250905002452-4ubtsd2" // 笔记本或文档 ID
    sort: 0
  },
  {
    id: "20250904001247-cl2aws7"
    sort: -8
  }
]

如果排序有更新(值确实变化了),并且前端文档树的 ID 对应的文档的父文档或笔记本是展开状态,还需要重新生成子文档列表


我的插件就差排序实现不了了:

const res = await fetchSyncPost('/api/filetree/moveDocsByID', {
    fromIDs: [currentDoc.id],
    toID: targetDocId || targetNotebookId,
});
if (res.code !== 0) {
    // 移动文档失败
    showMessage(this.displayName + ": " + this.i18n.moveDocFailed);
    return;
}
let notebook: string;
let path: string;
if (targetDocId) {
    const res2 = await fetchSyncPost('/api/filetree/getPathByID', {
        id: currentDoc.id,
    });
    console.log("res2", res2);
    notebook = res2.data?.notebook;
    path = res2.data?.path;
    if (res2.code !== 0 || !notebook || !path) {
        // 获取文档路径失败
        showMessage(this.displayName + ": " + this.i18n.getPathByIDFailed);
        return;
    }
    targetNotebookId = notebook;
}
const res3 = await fetchSyncPost('/api/filetree/listDocsByPath', {
    notebook: targetNotebookId,
    path: targetDocId || "/",
    maxListCount: 1, // 只需要获取最上面的文档的排序就够了
    showHidden: true, // 包含隐藏的文档
    ignoreMaxListHint: true, // 忽略最大数量提示
});
console.log("res3", res3);
const firstDocId = res3.data?.files[0]?.id;
const firstDocSort = res3.data?.files[0]?.sort;
if (res3.code !== 0 || !firstDocId || !firstDocSort) {
    // 通过路径获取文档失败
    showMessage(this.displayName + ": " + this.i18n.getDocsByPathFailed);
    return;
}
if (firstDocId !== currentDoc.id) {
    // TODO: 修改排序
    // 这个 API 不能指定排序值:
    // const res4 = await fetchSyncPost("/api/filetree/changeSort", {
    //     paths: [path],      // 新的排序路径数组
    //     notebook: notebook  // 目标笔记本 ID
    // });
    // console.log("res4", res4);
}
// 等待文档移动并排序完成之后才能展开文档树
if (this.data[STORAGE_NAME].expandDocTreeAfterMoveDoc) {
    // 移动文档之后展开文档树 https://github.com/TCOTC/move-doc/issues/2
    expandDocTree({ id: currentDoc.id });
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions