Skip to content

Commit 2a80454

Browse files
tjbckleandroyloli
andcommitted
refac
Co-Authored-By: Leandro Ygor Loli <77518998+leandroyloli@users.noreply.github.com>
1 parent 8c485b2 commit 2a80454

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

backend/open_webui/routers/notes.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636

3737
router = APIRouter()
3838

39+
40+
def _truncate_note_data(data: Optional[dict], max_length: int = 1000) -> Optional[dict]:
41+
if not data:
42+
return data
43+
md = (data.get("content") or {}).get("md") or ""
44+
return {"content": {"md": md[:max_length]}}
45+
46+
3947
############################
4048
# GetNotes
4149
############################
@@ -82,6 +90,7 @@ async def get_notes(
8290
NoteUserResponse(
8391
**{
8492
**note.model_dump(),
93+
"data": _truncate_note_data(note.data),
8594
"user": UserResponse(**users[note.user_id].model_dump()),
8695
}
8796
)
@@ -135,7 +144,10 @@ async def search_notes(
135144

136145
filter["user_id"] = user.id
137146

138-
return Notes.search_notes(user.id, filter, skip=skip, limit=limit, db=db)
147+
result = Notes.search_notes(user.id, filter, skip=skip, limit=limit, db=db)
148+
for note in result.items:
149+
note.data = _truncate_note_data(note.data)
150+
return result
139151

140152

141153
############################

src/lib/components/notes/Notes.svelte

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
3232
import { goto } from '$app/navigation';
3333
import { WEBUI_NAME, config, prompts as _prompts, user } from '$lib/stores';
34-
import { createNewNote, deleteNoteById, getNoteList, searchNotes } from '$lib/apis/notes';
34+
import { createNewNote, deleteNoteById, getNoteById, getNoteList, searchNotes } from '$lib/apis/notes';
3535
import { capitalizeFirstLetter, copyToClipboard, getTimeRange } from '$lib/utils';
3636
import { downloadPdf, createNoteHandler } from './utils';
3737
@@ -73,15 +73,23 @@
7373
let allItemsLoaded = false;
7474
7575
const downloadHandler = async (type) => {
76+
// Fetch the full note since the list response may not contain full content
77+
const note = await getNoteById(localStorage.token, selectedNote.id).catch((error) => {
78+
toast.error(`${error}`);
79+
return null;
80+
});
81+
82+
if (!note) return;
83+
7684
if (type === 'txt') {
77-
const blob = new Blob([selectedNote.data.content.md], { type: 'text/plain' });
78-
saveAs(blob, `${selectedNote.title}.txt`);
85+
const blob = new Blob([note.data.content.md], { type: 'text/plain' });
86+
saveAs(blob, `${note.title}.txt`);
7987
} else if (type === 'md') {
80-
const blob = new Blob([selectedNote.data.content.md], { type: 'text/markdown' });
81-
saveAs(blob, `${selectedNote.title}.md`);
88+
const blob = new Blob([note.data.content.md], { type: 'text/markdown' });
89+
saveAs(blob, `${note.title}.md`);
8290
} else if (type === 'pdf') {
8391
try {
84-
await downloadPdf(selectedNote);
92+
await downloadPdf(note);
8593
} catch (error) {
8694
toast.error(`${error}`);
8795
}

0 commit comments

Comments
 (0)