-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
41 lines (35 loc) · 1.13 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from PIL import Image
from flask import Flask
from werkzeug.datastructures import FileStorage
import logging
class Util:
status_response = {
'OK': 200,
'CREATED': 201,
'BAD_REQUEST': 400,
'NOT_FOUND': 404,
'METHOD_NOT_ALLOWED': 405,
'DUPLICATED': 409
}
logging.basicConfig(filename='access.log', level=logging.DEBUG, \
format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
@staticmethod
def remove_image_exif(img: FileStorage):
image = Image.open(img)
return image
@staticmethod
def allowed_file(filename: str):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() \
in ( 'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif' )
@staticmethod
def is_image(filename: str):
return filename.split('.')[1] in ( 'png', 'jpg', 'jpeg', 'gif' )
@staticmethod
def create_app():
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = './files'
app.add_url_rule(
"/<file>", endpoint="serve_files", build_only=True
)
return app