web: preserve note edited time when exporting

This commit is contained in:
Abdullah Atta
2023-11-02 12:59:47 +05:00
parent 76237ad7dd
commit dbe4015655
2 changed files with 12 additions and 5 deletions

View File

@@ -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;

View File

@@ -17,19 +17,22 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<Uint8Array> {
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) =>