diff --git a/hikari/__main__.py b/hikari/__main__.py new file mode 100644 index 0000000..4382a22 --- /dev/null +++ b/hikari/__main__.py @@ -0,0 +1,3 @@ +from .hikari import main + +main() diff --git a/hikari/hikari.py b/hikari/hikari.py index 191af13..007f5af 100755 --- a/hikari/hikari.py +++ b/hikari/hikari.py @@ -7,7 +7,9 @@ import pyperclip import requests import typer -HIKARI_URL = "https://hikari.butaishoujo.moe/upload" + +HIKARI_BASE = "https://hikari.butaishoujo.moe" +HIKARI_URL = f"{HIKARI_BASE}/upload" def upload(file: Path, @@ -22,6 +24,10 @@ def upload(file: Path, copy: bool = typer.Option( False, "--copy", "-c", help="Copy file URL to clipboard." + ), + hash: bool = typer.Option( + False, "--hash", "-h", + help="Hash file before uploading to avoid having to send the whole file twice." )): if copy: @@ -32,9 +38,21 @@ def upload(file: Path, elif filename is None: filename = file.name + if hash: + h = hashlib.sha256() + with file.open('br') as f: + while buf := f.read(1024**2): + h.update(buf) + + h.hexdigest()[:8] + url = f"{HIKARI_URL}/{h.hexdigest()[:8]}" + else: + url = HIKARI_URL + with file.open('br') as f: files = {'file': (filename, f)} - with requests.post(HIKARI_URL, files=files, stream=True) as req: + + with requests.post(url, files=files, stream=True) as req: resp = req.raw.read() data = orjson.loads(resp) diff --git a/setup.py b/setup.py index 20ddc0f..4508321 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ with req.open() as f: setup( name='hikari', - version='1.0', + version='1.1', packages=find_packages(), include_package_data=True, install_requires=install_requires,