|
12 | 12 | from sqlalchemy.schema import MetaData |
13 | 13 | from flask_sqlalchemy import SQLAlchemy |
14 | 14 | from flask_marshmallow import Marshmallow |
15 | | -from flask import json, jsonify, request, abort, current_app, Flask, Request, Response |
| 15 | +from flask import ( |
| 16 | + json, |
| 17 | + jsonify, |
| 18 | + make_response, |
| 19 | + request, |
| 20 | + abort, |
| 21 | + current_app, |
| 22 | + Flask, |
| 23 | + Request, |
| 24 | + Response, |
| 25 | +) |
16 | 26 | from flask_login import current_user, LoginManager |
17 | 27 | from flask_wtf.csrf import generate_csrf, CSRFProtect |
18 | 28 | from flask_migrate import Migrate |
|
25 | 35 | import time |
26 | 36 | import traceback |
27 | 37 | from werkzeug.exceptions import HTTPException |
28 | | -from typing import List, Dict, Optional |
| 38 | +from typing import List, Dict, Optional, Tuple |
29 | 39 |
|
30 | 40 | from .sync.utils import get_blacklisted_dirs, get_blacklisted_files |
31 | 41 | from .config import Configuration |
@@ -347,6 +357,16 @@ def ping(): # pylint: disable=W0612 |
347 | 357 | ) |
348 | 358 | return status, 200 |
349 | 359 |
|
| 360 | + # reading raw input stream not supported in connexion so far |
| 361 | + # https://github.com/zalando/connexion/issues/592 |
| 362 | + # and as workaround we use custom Flask endpoint in create_app function |
| 363 | + @app.route("/v2/projects/<id>/chunks", methods=["POST"]) |
| 364 | + @auth_required |
| 365 | + def upload_chunk_v2(id: str): |
| 366 | + from .sync import public_api_v2_controller |
| 367 | + |
| 368 | + return public_api_v2_controller.upload_chunk(id) |
| 369 | + |
350 | 370 | # reading raw input stream not supported in connexion so far |
351 | 371 | # https://github.com/zalando/connexion/issues/592 |
352 | 372 | # and as workaround we use custom Flask endpoint in create_app function |
@@ -485,6 +505,12 @@ class ResponseError: |
485 | 505 | def to_dict(self) -> Dict: |
486 | 506 | return dict(code=self.code, detail=self.detail + f" ({self.code})") |
487 | 507 |
|
| 508 | + def response(self, status_code: int) -> Tuple[Response, int]: |
| 509 | + """Returns a custom error response with the given code.""" |
| 510 | + response = make_response(jsonify(self.to_dict()), status_code) |
| 511 | + response.headers["Content-Type"] = "application/problem+json" |
| 512 | + return response, status_code |
| 513 | + |
488 | 514 |
|
489 | 515 | def whitespace_filter(obj): |
490 | 516 | return obj.strip() if isinstance(obj, str) else obj |
|
0 commit comments