summaryrefslogtreecommitdiff
path: root/foreign/client_handling/download.py
blob: d88f3f5fc6944364cb3ccab84fe2b683e675cd00 (plain)
1
2
3
4
5
6
7
8
9
import os


def download(filename, max_file_size):
  if (os.path.getsize(filename) / 1024 / 1024) > max_file_size:
    return {'message': f'File exceeding maximum size of {max_file_size}MB', 'download': None, 'text_mode': 'danger'}

  with open(filename, 'rb') as f:
    return {'message': f'{filename} succesfully downloaded', 'download': f.read(), 'text_mode': 'success'}