From dbe4015655ae95f359c51e2ba2b17d753c9279f9 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 2 Nov 2023 12:59:47 +0500 Subject: [PATCH] web: preserve note edited time when exporting --- apps/web/src/common/export.ts | 6 +++++- apps/web/src/utils/zip.ts | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/web/src/common/export.ts b/apps/web/src/common/export.ts index 5c700ab8e..c6b9e95a7 100644 --- a/apps/web/src/common/export.ts +++ b/apps/web/src/common/export.ts @@ -119,7 +119,11 @@ export async function exportNotes( return await exportToPDF(note.title, exported); } - files.push({ filename: note.title, content: exported }); + files.push({ + filename: note.title, + content: exported, + date: note.dateEdited + }); } if (!files.length) return false; diff --git a/apps/web/src/utils/zip.ts b/apps/web/src/utils/zip.ts index 45de57c25..3b65258f0 100644 --- a/apps/web/src/utils/zip.ts +++ b/apps/web/src/utils/zip.ts @@ -17,19 +17,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { Unzipped } from "fflate"; +import { AsyncZippable } from "fflate"; import { sanitizeFilename } from "@notesnook/common"; const textEncoder = new TextEncoder(); -type File = { filename: string; content: string }; +type File = { filename: string; content: string; date: number }; async function zip(files: File[], format: string): Promise { - const obj: Unzipped = Object.create(null); + const obj: AsyncZippable = Object.create(null); files.forEach((file) => { const name = sanitizeFilename(file.filename, { replacement: "-" }); let counter = 0; while (obj[makeFilename(name, format, counter)]) ++counter; - obj[makeFilename(name, format, counter)] = textEncoder.encode(file.content); + obj[makeFilename(name, format, counter)] = [ + textEncoder.encode(file.content), + { mtime: file.date } + ]; }); const { zip } = await import("fflate"); return new Promise((resolve, reject) =>