This commit is contained in:
		@@ -4,3 +4,5 @@ marshmallow
 | 
				
			|||||||
Flask
 | 
					Flask
 | 
				
			||||||
Flask-RESTful
 | 
					Flask-RESTful
 | 
				
			||||||
requests
 | 
					requests
 | 
				
			||||||
 | 
					werkzeug
 | 
				
			||||||
 | 
					filetype
 | 
				
			||||||
@@ -13,7 +13,7 @@ Main Flask RESTful API
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__author__ = "@tormakris"
 | 
					__author__ = "@tormakris"
 | 
				
			||||||
__copyright__ = "Copyright 2019, KSZK"
 | 
					__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
				
			||||||
__module_name__ = "app"
 | 
					__module_name__ = "app"
 | 
				
			||||||
__version__text__ = "1"
 | 
					__version__text__ = "1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ Main Flask RESTful API
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__author__ = "@tormakris"
 | 
					__author__ = "@tormakris"
 | 
				
			||||||
__copyright__ = "Copyright 2019, KSZK"
 | 
					__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
				
			||||||
__module_name__ = "app"
 | 
					__module_name__ = "app"
 | 
				
			||||||
__version__text__ = "1"
 | 
					__version__text__ = "1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,10 @@
 | 
				
			|||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import os
 | 
					import json
 | 
				
			||||||
from flask import request
 | 
					from flask import request
 | 
				
			||||||
from flask_restful import Resource
 | 
					from flask_restful import Resource, reqparse
 | 
				
			||||||
 | 
					from werkzeug.datastructures import FileStorage
 | 
				
			||||||
 | 
					import filetype
 | 
				
			||||||
from schemas import *
 | 
					from schemas import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
@@ -10,7 +12,7 @@ Flask Restful endpoints
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__author__ = '@tormakris'
 | 
					__author__ = '@tormakris'
 | 
				
			||||||
__copyright__ = "Copyright 2019, KSZK"
 | 
					__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
				
			||||||
__module_name__ = "endpoints"
 | 
					__module_name__ = "endpoints"
 | 
				
			||||||
__version__text__ = "1"
 | 
					__version__text__ = "1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,5 +24,33 @@ class SampleResource(Resource):
 | 
				
			|||||||
    Sample endpoint
 | 
					    Sample endpoint
 | 
				
			||||||
    See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
 | 
					    See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def post(self):
 | 
					    def post(self):
 | 
				
			||||||
        pass
 | 
					        """
 | 
				
			||||||
 | 
					        Post request send to the endpoint
 | 
				
			||||||
 | 
					        :return:
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        parse = reqparse.RequestParser()
 | 
				
			||||||
 | 
					        parse.add_argument('soundFile', type=FileStorage, location='soundFile')
 | 
				
			||||||
 | 
					        parse.add_argument('description', type=str, location='description')
 | 
				
			||||||
 | 
					        args = parse.parse_args()
 | 
				
			||||||
 | 
					        soundFile = args['soundFile']
 | 
				
			||||||
 | 
					        description = args['description']
 | 
				
			||||||
 | 
					        kind = filetype.guess(soundFile)
 | 
				
			||||||
 | 
					        if kind.mime != 'wav':
 | 
				
			||||||
 | 
					            LOGGER.error(
 | 
				
			||||||
 | 
					                "Input file was not WAV. Recieved metadata: {}",
 | 
				
			||||||
 | 
					                description)
 | 
				
			||||||
 | 
					            return {'status': 'error', 'message': 'Input file not WAV.'}, 415
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            desc = json.loads(description)
 | 
				
			||||||
 | 
					        except Exception as e:
 | 
				
			||||||
 | 
					            LOGGER.exception(e)
 | 
				
			||||||
 | 
					            return {'status': 'error',
 | 
				
			||||||
 | 
					                    'message': 'Input JSON could not be parsed'}, 400
 | 
				
			||||||
 | 
					        validate_errors = InputSchema().validate(desc)
 | 
				
			||||||
 | 
					        if validate_errors:
 | 
				
			||||||
 | 
					            LOGGER.error(
 | 
				
			||||||
 | 
					                "Input JSON did not conform to schema. It was: {}", desc)
 | 
				
			||||||
 | 
					            return {'status': 'error',
 | 
				
			||||||
 | 
					                    'message': 'Input JSON schema invalid'}, 417
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ Schemas of input objects
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__author__ = "@tormakris"
 | 
					__author__ = "@tormakris"
 | 
				
			||||||
__copyright__ = "Copyright 2019, KSZK"
 | 
					__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
				
			||||||
__module_name__ = "schemas"
 | 
					__module_name__ = "schemas"
 | 
				
			||||||
__version__text__ = "1"
 | 
					__version__text__ = "1"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user