2023-12-24 00:38:52 +01:00
|
|
|
from fastapi import APIRouter, UploadFile, File, BackgroundTasks
|
|
|
|
from fastapi import Depends, HTTPException, status
|
2024-03-02 09:33:20 +01:00
|
|
|
from starlette.responses import StreamingResponse, FileResponse
|
|
|
|
|
2023-12-24 00:38:52 +01:00
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2024-04-04 05:35:32 +02:00
|
|
|
|
|
|
|
import markdown
|
2023-12-24 00:38:52 +01:00
|
|
|
import requests
|
|
|
|
import os
|
2023-12-24 08:40:14 +01:00
|
|
|
import aiohttp
|
2023-12-24 00:38:52 +01:00
|
|
|
import json
|
2023-12-24 08:40:14 +01:00
|
|
|
|
2024-03-02 09:33:20 +01:00
|
|
|
|
|
|
|
from utils.utils import get_admin_user
|
2024-01-27 06:38:33 +01:00
|
|
|
from utils.misc import calculate_sha256, get_gravatar_url
|
2023-12-24 08:40:14 +01:00
|
|
|
|
2024-03-06 20:44:00 +01:00
|
|
|
from config import OLLAMA_BASE_URLS, DATA_DIR, UPLOAD_DIR
|
2024-01-09 22:25:42 +01:00
|
|
|
from constants import ERROR_MESSAGES
|
|
|
|
|
2023-12-24 00:38:52 +01:00
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
2024-01-27 06:38:33 +01:00
|
|
|
@router.get("/gravatar")
|
|
|
|
async def get_gravatar(
|
|
|
|
email: str,
|
|
|
|
):
|
|
|
|
return get_gravatar_url(email)
|
2024-03-02 09:33:20 +01:00
|
|
|
|
|
|
|
|
2024-04-04 05:35:32 +02:00
|
|
|
class MarkdownForm(BaseModel):
|
|
|
|
md: str
|
|
|
|
|
|
|
|
|
|
|
|
@router.post("/markdown")
|
|
|
|
async def get_html_from_markdown(
|
|
|
|
form_data: MarkdownForm,
|
|
|
|
):
|
|
|
|
return {"html": markdown.markdown(form_data.md)}
|
|
|
|
|
|
|
|
|
2024-03-02 09:33:20 +01:00
|
|
|
@router.get("/db/download")
|
|
|
|
async def download_db(user=Depends(get_admin_user)):
|
|
|
|
|
|
|
|
return FileResponse(
|
|
|
|
f"{DATA_DIR}/webui.db",
|
|
|
|
media_type="application/octet-stream",
|
|
|
|
filename="webui.db",
|
|
|
|
)
|