2023-12-23 23:38:52 +00:00
|
|
|
from fastapi import APIRouter, UploadFile, File, BackgroundTasks
|
|
|
|
from fastapi import Depends, HTTPException, status
|
2024-03-02 08:33:20 +00:00
|
|
|
from starlette.responses import StreamingResponse, FileResponse
|
|
|
|
|
2023-12-23 23:38:52 +00:00
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2024-04-04 03:35:32 +00:00
|
|
|
|
|
|
|
import markdown
|
2023-12-23 23:38:52 +00:00
|
|
|
import requests
|
|
|
|
import os
|
2023-12-24 07:40:14 +00:00
|
|
|
import aiohttp
|
2023-12-23 23:38:52 +00:00
|
|
|
import json
|
2023-12-24 07:40:14 +00:00
|
|
|
|
2024-03-02 08:33:20 +00:00
|
|
|
|
|
|
|
from utils.utils import get_admin_user
|
2024-01-27 05:38:33 +00:00
|
|
|
from utils.misc import calculate_sha256, get_gravatar_url
|
2023-12-24 07:40:14 +00:00
|
|
|
|
2024-03-06 19:44:00 +00:00
|
|
|
from config import OLLAMA_BASE_URLS, DATA_DIR, UPLOAD_DIR
|
2024-01-09 21:25:42 +00:00
|
|
|
from constants import ERROR_MESSAGES
|
|
|
|
|
2023-12-23 23:38:52 +00:00
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
2024-01-27 05:38:33 +00:00
|
|
|
@router.get("/gravatar")
|
|
|
|
async def get_gravatar(
|
|
|
|
email: str,
|
|
|
|
):
|
|
|
|
return get_gravatar_url(email)
|
2024-03-02 08:33:20 +00:00
|
|
|
|
|
|
|
|
2024-04-04 03:35:32 +00: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 08:33:20 +00: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",
|
|
|
|
)
|