refac
Co-Authored-By: Leandro Ygor Loli <77518998+leandroyloli@users.noreply.github.com>
This commit is contained in:
co-authored by
Leandro Ygor Loli
parent
8c485b260f
commit
2a804541e0
@@ -31,7 +31,7 @@
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
import { WEBUI_NAME, config, prompts as _prompts, user } from '$lib/stores';
|
||||
import { createNewNote, deleteNoteById, getNoteList, searchNotes } from '$lib/apis/notes';
|
||||
import { createNewNote, deleteNoteById, getNoteById, getNoteList, searchNotes } from '$lib/apis/notes';
|
||||
import { capitalizeFirstLetter, copyToClipboard, getTimeRange } from '$lib/utils';
|
||||
import { downloadPdf, createNoteHandler } from './utils';
|
||||
|
||||
@@ -73,15 +73,23 @@
|
||||
let allItemsLoaded = false;
|
||||
|
||||
const downloadHandler = async (type) => {
|
||||
// Fetch the full note since the list response may not contain full content
|
||||
const note = await getNoteById(localStorage.token, selectedNote.id).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!note) return;
|
||||
|
||||
if (type === 'txt') {
|
||||
const blob = new Blob([selectedNote.data.content.md], { type: 'text/plain' });
|
||||
saveAs(blob, `${selectedNote.title}.txt`);
|
||||
const blob = new Blob([note.data.content.md], { type: 'text/plain' });
|
||||
saveAs(blob, `${note.title}.txt`);
|
||||
} else if (type === 'md') {
|
||||
const blob = new Blob([selectedNote.data.content.md], { type: 'text/markdown' });
|
||||
saveAs(blob, `${selectedNote.title}.md`);
|
||||
const blob = new Blob([note.data.content.md], { type: 'text/markdown' });
|
||||
saveAs(blob, `${note.title}.md`);
|
||||
} else if (type === 'pdf') {
|
||||
try {
|
||||
await downloadPdf(selectedNote);
|
||||
await downloadPdf(note);
|
||||
} catch (error) {
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user