diff options
author | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
---|---|---|
committer | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
commit | 20dbeb2f38684c65ff0a4b99012c161295708e88 (patch) | |
tree | a5b8445f55da2fbbb92443b68e9d7354a290c598 /domestic/session/server_handling/download.py |
Diffstat (limited to 'domestic/session/server_handling/download.py')
-rw-r--r-- | domestic/session/server_handling/download.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/domestic/session/server_handling/download.py b/domestic/session/server_handling/download.py new file mode 100644 index 0000000..a51e394 --- /dev/null +++ b/domestic/session/server_handling/download.py @@ -0,0 +1,35 @@ +import os + +from domestic.parse.error_exception_handling import * +from domestic.session.session_message import * +from domestic.utility.status_message import * +from domestic.make.make_directories import * +from domestic.global_state import * + + +@error_exception_handling +def download(message): + assert message['file'] + + filename = validate_dict_key(message, 'file') + execute = validate_dict_key(message, 'execute') + + username = state['session']['username'] + make_directories([username, f'{username}/downloads']) + root = f'{state["root"]}/{username}/downloads/{filename}' + + message['max_file_size'] = state['settings']['max-file-size'] + if execute: + del message['execute'] + + data = session_message(message, False, loading_text='downloading file...') + download = validate_dict_key(data, 'download', False) + + if download: + with open(root, 'wb') as f: + f.write(download) + + if execute: + os.startfile(root) + + status_message(data['message'], data['text_mode'])
\ No newline at end of file |