From 3b4df3dee1ef1bb0555e6fddde6fb08a3063b1f4 Mon Sep 17 00:00:00 2001 From: assar Date: Tue, 6 Jun 2017 11:03:55 +0000 Subject: [PATCH] Added the getfile app route --- server.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index fc789a0..8eb3643 100644 --- a/server.py +++ b/server.py @@ -1,9 +1,10 @@ import json +import re import sqlalchemy from sqlalchemy.sql import select from sqlalchemy.sql import text from flask import Flask -from flask import render_template +from flask import render_template, send_from_directory app = Flask(__name__) @@ -49,6 +50,13 @@ def query(filter, query): r.close() return json.dumps(l) +@app.route('/parts/getfile/') +def getfile(filename): + if(re.match('^[\w-_]+\.pdf$', filename) == None): + return 'No injections pls.' + + return send_from_directory('/srv/datasheets/', 'filename') + def connect(user, password, db, host='localhost', port=5432): '''Returns a connection and a metadata object''' # We connect with the help of the PostgreSQL URL