cli: display the full download link, not just the download code

main
xenofem 2023-06-11 05:57:17 -04:00
parent d80180956f
commit 3bbea6dc9c
1 changed files with 5 additions and 5 deletions

View File

@ -24,7 +24,7 @@ def file_loader(files):
file_progress.update(len(data))
yield data
async def send(paths, uri, password, lifetime, collection_name=None):
async def send(paths, host, password, lifetime, collection_name=None):
paths = [path for path in paths if path.is_file()]
fileMetadata = [
{
@ -41,13 +41,13 @@ async def send(paths, uri, password, lifetime, collection_name=None):
if collection_name is not None:
manifest["collection_name"] = collection_name
async with connect(uri) as ws:
async with connect("wss://{}/upload".format(host)) as ws:
await ws.send(json.dumps(manifest))
resp = json.loads(await ws.recv())
if resp["type"] != "ready":
print("unexpected response: {}".format(resp))
exit(1)
print("Download code: {}".format(resp["code"]))
print("Download: https://{}/download?code={}".format(host, resp["code"]))
loader = file_loader([(paths[i], fileMetadata[i]["size"]) for i in range(len(paths))])
for data in loader:
await ws.send(data)
@ -58,7 +58,7 @@ async def send(paths, uri, password, lifetime, collection_name=None):
parser = argparse.ArgumentParser(description="Upload files to transbeam")
parser.add_argument("-l", "--lifetime", type=int, default=7, help="Lifetime in days for files (default 7)")
parser.add_argument("-u", "--uri", type=str, default="wss://transbeam.link/upload", help="Websocket URI for transbeam (default wss://transbeam.link/upload)")
parser.add_argument("-H", "--host", type=str, default="transbeam.link", help="transbeam host (default transbeam.link)")
parser.add_argument("-n", "--collection-name", type=str, help="Name for a collection of multiple files")
parser.add_argument("files", type=pathlib.Path, nargs="+", help="Files to upload")
@ -68,6 +68,6 @@ async def main():
print("--collection-name is only applicable when multiple files are being uploaded")
exit(1)
password = getpass.getpass()
await send(args.files, args.uri, password, args.lifetime, args.collection_name)
await send(args.files, args.host, password, args.lifetime, args.collection_name)
asyncio.run(main())