Skip to content

Commit 31a0af6

Browse files
committed
Added short_uid param in utils.get_file_download_url
1 parent 8cbecc1 commit 31a0af6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/imio/esign/tests/test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ def test_get_file_download_url(self):
325325
self.assertTrue(result2[0].startswith("https://downloads.files.com/"))
326326
self.assertEqual(shortuid_decode_id(result2[1], separator="-"), uid2) # correctly decoded
327327

328+
# Test with pre-computed short_uid parameter
329+
result3 = get_file_download_url(None, short_uid="MyCustom-Short-UID")
330+
self.assertEqual(result3, ("https://downloads.files.com/MyCustom-Short-UID", "MyCustom-Short-UID"))
331+
328332
def test_get_max_download_date(self):
329333
annex = self.folders[0]
330334
mod_date = annex.modified().asdatetime().date()

src/imio/esign/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,23 @@ def remove_session(session_id):
384384
# logger.info("Session %s removed", session_id)
385385

386386

387-
def get_file_download_url(uid, separator="-", block_size=5, root_url=None):
387+
def get_file_download_url(uid, separator="-", block_size=5, root_url=None, short_uid=None):
388388
"""Get the file download URL for a given file UID.
389389
390390
:param uid: file UID
391391
:param separator: separator used in short UID encoding
392392
:param block_size: block size used in short UID encoding
393393
:param root_url: root URL. If not provided, the settings value is used
394+
:param short_uid: take this short UID instead of computing it
394395
:return: file download URL, short_uid
395396
"""
396397
if not root_url:
397398
root_url = get_registry_file_url()
398399

399400
if not root_url:
400401
raise Exception("No root URL provided for file download url.")
401-
short_uid = shortuid_encode_id(uid, separator=separator, block_size=block_size)
402+
if not short_uid:
403+
short_uid = shortuid_encode_id(uid, separator=separator, block_size=block_size)
402404
return "{}/{}".format(root_url.strip('/'), short_uid), short_uid
403405

404406

0 commit comments

Comments
 (0)