add collection name parameter to transbeam-cli

This commit is contained in:
xenofem 2022-05-29 11:12:43 -04:00
parent 4914864887
commit 1a583983ee

View file

@ -24,7 +24,7 @@ def file_loader(files):
file_progress.update(len(data))
yield data
async def send(paths, uri, password, lifetime):
async def send(paths, uri, password, lifetime, collection_name=None):
paths = [path for path in paths if path.is_file()]
fileMetadata = [
{
@ -38,6 +38,9 @@ async def send(paths, uri, password, lifetime):
"lifetime": lifetime,
"password": password,
}
if collection_name is not None:
manifest["collection_name"] = collection_name
async with connect(uri) as ws:
await ws.send(json.dumps(manifest))
resp = json.loads(await ws.recv())
@ -56,11 +59,15 @@ async def send(paths, uri, password, lifetime):
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("-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")
async def main():
args = parser.parse_args()
if len(args.files) == 1 and args.collection_name is not None:
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)
await send(args.files, args.uri, password, args.lifetime, args.collection_name)
asyncio.run(main())