main
 1#!/usr/bin/env python
 2# -*- coding: utf-8 -*-
 3import io
 4from pathlib import Path
 5
 6import anyio
 7from loguru import logger
 8
 9from networking import hx_req
10from utils import guess_mime
11
12
13async def upload_uguu(path: str | Path) -> str:
14    """Upload to https://uguu.se, return the download url."""
15    path = Path(path).expanduser().resolve()
16    if not path.is_file():
17        return ""
18    api = "https://uguu.se/upload"
19    logger.debug(f"Uploading {path.name} to: https://Uguu.se")
20    async with await anyio.open_file(path, "rb") as f:
21        content = await f.read()
22        res = await hx_req(api, method="POST", files={"files[]": (path.name, io.BytesIO(content), guess_mime(path))}, check_kv={"success": True}, check_keys=["files.0.url"])
23    url = res["files"][0]["url"]
24    logger.success(f"Uploaded {path.name} to {url}")
25    return url