summaryrefslogtreecommitdiff
path: root/domestic/session/server_handling/download.py
diff options
context:
space:
mode:
Diffstat (limited to 'domestic/session/server_handling/download.py')
-rw-r--r--domestic/session/server_handling/download.py35
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