import os

from flask import send_from_directory
from flask.views import View

from pycs.database.File import File


class GetFile(View):
    """
    returns binary file data
    """
    # pylint: disable=arguments-differ
    methods = ['GET']

    def dispatch_request(self, file_id: int):
        file = File.get_or_404(file_id)

        abs_file_path = file.absolute_path

        # return data
        file_directory, file_name = os.path.split(abs_file_path)
        return send_from_directory(file_directory, file_name)
