summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2018-11-11 23:25:40 +0100
committerjvoisin2018-11-11 23:25:40 +0100
commit60aa7f879e16e4ae329c099eecffd97547b39a07 (patch)
tree52a75b31e5b00f0f52a7cd9fe3fea15caab9d0bd
First commit
-rw-r--r--main.py54
-rw-r--r--static/style.css21
-rw-r--r--templates/index.html20
3 files changed, 95 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..b2f7776
--- /dev/null
+++ b/main.py
@@ -0,0 +1,54 @@
1import os
2
3import libmat2
4from libmat2 import parser_factory
5
6from flask import Flask, flash, request, redirect, url_for, render_template
7from flask import send_from_directory, after_this_request
8
9from werkzeug.utils import secure_filename
10
11UPLOAD_FOLDER = './'
12ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
13
14app = Flask(__name__)
15app.config['SECRET_KEY'] = '1337'
16app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
17app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB
18
19
20@app.route('/', methods=['GET', 'POST'])
21def upload_file():
22 if request.method == 'POST':
23 if 'file' not in request.files: # check if the post request has the file part
24 flash('No file part')
25 return redirect(request.url)
26 uploaded_file = request.files['file']
27 if uploaded_file.filename == '':
28 flash('No selected file')
29 return redirect(request.url)
30 filename = secure_filename(uploaded_file.filename)
31 filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
32 uploaded_file.save(os.path.join(filepath))
33
34 parser, mime = parser_factory.get_parser(filepath)
35 if parser is None:
36 flash('The type %s is not supported' % mime)
37 return redirect(url_for('upload_file'))
38 elif parser.remove_all() is not True:
39 flash('Unable to clean ' % mime)
40 return redirect(url_for('upload_file'))
41 os.remove(filename)
42
43 @after_this_request
44 def remove_file(response):
45 os.remove(parser.output_filename)
46 return response
47
48 return send_from_directory(app.config['UPLOAD_FOLDER'], parser.output_filename)
49
50 mimetypes = 'image/jpeg, image/png'
51 return render_template('index.html', mimetypes=mimetypes)
52
53
54app.run()
diff --git a/static/style.css b/static/style.css
new file mode 100644
index 0000000..ed92664
--- /dev/null
+++ b/static/style.css
@@ -0,0 +1,21 @@
1header {
2 border-bottom: 1px solid black;
3 width: 100%;
4}
5
6header h1 {
7 text-align: center;
8}
9header a {
10 text-align:right;
11}
12
13section {
14 border-radius: 1em;
15 padding: 1em;
16 position: absolute;
17 top: 50%;
18 left: 50%;
19 margin-right: -50%;
20 transform: translate(-50%, -50%);
21}
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..0496c2d
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,20 @@
1<!doctype html>
2<html>
3<head>
4 <title>mat2 - online edition</title>
5 <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" type="text/css" />
6</head>
7<body>
8 <header>
9 <h1>mat2 - online edition</h1>
10 </header>
11 <section>
12 <h1>Remove metadata from your images</h1>
13 <p>Drag and drop anywhere you want and get your files cleaned</p>
14 <br>
15 <form method=post enctype=multipart/form-data>
16 <input type=file name=file id="upload_file" accept="{{ mimetypes }}">
17 <input type=submit value=Upload>
18 </form>
19 </section>
20</body>