mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-05-11 02:35:18 -04:00
addded oas for upload endpoint
This commit is contained in:
parent
7ba88acf09
commit
6aa9fa7029
4 changed files with 88 additions and 2 deletions
2
main.py
2
main.py
|
@ -5,6 +5,7 @@ from matweb import utils, rest_api, frontend
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_restful import Api
|
from flask_restful import Api
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
from flasgger import Swagger
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
|
@ -28,6 +29,7 @@ def create_app(test_config=None):
|
||||||
|
|
||||||
# Restful API hookup
|
# Restful API hookup
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
|
swagger = Swagger(app)
|
||||||
CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}})
|
CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}})
|
||||||
api.add_resource(
|
api.add_resource(
|
||||||
rest_api.APIUpload,
|
rest_api.APIUpload,
|
||||||
|
|
80
matweb/oas/upload.yml
Normal file
80
matweb/oas/upload.yml
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
---
|
||||||
|
tags:
|
||||||
|
- "File Upload (Metadata removal)"
|
||||||
|
summary: 'Upload a single file which will be cleaned from metadata'
|
||||||
|
consumes:
|
||||||
|
- "application/json"
|
||||||
|
produces:
|
||||||
|
- "application/json"
|
||||||
|
parameters:
|
||||||
|
- in: "body"
|
||||||
|
name: "body"
|
||||||
|
description: "The file that will be cleaned from metadata. Note that the file must be base64 encoded"
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
file_name:
|
||||||
|
type: "string"
|
||||||
|
example: 'my_example.jpg'
|
||||||
|
file:
|
||||||
|
type: "string"
|
||||||
|
example: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='
|
||||||
|
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "An object containing all info about the cleaned file"
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/UploadResponse'
|
||||||
|
400:
|
||||||
|
description: "Invalid input"
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ErrorResponse'
|
||||||
|
415:
|
||||||
|
description: "Unsupported file type"
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ErrorResponse'
|
||||||
|
500:
|
||||||
|
description: "Unable to clean the file"
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/ErrorResponse'
|
||||||
|
|
||||||
|
definitions:
|
||||||
|
UploadResponse:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
inactive_after_sec:
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
description: "Defines after how many seconds the download wont be available"
|
||||||
|
output_filename:
|
||||||
|
type: "string"
|
||||||
|
description: "The resulting filename after metadata removal"
|
||||||
|
mime:
|
||||||
|
type: "string"
|
||||||
|
description: "The mime type of the cleaned file"
|
||||||
|
key:
|
||||||
|
type: "string"
|
||||||
|
description: "A key used to guarantee file integrity"
|
||||||
|
secret:
|
||||||
|
type: "string"
|
||||||
|
description: "A secret used to guarantee file integrity"
|
||||||
|
meta:
|
||||||
|
type: "object"
|
||||||
|
description: "An object of the removed metadata where key indicates the metadata type"
|
||||||
|
items:
|
||||||
|
type: "string"
|
||||||
|
meta_after:
|
||||||
|
type: "object"
|
||||||
|
description: "An object of the remaining metadata where key indicates the metadata type"
|
||||||
|
items:
|
||||||
|
type: "string"
|
||||||
|
download_link:
|
||||||
|
type: "string"
|
||||||
|
description: "The link to download the cleaned file"
|
||||||
|
ErrorResponse:
|
||||||
|
type: "object"
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: "string"
|
||||||
|
description: "A description of the error"
|
|
@ -9,6 +9,8 @@ from flask import after_this_request, send_from_directory
|
||||||
from flask_restful import Resource, reqparse, abort, request, url_for
|
from flask_restful import Resource, reqparse, abort, request, url_for
|
||||||
from cerberus import Validator
|
from cerberus import Validator
|
||||||
from werkzeug.datastructures import FileStorage
|
from werkzeug.datastructures import FileStorage
|
||||||
|
from flasgger import swag_from
|
||||||
|
|
||||||
|
|
||||||
from matweb import file_removal_scheduler, utils
|
from matweb import file_removal_scheduler, utils
|
||||||
|
|
||||||
|
@ -18,6 +20,7 @@ class APIUpload(Resource):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.upload_folder = kwargs['upload_folder']
|
self.upload_folder = kwargs['upload_folder']
|
||||||
|
|
||||||
|
@swag_from('./oas/upload.yml')
|
||||||
def post(self):
|
def post(self):
|
||||||
utils.check_upload_folder(self.upload_folder)
|
utils.check_upload_folder(self.upload_folder)
|
||||||
req_parser = reqparse.RequestParser()
|
req_parser = reqparse.RequestParser()
|
||||||
|
|
|
@ -8,3 +8,4 @@ Flask-Cors==3.0.8
|
||||||
Cerberus==1.3.2
|
Cerberus==1.3.2
|
||||||
Flask-Testing==0.8.0
|
Flask-Testing==0.8.0
|
||||||
blinker==1.4
|
blinker==1.4
|
||||||
|
flasgger==0.9.4
|
Loading…
Add table
Add a link
Reference in a new issue