mirror of
https://github.com/FAUSheppy/python-flask-picture-factory
synced 2025-12-06 07:01:37 +01:00
change: remove native oidc & before_first_request
This commit is contained in:
24
server.py
24
server.py
@@ -5,23 +5,15 @@ import argparse
|
|||||||
import sys
|
import sys
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
import werkzeug.utils
|
import werkzeug.utils
|
||||||
import flask_oidc
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
app = flask.Flask("Picture factory app", static_folder=None)
|
app = flask.Flask("Picture factory app", static_folder=None)
|
||||||
|
|
||||||
## OIDC CONFIG SETUP ##
|
|
||||||
if os.path.isfile("oidc.json"):
|
|
||||||
with open("oidc.json") as f:
|
|
||||||
app.config |= json.load(f)
|
|
||||||
if not os.path.isfile(app.config["OIDC_CLIENT_SECRETS"]):
|
|
||||||
raise ValueError("client_secrets.json file is missing in project root")
|
|
||||||
else:
|
|
||||||
raise ValueError("OIDC required by environment but not oidc.json file found")
|
|
||||||
|
|
||||||
oidc = flask_oidc.OpenIDConnect(app)
|
|
||||||
PICTURE_DIR = "pictures/"
|
PICTURE_DIR = "pictures/"
|
||||||
|
|
||||||
|
app.config['MAX_CONTENT_PATH'] = 32+1000*1000
|
||||||
|
app.config['UPLOAD_FOLDER'] = PICTURE_DIR
|
||||||
|
app.config['UPLOAD_ENABLED'] = os.path.isfile("./upload.enable")
|
||||||
|
|
||||||
def generatePicture(pathToOrig, scaleX, scaleY, encoding, crop):
|
def generatePicture(pathToOrig, scaleX, scaleY, encoding, crop):
|
||||||
'''Generate an pictures with the requested scales and encoding if it doesn't already exist'''
|
'''Generate an pictures with the requested scales and encoding if it doesn't already exist'''
|
||||||
|
|
||||||
@@ -149,7 +141,6 @@ def list():
|
|||||||
return flask.render_template("index.html", paths=retStringArr)
|
return flask.render_template("index.html", paths=retStringArr)
|
||||||
|
|
||||||
@app.route("/upload", methods = ['GET', 'POST'])
|
@app.route("/upload", methods = ['GET', 'POST'])
|
||||||
@oidc.require_login
|
|
||||||
def upload():
|
def upload():
|
||||||
if not app.config['UPLOAD_ENABLED']:
|
if not app.config['UPLOAD_ENABLED']:
|
||||||
return ("Upload Disabled", 403)
|
return ("Upload Disabled", 403)
|
||||||
@@ -169,13 +160,6 @@ def upload():
|
|||||||
else:
|
else:
|
||||||
return flask.render_template("upload.html")
|
return flask.render_template("upload.html")
|
||||||
|
|
||||||
@app.before_first_request
|
|
||||||
def init():
|
|
||||||
app.config['MAX_CONTENT_PATH'] = 32+1000*1000
|
|
||||||
app.config['UPLOAD_FOLDER'] = PICTURE_DIR
|
|
||||||
app.config['UPLOAD_ENABLED'] = os.path.isfile("./upload.enable")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Picture Factory',
|
parser = argparse.ArgumentParser(description='Picture Factory',
|
||||||
|
|||||||
Reference in New Issue
Block a user