From 97ea9d10281365f44464314904af0450cbe9a691 Mon Sep 17 00:00:00 2001 From: Gnarwhal Date: Thu, 1 Aug 2024 17:56:06 +0000 Subject: [PATCH] Convert ids to base 62 (shorter url) --- src/sshare/cli.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sshare/cli.py b/src/sshare/cli.py index 135a263..87af8be 100644 --- a/src/sshare/cli.py +++ b/src/sshare/cli.py @@ -71,6 +71,23 @@ class Config: with open(config_path, mode="rb") as file: return tomllib.load(file) + +def rebase(number): + if number == 0: + return "0" + rebased = "" + while number != 0: + digit = number % 62 + if digit < 10: + rebased = chr(digit + 48) + rebased + elif digit < 36: + rebased = chr(digit + 87) + rebased + else: + rebased = chr(digit + 29) + rebased + number = int(number / 62) + return rebased + + def main(): arguments = parse_arguments() @@ -101,7 +118,7 @@ def main(): print("Error: must specify one of -f FILE, -l, -p") sys.exit(1) - target_id = time.time_ns() + target_id = rebase(time.time_ns()) target_file_name = f"{target_id}{target_file_extension}" target_file = f"{config.ssh_path}/{target_file_name}" target_destination = f"{config.ssh_user}@{config.host_name}"