diff options
| author | Jan Friedli | 2020-07-13 08:01:07 +0200 |
|---|---|---|
| committer | Jan Friedli | 2020-07-13 08:01:07 +0200 |
| commit | 6aa9fa7029ae15d0a18657fb9deccc3313aed9e1 (patch) | |
| tree | fd408ebc0874c059d8fab4f134bc147cd111305e | |
| parent | 7ba88acf09db93be0004fd901f98a6eb72b66006 (diff) | |
addded oas for upload endpoint
| -rw-r--r-- | main.py | 2 | ||||
| -rw-r--r-- | matweb/oas/upload.yml | 80 | ||||
| -rw-r--r-- | matweb/rest_api.py | 5 | ||||
| -rw-r--r-- | requirements.txt | 3 |
4 files changed, 88 insertions, 2 deletions
| @@ -5,6 +5,7 @@ from matweb import utils, rest_api, frontend | |||
| 5 | from flask import Flask | 5 | from flask import Flask |
| 6 | from flask_restful import Api | 6 | from flask_restful import Api |
| 7 | from flask_cors import CORS | 7 | from flask_cors import CORS |
| 8 | from flasgger import Swagger | ||
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | def create_app(test_config=None): | 11 | def create_app(test_config=None): |
| @@ -28,6 +29,7 @@ def create_app(test_config=None): | |||
| 28 | 29 | ||
| 29 | # Restful API hookup | 30 | # Restful API hookup |
| 30 | api = Api(app) | 31 | api = Api(app) |
| 32 | swagger = Swagger(app) | ||
| 31 | CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) | 33 | CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) |
| 32 | api.add_resource( | 34 | api.add_resource( |
| 33 | rest_api.APIUpload, | 35 | rest_api.APIUpload, |
diff --git a/matweb/oas/upload.yml b/matweb/oas/upload.yml new file mode 100644 index 0000000..c7a9bd7 --- /dev/null +++ b/matweb/oas/upload.yml | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | --- | ||
| 2 | tags: | ||
| 3 | - "File Upload (Metadata removal)" | ||
| 4 | summary: 'Upload a single file which will be cleaned from metadata' | ||
| 5 | consumes: | ||
| 6 | - "application/json" | ||
| 7 | produces: | ||
| 8 | - "application/json" | ||
| 9 | parameters: | ||
| 10 | - in: "body" | ||
| 11 | name: "body" | ||
| 12 | description: "The file that will be cleaned from metadata. Note that the file must be base64 encoded" | ||
| 13 | required: true | ||
| 14 | schema: | ||
| 15 | type: "object" | ||
| 16 | properties: | ||
| 17 | file_name: | ||
| 18 | type: "string" | ||
| 19 | example: 'my_example.jpg' | ||
| 20 | file: | ||
| 21 | type: "string" | ||
| 22 | example: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==' | ||
| 23 | |||
| 24 | responses: | ||
| 25 | 200: | ||
| 26 | description: "An object containing all info about the cleaned file" | ||
| 27 | schema: | ||
| 28 | $ref: '#/definitions/UploadResponse' | ||
| 29 | 400: | ||
| 30 | description: "Invalid input" | ||
| 31 | schema: | ||
| 32 | $ref: '#/definitions/ErrorResponse' | ||
| 33 | 415: | ||
| 34 | description: "Unsupported file type" | ||
| 35 | schema: | ||
| 36 | $ref: '#/definitions/ErrorResponse' | ||
| 37 | 500: | ||
| 38 | description: "Unable to clean the file" | ||
| 39 | schema: | ||
| 40 | $ref: '#/definitions/ErrorResponse' | ||
| 41 | |||
| 42 | definitions: | ||
| 43 | UploadResponse: | ||
| 44 | type: "object" | ||
| 45 | properties: | ||
| 46 | inactive_after_sec: | ||
| 47 | type: "integer" | ||
| 48 | format: "int64" | ||
| 49 | description: "Defines after how many seconds the download wont be available" | ||
| 50 | output_filename: | ||
| 51 | type: "string" | ||
| 52 | description: "The resulting filename after metadata removal" | ||
| 53 | mime: | ||
| 54 | type: "string" | ||
| 55 | description: "The mime type of the cleaned file" | ||
| 56 | key: | ||
| 57 | type: "string" | ||
| 58 | description: "A key used to guarantee file integrity" | ||
| 59 | secret: | ||
| 60 | type: "string" | ||
| 61 | description: "A secret used to guarantee file integrity" | ||
| 62 | meta: | ||
| 63 | type: "object" | ||
| 64 | description: "An object of the removed metadata where key indicates the metadata type" | ||
| 65 | items: | ||
| 66 | type: "string" | ||
| 67 | meta_after: | ||
| 68 | type: "object" | ||
| 69 | description: "An object of the remaining metadata where key indicates the metadata type" | ||
| 70 | items: | ||
| 71 | type: "string" | ||
| 72 | download_link: | ||
| 73 | type: "string" | ||
| 74 | description: "The link to download the cleaned file" | ||
| 75 | ErrorResponse: | ||
| 76 | type: "object" | ||
| 77 | properties: | ||
| 78 | message: | ||
| 79 | type: "string" | ||
| 80 | description: "A description of the error" \ No newline at end of file | ||
diff --git a/matweb/rest_api.py b/matweb/rest_api.py index 49334c0..4aeaa62 100644 --- a/matweb/rest_api.py +++ b/matweb/rest_api.py | |||
| @@ -9,6 +9,8 @@ from flask import after_this_request, send_from_directory | |||
| 9 | from flask_restful import Resource, reqparse, abort, request, url_for | 9 | from flask_restful import Resource, reqparse, abort, request, url_for |
| 10 | from cerberus import Validator | 10 | from cerberus import Validator |
| 11 | from werkzeug.datastructures import FileStorage | 11 | from werkzeug.datastructures import FileStorage |
| 12 | from flasgger import swag_from | ||
| 13 | |||
| 12 | 14 | ||
| 13 | from matweb import file_removal_scheduler, utils | 15 | from matweb import file_removal_scheduler, utils |
| 14 | 16 | ||
| @@ -17,7 +19,8 @@ class APIUpload(Resource): | |||
| 17 | 19 | ||
| 18 | def __init__(self, **kwargs): | 20 | def __init__(self, **kwargs): |
| 19 | self.upload_folder = kwargs['upload_folder'] | 21 | self.upload_folder = kwargs['upload_folder'] |
| 20 | 22 | ||
| 23 | @swag_from('./oas/upload.yml') | ||
| 21 | def post(self): | 24 | def post(self): |
| 22 | utils.check_upload_folder(self.upload_folder) | 25 | utils.check_upload_folder(self.upload_folder) |
| 23 | req_parser = reqparse.RequestParser() | 26 | req_parser = reqparse.RequestParser() |
diff --git a/requirements.txt b/requirements.txt index d57aeb6..72ad125 100644 --- a/requirements.txt +++ b/requirements.txt | |||
| @@ -7,4 +7,5 @@ Flask-RESTful==0.3.8 | |||
| 7 | Flask-Cors==3.0.8 | 7 | Flask-Cors==3.0.8 |
| 8 | Cerberus==1.3.2 | 8 | Cerberus==1.3.2 |
| 9 | Flask-Testing==0.8.0 | 9 | Flask-Testing==0.8.0 |
| 10 | blinker==1.4 \ No newline at end of file | 10 | blinker==1.4 |
| 11 | flasgger==0.9.4 \ No newline at end of file | ||
