Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(import): preserve OneNote section creation/modification dates
Elian Doran0875364de2e7
diff --git a/apps/client/src/services/onenote_import.ts b/apps/client/src/services/onenote_import.tsindex b7a9daf3a9..97ceb51994 100644--- a/apps/client/src/services/onenote_import.ts+++ b/apps/client/src/services/onenote_import.ts@@ -18,6 +18,8 @@ export interface OneNoteStatus {export interface OneNoteSection {id: string;title: string;+ createdDateTime?: string;+ lastModifiedDateTime?: string;}export interface OneNoteNotebook {@@ -32,6 +34,8 @@ export interface OneNoteNotebook {export interface OneNoteSectionSelection {id: string;title: string;+ createdDateTime?: string;+ lastModifiedDateTime?: string;notebookId: string;notebookTitle: string;notebookCreatedDateTime?: string;diff --git a/apps/client/src/widgets/dialogs/import_providers/onenote.tsx b/apps/client/src/widgets/dialogs/import_providers/onenote.tsxindex 4e733e02af..0fcc477a8d 100644--- a/apps/client/src/widgets/dialogs/import_providers/onenote.tsx+++ b/apps/client/src/widgets/dialogs/import_providers/onenote.tsx@@ -104,6 +104,8 @@ function OneNotePanel({ parentNoteId, closeDialog }: ImportProviderPanelProps) {sections.push({id: section.id,title: section.title,+ createdDateTime: section.createdDateTime,+ lastModifiedDateTime: section.lastModifiedDateTime,notebookId: notebook.id,notebookTitle: notebook.title,notebookCreatedDateTime: notebook.createdDateTime,diff --git a/apps/server/src/services/import/onenote/graph.ts b/apps/server/src/services/import/onenote/graph.tsindex b9061cbcb3..8b30d4d24f 100644--- a/apps/server/src/services/import/onenote/graph.ts+++ b/apps/server/src/services/import/onenote/graph.ts@@ -17,6 +17,8 @@ export interface GraphAccount {export interface OneNoteSection {id: string;title: string;+ createdDateTime?: string;+ lastModifiedDateTime?: string;}export interface OneNoteNotebook {@@ -54,12 +56,12 @@ export async function getAccount(accessToken: string): Promise<GraphAccount> {* section groups nest arbitrarily and the notebooks endpoint won't $expand them more than one level.*/export async function listNotebooks(accessToken: string): Promise<OneNoteNotebook[]> {- const url = "/me/onenote/notebooks?$select=id,displayName,createdDateTime,lastModifiedDateTime,sectionGroupsUrl&$expand=sections($select=id,displayName),sectionGroups($select=id)&$orderby=displayName";+ const url = "/me/onenote/notebooks?$select=id,displayName,createdDateTime,lastModifiedDateTime,sectionGroupsUrl&$expand=sections($select=id,displayName,createdDateTime,lastModifiedDateTime),sectionGroups($select=id)&$orderby=displayName";const notebooks = await graphGetAll<RawNotebook>(accessToken, url);return Promise.all(notebooks.map(async (notebook) => {- const direct = (notebook.sections ?? []).map((s) => ({ id: s.id, title: s.displayName }));+ const direct = (notebook.sections ?? []).map((s) => ({ id: s.id, title: s.displayName, createdDateTime: s.createdDateTime, lastModifiedDateTime: s.lastModifiedDateTime }));const grouped = notebook.sectionGroups?.length && notebook.sectionGroupsUrl ? await sectionsFromSectionGroups(accessToken, notebook.sectionGroupsUrl, "") : [];return {id: notebook.id,@@ -78,13 +80,13 @@ export async function listNotebooks(accessToken: string): Promise<OneNoteNoteboo* further round-trip happens only for groups that actually have children.*/async function sectionsFromSectionGroups(accessToken: string, sectionGroupsUrl: string, prefix: string): Promise<OneNoteSection[]> {- const url = appendQuery(sectionGroupsUrl, "$select=id,displayName,sectionGroupsUrl&$expand=sections($select=id,displayName),sectionGroups($select=id)");+ const url = appendQuery(sectionGroupsUrl, "$select=id,displayName,sectionGroupsUrl&$expand=sections($select=id,displayName,createdDateTime,lastModifiedDateTime),sectionGroups($select=id)");const groups = await graphGetAll<RawSectionGroup>(accessToken, url);const perGroup = await Promise.all(groups.map(async (group) => {const path = prefix ? `${prefix} / ${group.displayName}` : group.displayName;- const direct = (group.sections ?? []).map((s) => ({ id: s.id, title: `${path} / ${s.displayName}` }));+ const direct = (group.sections ?? []).map((s) => ({ id: s.id, title: `${path} / ${s.displayName}`, createdDateTime: s.createdDateTime, lastModifiedDateTime: s.lastModifiedDateTime }));const nested = group.sectionGroups?.length && group.sectionGroupsUrl ? await sectionsFromSectionGroups(accessToken, group.sectionGroupsUrl, path) : [];return [...direct, ...nested];})@@ -180,7 +182,7 @@ interface RawNotebook {createdDateTime?: string;lastModifiedDateTime?: string;sectionGroupsUrl?: string;- sections?: { id: string; displayName: string }[];+ sections?: { id: string; displayName: string; createdDateTime?: string; lastModifiedDateTime?: string }[];/** id-only, requested just to detect whether the notebook has section groups to follow. */sectionGroups?: { id: string }[];}@@ -189,7 +191,7 @@ interface RawSectionGroup {id: string;displayName: string;sectionGroupsUrl?: string;- sections?: { id: string; displayName: string }[];+ sections?: { id: string; displayName: string; createdDateTime?: string; lastModifiedDateTime?: string }[];/** id-only, requested just to detect whether the group has nested section groups to follow. */sectionGroups?: { id: string }[];}diff --git a/apps/server/src/services/import/onenote/importer.ts b/apps/server/src/services/import/onenote/importer.tsindex 9c84670451..f12ee13a85 100644--- a/apps/server/src/services/import/onenote/importer.ts+++ b/apps/server/src/services/import/onenote/importer.ts@@ -17,6 +17,10 @@ import { type LinkTarget, rewritePageLinks } from "./links.js";export interface SectionSelection {id: string;title: string;+ /** OneNote's section creation timestamp (ISO 8601), preserved on the imported section folder. */+ createdDateTime?: string;+ /** OneNote's section last-modified timestamp (ISO 8601), preserved on the imported section folder. */+ lastModifiedDateTime?: string;notebookId: string;notebookTitle: string;/** OneNote's notebook creation timestamp (ISO 8601), preserved on the imported notebook folder. */@@ -56,6 +60,8 @@ interface DownloadedResource {interface FetchedSection {title: string;+ createdDateTime?: string;+ lastModifiedDateTime?: string;notebookId: string;notebookTitle: string;notebookCreatedDateTime?: string;@@ -96,6 +102,8 @@ export async function importSelection({ accessToken, parentNoteId, sections, tas}fetched.push({title: section.title,+ createdDateTime: section.createdDateTime,+ lastModifiedDateTime: section.lastModifiedDateTime,notebookId: section.notebookId,notebookTitle: section.notebookTitle,notebookCreatedDateTime: section.notebookCreatedDateTime,@@ -142,6 +150,7 @@ function createNotes(parentNoteId: string, sections: FetchedSection[], debug: bo}const sectionNote = createFolder(notebookNoteId, section.title);+ applyOriginalDates(sectionNote, section.createdDateTime, section.lastModifiedDateTime);for (const page of section.pages) {const { note: pageNote } = noteService.createNewNote({