123456789101112131415161718192021222324252627282930313233343536 |
- from eventlet import tpool
- from flask import abort
- from flask import send_from_directory
- from flask.views import View
- from pycs.database.File import File
- from pycs.util import file_ops
- class GetResizedFile(View):
- """
- returns binary file after resizing
- """
- # pylint: disable=arguments-differ
- methods = ['GET']
- def dispatch_request(self, file_id: int, resolution: str):
- # get file from database
- file = File.get_or_404(file_id)
- project = file.project
- if not os.path.exists(file.absolute_path):
- abort(404, "File not found!")
- # extract desired resolution
- resolution = re.split(r'[^0-9]', resolution)
- max_width = int(resolution[0])
- max_height = int(resolution[1]) if len(resolution) > 1 else 2 ** 24
- # send data
- file_directory, file_name = tpool.execute(file_ops.resize_file,
- file, file.project.root_folder,
- max_width, max_height)
- return send_from_directory(file_directory, file_name)
|