summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Friedli2020-07-13 08:01:07 +0200
committerJan Friedli2020-07-13 08:01:07 +0200
commit6aa9fa7029ae15d0a18657fb9deccc3313aed9e1 (patch)
treefd408ebc0874c059d8fab4f134bc147cd111305e
parent7ba88acf09db93be0004fd901f98a6eb72b66006 (diff)
addded oas for upload endpoint
Diffstat (limited to '')
-rw-r--r--main.py2
-rw-r--r--matweb/oas/upload.yml80
-rw-r--r--matweb/rest_api.py5
-rw-r--r--requirements.txt3
4 files changed, 88 insertions, 2 deletions
diff --git a/main.py b/main.py
index 5c7f8e7..5e47531 100644
--- a/main.py
+++ b/main.py
@@ -5,6 +5,7 @@ from matweb import utils, rest_api, frontend
5from flask import Flask 5from flask import Flask
6from flask_restful import Api 6from flask_restful import Api
7from flask_cors import CORS 7from flask_cors import CORS
8from flasgger import Swagger
8 9
9 10
10def create_app(test_config=None): 11def 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---
2tags:
3 - "File Upload (Metadata removal)"
4summary: 'Upload a single file which will be cleaned from metadata'
5consumes:
6 - "application/json"
7produces:
8 - "application/json"
9parameters:
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
24responses:
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
42definitions:
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
9from flask_restful import Resource, reqparse, abort, request, url_for 9from flask_restful import Resource, reqparse, abort, request, url_for
10from cerberus import Validator 10from cerberus import Validator
11from werkzeug.datastructures import FileStorage 11from werkzeug.datastructures import FileStorage
12from flasgger import swag_from
13
12 14
13from matweb import file_removal_scheduler, utils 15from 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
7Flask-Cors==3.0.8 7Flask-Cors==3.0.8
8Cerberus==1.3.2 8Cerberus==1.3.2
9Flask-Testing==0.8.0 9Flask-Testing==0.8.0
10blinker==1.4 \ No newline at end of file 10blinker==1.4
11flasgger==0.9.4 \ No newline at end of file