mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 13:55:19 +00:00
wip: notes
This commit is contained in:
parent
93d27b84d4
commit
30bd4a2910
4 changed files with 23 additions and 23 deletions
|
|
@ -74,7 +74,7 @@ class NoteUserResponse(NoteModel):
|
||||||
|
|
||||||
|
|
||||||
class NoteTable:
|
class NoteTable:
|
||||||
def insert_new_note(
|
async def insert_new_note(
|
||||||
self,
|
self,
|
||||||
form_data: NoteForm,
|
form_data: NoteForm,
|
||||||
user_id: str,
|
user_id: str,
|
||||||
|
|
@ -92,8 +92,8 @@ class NoteTable:
|
||||||
|
|
||||||
new_note = Note(**note.model_dump())
|
new_note = Note(**note.model_dump())
|
||||||
|
|
||||||
db.add(new_note)
|
await db.add(new_note)
|
||||||
db.commit()
|
await db.commit()
|
||||||
return note
|
return note
|
||||||
|
|
||||||
async def get_notes(self) -> list[NoteModel]:
|
async def get_notes(self) -> list[NoteModel]:
|
||||||
|
|
@ -112,16 +112,16 @@ class NoteTable:
|
||||||
or await has_access(user_id, permission, note.access_control)
|
or await has_access(user_id, permission, note.access_control)
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_note_by_id(self, id: str) -> Optional[NoteModel]:
|
async def get_note_by_id(self, id: str) -> Optional[NoteModel]:
|
||||||
async with get_db() as db:
|
async with get_db() as db:
|
||||||
note = db.query(Note).filter(Note.id == id).first()
|
note = await db.query(Note).filter(Note.id == id).first()
|
||||||
return NoteModel.model_validate(note) if note else None
|
return NoteModel.model_validate(note) if note else None
|
||||||
|
|
||||||
def update_note_by_id(
|
async def update_note_by_id(
|
||||||
self, id: str, form_data: NoteUpdateForm
|
self, id: str, form_data: NoteUpdateForm
|
||||||
) -> Optional[NoteModel]:
|
) -> Optional[NoteModel]:
|
||||||
async with get_db() as db:
|
async with get_db() as db:
|
||||||
note = db.query(Note).filter(Note.id == id).first()
|
note = await db.query(Note).filter(Note.id == id).first()
|
||||||
if not note:
|
if not note:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -139,13 +139,13 @@ class NoteTable:
|
||||||
|
|
||||||
note.updated_at = int(time.time_ns())
|
note.updated_at = int(time.time_ns())
|
||||||
|
|
||||||
db.commit()
|
await db.commit()
|
||||||
return NoteModel.model_validate(note) if note else None
|
return NoteModel.model_validate(note) if note else None
|
||||||
|
|
||||||
def delete_note_by_id(self, id: str):
|
async def delete_note_by_id(self, id: str):
|
||||||
async with get_db() as db:
|
async with get_db() as db:
|
||||||
db.query(Note).filter(Note.id == id).delete()
|
await db.query(Note).filter(Note.id == id).delete()
|
||||||
db.commit()
|
await db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -512,7 +512,7 @@ def get_sources_from_items(
|
||||||
|
|
||||||
elif item.get("type") == "note":
|
elif item.get("type") == "note":
|
||||||
# Note Attached
|
# Note Attached
|
||||||
note = Notes.get_note_by_id(item.get("id"))
|
note = await Notes.get_note_by_id(item.get("id"))
|
||||||
|
|
||||||
if note and (
|
if note and (
|
||||||
user.role == "admin"
|
user.role == "admin"
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ async def get_notes(request: Request, user=Depends(get_verified_user)):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for note in Notes.get_notes_by_user_id(user.id, "write")
|
for note in await Notes.get_notes_by_user_id(user.id, "write")
|
||||||
]
|
]
|
||||||
|
|
||||||
return notes
|
return notes
|
||||||
|
|
@ -76,7 +76,7 @@ async def get_note_list(request: Request, user=Depends(get_verified_user)):
|
||||||
|
|
||||||
notes = [
|
notes = [
|
||||||
NoteTitleIdResponse(**note.model_dump())
|
NoteTitleIdResponse(**note.model_dump())
|
||||||
for note in Notes.get_notes_by_user_id(user.id, "write")
|
for note in await Notes.get_notes_by_user_id(user.id, "write")
|
||||||
]
|
]
|
||||||
|
|
||||||
return notes
|
return notes
|
||||||
|
|
@ -101,7 +101,7 @@ async def create_new_note(
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
note = Notes.insert_new_note(form_data, user.id)
|
note = await Notes.insert_new_note(form_data, user.id)
|
||||||
return note
|
return note
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
@ -125,7 +125,7 @@ async def get_note_by_id(request: Request, id: str, user=Depends(get_verified_us
|
||||||
detail=ERROR_MESSAGES.UNAUTHORIZED,
|
detail=ERROR_MESSAGES.UNAUTHORIZED,
|
||||||
)
|
)
|
||||||
|
|
||||||
note = Notes.get_note_by_id(id)
|
note = await Notes.get_note_by_id(id)
|
||||||
if not note:
|
if not note:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
||||||
|
|
@ -163,7 +163,7 @@ async def update_note_by_id(
|
||||||
detail=ERROR_MESSAGES.UNAUTHORIZED,
|
detail=ERROR_MESSAGES.UNAUTHORIZED,
|
||||||
)
|
)
|
||||||
|
|
||||||
note = Notes.get_note_by_id(id)
|
note = await Notes.get_note_by_id(id)
|
||||||
if not note:
|
if not note:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
||||||
|
|
@ -180,7 +180,7 @@ async def update_note_by_id(
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
note = Notes.update_note_by_id(id, form_data)
|
note = await Notes.update_note_by_id(id, form_data)
|
||||||
await sio.emit(
|
await sio.emit(
|
||||||
"note-events",
|
"note-events",
|
||||||
note.model_dump(),
|
note.model_dump(),
|
||||||
|
|
@ -210,7 +210,7 @@ async def delete_note_by_id(request: Request, id: str, user=Depends(get_verified
|
||||||
detail=ERROR_MESSAGES.UNAUTHORIZED,
|
detail=ERROR_MESSAGES.UNAUTHORIZED,
|
||||||
)
|
)
|
||||||
|
|
||||||
note = Notes.get_note_by_id(id)
|
note = await Notes.get_note_by_id(id)
|
||||||
if not note:
|
if not note:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND
|
||||||
|
|
@ -227,7 +227,7 @@ async def delete_note_by_id(request: Request, id: str, user=Depends(get_verified
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
note = Notes.delete_note_by_id(id)
|
note = await Notes.delete_note_by_id(id)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ async def join_note(sid, data):
|
||||||
if not user:
|
if not user:
|
||||||
return
|
return
|
||||||
|
|
||||||
note = Notes.get_note_by_id(data["note_id"])
|
note = await Notes.get_note_by_id(data["note_id"])
|
||||||
if not note:
|
if not note:
|
||||||
log.error(f"Note {data['note_id']} not found for user {user.id}")
|
log.error(f"Note {data['note_id']} not found for user {user.id}")
|
||||||
return
|
return
|
||||||
|
|
@ -394,7 +394,7 @@ async def ydoc_document_join(sid, data):
|
||||||
|
|
||||||
if document_id.startswith("note:"):
|
if document_id.startswith("note:"):
|
||||||
note_id = document_id.split(":")[1]
|
note_id = document_id.split(":")[1]
|
||||||
note = Notes.get_note_by_id(note_id)
|
note = await Notes.get_note_by_id(note_id)
|
||||||
if not note:
|
if not note:
|
||||||
log.error(f"Note {note_id} not found")
|
log.error(f"Note {note_id} not found")
|
||||||
return
|
return
|
||||||
|
|
@ -464,7 +464,7 @@ async def ydoc_document_join(sid, data):
|
||||||
async def document_save_handler(document_id, data, user):
|
async def document_save_handler(document_id, data, user):
|
||||||
if document_id.startswith("note:"):
|
if document_id.startswith("note:"):
|
||||||
note_id = document_id.split(":")[1]
|
note_id = document_id.split(":")[1]
|
||||||
note = Notes.get_note_by_id(note_id)
|
note = await Notes.get_note_by_id(note_id)
|
||||||
if not note:
|
if not note:
|
||||||
log.error(f"Note {note_id} not found")
|
log.error(f"Note {note_id} not found")
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue