always show url
This commit is contained in:
parent
e24b2d48ac
commit
600a3824a6
|
@ -2,18 +2,27 @@
|
|||
import hashlib
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
from typing import Literal
|
||||
|
||||
import pyperclip
|
||||
import requests
|
||||
import typer
|
||||
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor
|
||||
from rich.console import Console
|
||||
from rich.progress import (BarColumn, DownloadColumn, Progress, TextColumn,
|
||||
TimeRemainingColumn, TransferSpeedColumn)
|
||||
|
||||
HIKARI_BASE = "https://hikari.butaishoujo.moe"
|
||||
HIKARI_URL = f"{HIKARI_BASE}/upload"
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
@dataclass
|
||||
class UploadResponse:
|
||||
status: Literal["exists"] | Literal["uploaded"]
|
||||
url: str
|
||||
|
||||
|
||||
def check_hash(filename: str, file: Path):
|
||||
h = hashlib.sha256()
|
||||
|
@ -32,14 +41,21 @@ def check_hash(filename: str, file: Path):
|
|||
return
|
||||
|
||||
req.raise_for_status()
|
||||
return req.json()
|
||||
return UploadResponse(**req.json())
|
||||
|
||||
|
||||
def output(copy: bool, resp: dict):
|
||||
def output(copy: bool, resp: UploadResponse):
|
||||
if copy:
|
||||
pyperclip.copy(resp['url'])
|
||||
pyperclip.copy(resp.url)
|
||||
action = "Copied"
|
||||
elif resp.status == "exists":
|
||||
action = "Found"
|
||||
elif resp.status == "uploaded":
|
||||
action = "Uploaded"
|
||||
else:
|
||||
pprint(resp)
|
||||
action = ""
|
||||
|
||||
console.print(action, resp.url, style="bold green")
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
Loading…
Reference in a new issue