Improve token flow
This commit is contained in:
parent
3eead1a769
commit
fb54971d14
40
oxo.py
40
oxo.py
|
@ -56,26 +56,32 @@ def post_to(
|
|||
for d in data:
|
||||
if isinstance(d.get("file"), io.BufferedReader):
|
||||
res = client.post(base_url, files=d, data=data_dict)
|
||||
token = res.headers.get("x-token")
|
||||
remote_url = res.text.strip()
|
||||
if token:
|
||||
token_data = TokenData(
|
||||
token=token,
|
||||
oxo_url=remote_url,
|
||||
)
|
||||
err_console.print(f"To remove post, {token_data.curl_rm}")
|
||||
err_console.print(
|
||||
f"To update expiration date, {token_data.curl_expiry}"
|
||||
)
|
||||
if token_dir:
|
||||
fname = Path(d.get("file").name).name
|
||||
token_dir.joinpath(f"{fname}.token").write_text(
|
||||
json.dumps(asdict(token_data))
|
||||
)
|
||||
else:
|
||||
res = client.post(base_url, data={**d, **data_dict})
|
||||
remote_url = res.text.strip()
|
||||
res.raise_for_status()
|
||||
remote_url = res.text.strip()
|
||||
token = res.headers.get("x-token")
|
||||
if token:
|
||||
token_data = TokenData(
|
||||
token=token,
|
||||
oxo_url=remote_url,
|
||||
)
|
||||
err_console.print(f"To remove post, {token_data.curl_rm}")
|
||||
err_console.print(
|
||||
f"To update expiration date, {token_data.curl_expiry}"
|
||||
)
|
||||
if token_dir:
|
||||
# todo rewrite when drop 3.7
|
||||
if d.get("url"):
|
||||
fname = d.get("url").rpartition("/")[2]
|
||||
elif d.get("file").name:
|
||||
fname = Path(d.get("file").name).name
|
||||
else:
|
||||
raise ValueError(f"{d}")
|
||||
token_dir.joinpath(f"{fname}.token").write_text(
|
||||
json.dumps(asdict(token_data))
|
||||
)
|
||||
|
||||
retval.append(remote_url)
|
||||
return " ".join(retval)
|
||||
|
||||
|
|
Loading…
Reference in New Issue