utils.py 1022 Bytes
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
from fastapi import APIRouter, UploadFile, File, BackgroundTasks
from fastapi import Depends, HTTPException, status
3
4
from starlette.responses import StreamingResponse, FileResponse

Timothy J. Baek's avatar
Timothy J. Baek committed
5
6
7

from pydantic import BaseModel

Timothy J. Baek's avatar
Timothy J. Baek committed
8
9

import markdown
Timothy J. Baek's avatar
Timothy J. Baek committed
10
11
import requests
import os
12
import aiohttp
Timothy J. Baek's avatar
Timothy J. Baek committed
13
import json
14

15
16

from utils.utils import get_admin_user
17
from utils.misc import calculate_sha256, get_gravatar_url
18

19
from config import OLLAMA_BASE_URLS, DATA_DIR, UPLOAD_DIR
Timothy J. Baek's avatar
Timothy J. Baek committed
20
21
from constants import ERROR_MESSAGES

Timothy J. Baek's avatar
Timothy J. Baek committed
22
23
24
25

router = APIRouter()


26
27
28
29
30
@router.get("/gravatar")
async def get_gravatar(
    email: str,
):
    return get_gravatar_url(email)
31
32


Timothy J. Baek's avatar
Timothy J. Baek committed
33
34
35
36
37
38
39
40
41
42
43
class MarkdownForm(BaseModel):
    md: str


@router.post("/markdown")
async def get_html_from_markdown(
    form_data: MarkdownForm,
):
    return {"html": markdown.markdown(form_data.md)}


44
45
46
47
48
49
50
51
@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",
    )