# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTBadRequest(RESTResponse):
#     status = 400
#     detail = "Bad request"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTInternalServerError(RESTResponse):
#     status = 500
#     detail = (
#         "The server encountered an unexpected condition that prevented it "
#         "from fulfilling the request"
#     )
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTNotFound(RESTBadRequest):
#     status = 404
#     detail = "Resource not found"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTSuccess(RESTResponse):
#     status = 200
# 
# Path: il2fb/ds/airbridge/api/http/security.py
# def with_authorization(view):
# 
#     @functools.wraps(view)
#     async def wrapper(arg0, *args, **kwargs):
#         request = arg0 if isinstance(arg0, web.Request) else arg0.request
#         backend = request.app.get('auth_backend')
# 
#         if backend and not backend.authorize(request):
#             raise web.HTTPForbidden()
# 
#         return (await view(arg0, *args, **kwargs))
# 
#     return wrapper


import logging
import re
from stat import S_ISREG, S_ISDIR
from aiohttp.web import FileResponse
from il2fb.ds.airbridge.api.http.responses.rest import RESTBadRequest
from il2fb.ds.airbridge.api.http.responses.rest import RESTInternalServerError
from il2fb.ds.airbridge.api.http.responses.rest import RESTNotFound
from il2fb.ds.airbridge.api.http.responses.rest import RESTSuccess
from il2fb.ds.airbridge.api.http.security import with_authorization
        else:
            return RESTSuccess(payload=result, pretty=pretty)
    else:
        return FileResponse(absolute_path)


@with_authorization
async def upload_mission(request):
    pretty = 'pretty' in request.query
    root_dir = request.app['dedicated_server'].missions_dir

    try:
        relative_dir = request.match_info.get('dir_path', '')
        absolute_dir = (root_dir / relative_dir)
    except Exception:
        LOG.exception(
            "HTTP failed to upload mission: incorrect input data"
        )
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    if not absolute_dir.exists():
        absolute_dir.mkdir(parents=True, exist_ok=True)

    try:
        reader = await request.multipart()
    except Exception:
        LOG.exception("HTTP failed to upload mission: incorrect input data")

# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTBadRequest(RESTResponse):
#     status = 400
#     detail = "Bad request"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTInternalServerError(RESTResponse):
#     status = 500
#     detail = (
#         "The server encountered an unexpected condition that prevented it "
#         "from fulfilling the request"
#     )
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTNotFound(RESTBadRequest):
#     status = 404
#     detail = "Resource not found"
# 
# Path: il2fb/ds/airbridge/api/http/responses/rest.py
# class RESTSuccess(RESTResponse):
#     status = 200
# 
# Path: il2fb/ds/airbridge/api/http/security.py
# def with_authorization(view):
# 
#     @functools.wraps(view)
#     async def wrapper(arg0, *args, **kwargs):
#         request = arg0 if isinstance(arg0, web.Request) else arg0.request
#         backend = request.app.get('auth_backend')
# 
#         if backend and not backend.authorize(request):
#             raise web.HTTPForbidden()
# 
#         return (await view(arg0, *args, **kwargs))
# 
#     return wrapper


# Path: il2fb/ds/airbridge/api/http/views/missions.py
import logging
import re
from stat import S_ISREG, S_ISDIR
from aiohttp.web import FileResponse
from il2fb.ds.airbridge.api.http.responses.rest import RESTBadRequest
from il2fb.ds.airbridge.api.http.responses.rest import RESTInternalServerError
from il2fb.ds.airbridge.api.http.responses.rest import RESTNotFound
from il2fb.ds.airbridge.api.http.responses.rest import RESTSuccess
from il2fb.ds.airbridge.api.http.security import with_authorization

        else:
            return RESTSuccess(payload=result, pretty=pretty)
    else:
        return FileResponse(absolute_path)


@with_authorization
async def upload_mission(request):
    pretty = 'pretty' in request.query
    root_dir = request.app['dedicated_server'].missions_dir

    try:
        relative_dir = request.match_info.get('dir_path', '')
        absolute_dir = (root_dir / relative_dir)
    except Exception:
        LOG.exception(
            "HTTP failed to upload mission: incorrect input data"
        )
        return RESTBadRequest(
            detail="incorrect input data",
            pretty=pretty,
        )

    if not absolute_dir.exists():
        absolute_dir.mkdir(parents=True, exist_ok=True)

    try:
        reader = await request.multipart()
    except Exception:
        LOG.exception("HTTP failed to upload mission: incorrect input data")

        return RESTBadRequest(