Co-Authored-By: Leandro Ygor Loli <77518998+leandroyloli@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek
2026-02-19 16:57:32 -06:00
parent 8c485b260f
commit 2a804541e0
2 changed files with 27 additions and 7 deletions

View File

@@ -36,6 +36,14 @@ log = logging.getLogger(__name__)
router = APIRouter()
def _truncate_note_data(data: Optional[dict], max_length: int = 1000) -> Optional[dict]:
if not data:
return data
md = (data.get("content") or {}).get("md") or ""
return {"content": {"md": md[:max_length]}}
############################
# GetNotes
############################
@@ -82,6 +90,7 @@ async def get_notes(
NoteUserResponse(
**{
**note.model_dump(),
"data": _truncate_note_data(note.data),
"user": UserResponse(**users[note.user_id].model_dump()),
}
)
@@ -135,7 +144,10 @@ async def search_notes(
filter["user_id"] = user.id
return Notes.search_notes(user.id, filter, skip=skip, limit=limit, db=db)
result = Notes.search_notes(user.id, filter, skip=skip, limit=limit, db=db)
for note in result.items:
note.data = _truncate_note_data(note.data)
return result
############################

View File

@@ -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}`);
}