mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-05-10 18:25:03 -04:00
First commit
This commit is contained in:
commit
60aa7f879e
3 changed files with 95 additions and 0 deletions
54
main.py
Normal file
54
main.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import os
|
||||
|
||||
import libmat2
|
||||
from libmat2 import parser_factory
|
||||
|
||||
from flask import Flask, flash, request, redirect, url_for, render_template
|
||||
from flask import send_from_directory, after_this_request
|
||||
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
UPLOAD_FOLDER = './'
|
||||
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = '1337'
|
||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def upload_file():
|
||||
if request.method == 'POST':
|
||||
if 'file' not in request.files: # check if the post request has the file part
|
||||
flash('No file part')
|
||||
return redirect(request.url)
|
||||
uploaded_file = request.files['file']
|
||||
if uploaded_file.filename == '':
|
||||
flash('No selected file')
|
||||
return redirect(request.url)
|
||||
filename = secure_filename(uploaded_file.filename)
|
||||
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||
uploaded_file.save(os.path.join(filepath))
|
||||
|
||||
parser, mime = parser_factory.get_parser(filepath)
|
||||
if parser is None:
|
||||
flash('The type %s is not supported' % mime)
|
||||
return redirect(url_for('upload_file'))
|
||||
elif parser.remove_all() is not True:
|
||||
flash('Unable to clean ' % mime)
|
||||
return redirect(url_for('upload_file'))
|
||||
os.remove(filename)
|
||||
|
||||
@after_this_request
|
||||
def remove_file(response):
|
||||
os.remove(parser.output_filename)
|
||||
return response
|
||||
|
||||
return send_from_directory(app.config['UPLOAD_FOLDER'], parser.output_filename)
|
||||
|
||||
mimetypes = 'image/jpeg, image/png'
|
||||
return render_template('index.html', mimetypes=mimetypes)
|
||||
|
||||
|
||||
app.run()
|
21
static/style.css
Normal file
21
static/style.css
Normal file
|
@ -0,0 +1,21 @@
|
|||
header {
|
||||
border-bottom: 1px solid black;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
text-align: center;
|
||||
}
|
||||
header a {
|
||||
text-align:right;
|
||||
}
|
||||
|
||||
section {
|
||||
border-radius: 1em;
|
||||
padding: 1em;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin-right: -50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
20
templates/index.html
Normal file
20
templates/index.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>mat2 - online edition</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>mat2 - online edition</h1>
|
||||
</header>
|
||||
<section>
|
||||
<h1>Remove metadata from your images</h1>
|
||||
<p>Drag and drop anywhere you want and get your files cleaned</p>
|
||||
<br>
|
||||
<form method=post enctype=multipart/form-data>
|
||||
<input type=file name=file id="upload_file" accept="{{ mimetypes }}">
|
||||
<input type=submit value=Upload>
|
||||
</form>
|
||||
</section>
|
||||
</body>
|
Loading…
Add table
Add a link
Reference in a new issue