Restore broken repost call
This commit is contained in:
parent
c363a36367
commit
29a5b43ad1
38
README.org
38
README.org
|
@ -23,9 +23,17 @@ oxo --help
|
|||
│ --help Show this message and exit. │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
╭─ Commands ───────────────────────────────────────────────────────────────────╮
|
||||
│ files Upload one or more files. │
|
||||
│ repost Repost one or more urls. │
|
||||
│ shorten Shorten one or more urls. │
|
||||
│ delete Delete uploaded files if tokens are found on disk at │
|
||||
│ `token_cache_dir`. │
|
||||
│ files Upload one or more files. If one is provided by the 0x0 site used │
|
||||
│ on a successful upload, a management token will be printed to │
|
||||
│ stderr along with instructions on how to use it to delete or adjust │
|
||||
│ the expiration time on the uploaded file(s). If │
|
||||
│ `--token-cache-dir` is passed or `OXO_TOKEN_CACHE_DIR` is set, the │
|
||||
│ management token will also be cached as a json file in that │
|
||||
│ directory. The cache directory will be created on first use. │
|
||||
│ repost Repost one or more urls. │
|
||||
│ shorten Shorten one or more urls. │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
|
||||
#+end_example
|
||||
|
@ -49,11 +57,11 @@ oxo files --help
|
|||
│ * files FILES... [default: None] [required] │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
╭─ Options ────────────────────────────────────────────────────────────────────╮
|
||||
│ --base-url TEXT [env var: OXO_BASE_URL] │
|
||||
│ [default: https://0x0.st] │
|
||||
│ --expires INTEGER Expiration time, in hours or epoch │
|
||||
│ milliseconds │
|
||||
│ [default: None] │
|
||||
│ --base-url TEXT [env var: OXO_BASE_URL] │
|
||||
│ [default: https://0x0.st] │
|
||||
│ --token-cache-dir TEXT [env var: OXO_TOKEN_CACHE_DIR] │
|
||||
│ [default: None] │
|
||||
│ --help Show this message and exit. │
|
||||
|
@ -76,8 +84,14 @@ oxo repost --help
|
|||
│ * urls URLS... [default: None] [required] │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
╭─ Options ────────────────────────────────────────────────────────────────────╮
|
||||
│ --base-url TEXT [env var: OXO_BASE_URL] [default: https://0x0.st] │
|
||||
│ --help Show this message and exit. │
|
||||
│ --base-url TEXT [env var: OXO_BASE_URL] │
|
||||
│ [default: https://0x0.st] │
|
||||
│ --expires INTEGER Expiration time, in hours or epoch │
|
||||
│ milliseconds │
|
||||
│ [default: None] │
|
||||
│ --token-cache-dir TEXT [env var: OXO_TOKEN_CACHE_DIR] │
|
||||
│ [default: None] │
|
||||
│ --help Show this message and exit. │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
|
||||
#+end_example
|
||||
|
@ -97,8 +111,14 @@ oxo shorten --help
|
|||
│ * urls URLS... [default: None] [required] │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
╭─ Options ────────────────────────────────────────────────────────────────────╮
|
||||
│ --base-url TEXT [env var: OXO_BASE_URL] [default: https://0x0.st] │
|
||||
│ --help Show this message and exit. │
|
||||
│ --base-url TEXT [env var: OXO_BASE_URL] │
|
||||
│ [default: https://0x0.st] │
|
||||
│ --expires INTEGER Expiration time, in hours or epoch │
|
||||
│ milliseconds │
|
||||
│ [default: None] │
|
||||
│ --token-cache-dir TEXT [env var: OXO_TOKEN_CACHE_DIR] │
|
||||
│ [default: None] │
|
||||
│ --help Show this message and exit. │
|
||||
╰──────────────────────────────────────────────────────────────────────────────╯
|
||||
|
||||
#+end_example
|
||||
|
|
55
oxo.py
55
oxo.py
|
@ -73,6 +73,7 @@ def post_to(
|
|||
)
|
||||
else:
|
||||
res = client.post(base_url, data=d)
|
||||
remote_url = res.text.strip()
|
||||
res.raise_for_status()
|
||||
retval.append(remote_url)
|
||||
return " ".join(retval)
|
||||
|
@ -93,12 +94,34 @@ def post_files(
|
|||
)
|
||||
|
||||
|
||||
def post_repost(base_url, urls: t.List[str]):
|
||||
return post_to(base_url, data=({"url": u.strip()} for u in urls))
|
||||
def post_repost(
|
||||
base_url,
|
||||
urls: t.List[str],
|
||||
*,
|
||||
expires: t.Optional[int],
|
||||
token_dir: t.Optional[Path],
|
||||
):
|
||||
return post_to(
|
||||
base_url,
|
||||
data=({"url": u.strip()} for u in urls),
|
||||
expires=expires,
|
||||
token_dir=token_dir,
|
||||
)
|
||||
|
||||
|
||||
def post_shorten(base_url, urls: t.List[str]):
|
||||
return post_to(base_url, data=({"shorten": u.strip()} for u in urls))
|
||||
def post_shorten(
|
||||
base_url,
|
||||
urls: t.List[str],
|
||||
*,
|
||||
expires: t.Optional[int],
|
||||
token_dir: t.Optional[Path],
|
||||
):
|
||||
return post_to(
|
||||
base_url,
|
||||
data=({"shorten": u.strip()} for u in urls),
|
||||
expires=expires,
|
||||
token_dir=token_dir,
|
||||
)
|
||||
|
||||
|
||||
def version_callback(value: bool):
|
||||
|
@ -129,10 +152,10 @@ def files(
|
|||
files: t.List[Path] = typer.Argument(
|
||||
..., min=1, exists=True, file_okay=True, dir_okay=False, resolve_path=True
|
||||
),
|
||||
base_url: str = BASE_URL,
|
||||
expires: t.Optional[int] = typer.Option(
|
||||
None, help="Expiration time, in hours or epoch milliseconds"
|
||||
),
|
||||
base_url: str = BASE_URL,
|
||||
token_cache_dir: str = TOKEN_CACHE_DIR,
|
||||
):
|
||||
"""Upload one or more files. If one is provided by the 0x0 site used on a
|
||||
|
@ -160,13 +183,27 @@ def files(
|
|||
|
||||
|
||||
@app.command()
|
||||
def repost(urls: t.List[str] = typer.Argument(..., min=1), base_url=BASE_URL):
|
||||
def repost(
|
||||
urls: t.List[str] = typer.Argument(..., min=1),
|
||||
base_url=BASE_URL,
|
||||
expires: t.Optional[int] = typer.Option(
|
||||
None, help="Expiration time, in hours or epoch milliseconds"
|
||||
),
|
||||
token_cache_dir: str = TOKEN_CACHE_DIR,
|
||||
):
|
||||
"""Repost one or more urls."""
|
||||
typer.echo(post_repost(base_url, urls))
|
||||
typer.echo(post_repost(base_url, urls, expires, token_cache_dir))
|
||||
|
||||
|
||||
@app.command()
|
||||
def shorten(urls: t.List[str] = typer.Argument(..., min=1), base_url=BASE_URL):
|
||||
def shorten(
|
||||
urls: t.List[str] = typer.Argument(..., min=1),
|
||||
base_url=BASE_URL,
|
||||
expires: t.Optional[int] = typer.Option(
|
||||
None, help="Expiration time, in hours or epoch milliseconds"
|
||||
),
|
||||
token_cache_dir: str = TOKEN_CACHE_DIR,
|
||||
):
|
||||
"""Shorten one or more urls."""
|
||||
if base_url == BASE_URL.default:
|
||||
typer.secho(
|
||||
|
@ -175,7 +212,7 @@ def shorten(urls: t.List[str] = typer.Argument(..., min=1), base_url=BASE_URL):
|
|||
fg=typer.colors.RED,
|
||||
err=True,
|
||||
)
|
||||
typer.echo(post_shorten(base_url, urls))
|
||||
typer.echo(post_shorten(base_url, urls, expires, token_cache_dir))
|
||||
|
||||
|
||||
def did_confirm(token: TokenData, filename: Path) -> bool:
|
||||
|
|
Loading…
Reference in New Issue