It is now possible to run the API with gunicorn using gunicorn -w 4 -b 0.0.0.0:8001 'bcnsGDSAPI:create_app()'. Also did other small changes.
85 lines
2.7 KiB
Python
85 lines
2.7 KiB
Python
import json
|
|
import requests
|
|
import base64
|
|
from flask import render_template, request, Response, Blueprint
|
|
import bcnsGDSSite.modules.init
|
|
|
|
apihost = bcnsGDSSite.modules.init.apihost()
|
|
languages = bcnsGDSSite.modules.init.get_languages()
|
|
app_language = bcnsGDSSite.modules.init.app_language
|
|
|
|
|
|
game = Blueprint('game', __name__,
|
|
template_folder='templates')
|
|
|
|
|
|
# Check if valid language code is set. If not, return app default
|
|
def lang(lang_code):
|
|
if lang_code not in languages:
|
|
return app_language
|
|
return lang_code
|
|
|
|
|
|
# Show game
|
|
@game.route("/<lang_code>/game")
|
|
def showgame(lang_code):
|
|
lang_code = lang(lang_code)
|
|
gamepath = request.args.get("gamepath")
|
|
|
|
game = json.loads((requests.post(
|
|
apihost + '/game', json=gamepath).content).decode())
|
|
|
|
game['game']['plot'] = game['game']['plot'].split('\\n')
|
|
if 'linuxinstructions' in game['game']:
|
|
if game['game']['linuxinstructions'] != "":
|
|
game['game']['linuxinstructions'] = (
|
|
game['game']['linuxinstructions'].split('\\n'))
|
|
else:
|
|
game['game'].pop('linuxinstructions')
|
|
return render_template('game.html', game=game,
|
|
**languages[lang_code], lang_code=lang_code)
|
|
|
|
|
|
# Show game artwork
|
|
@game.route("/<lang_code>/game/artwork")
|
|
def artwork(lang_code):
|
|
pass
|
|
|
|
|
|
# Download a game
|
|
#@app.route("/<lang_code>/game/download")
|
|
@game.route("/<lang_code>/game/download")
|
|
def download(lang_code):
|
|
gamepath = request.args.get("gamepath")
|
|
gametitle = request.args.get("gametitle")
|
|
targettype = request.args.get("targettype")
|
|
if "zip" in targettype:
|
|
gamezip = requests.get(apihost + '/getzipfile', json=gamepath)
|
|
return Response(gamezip, mimetype="application/zip",
|
|
headers={
|
|
"Content-Disposition":
|
|
"attachment;filename=" + str(gametitle)})
|
|
elif "torrent" in targettype:
|
|
pass
|
|
|
|
else:
|
|
pass
|
|
|
|
|
|
# Download manual
|
|
# Download file from backend. Could be documents, patches etc.
|
|
# gamepath full path to current games NFO-file
|
|
# filepath path from gamepath to the file in question
|
|
@game.route("/<lang_code>/game/getfile")
|
|
def getfile(lang_code):
|
|
gamepath = request.args.get("gamepath")
|
|
filepath = request.args.get("filepath")
|
|
filepath_enc = base64.b64encode(filepath.encode('utf-8')).decode()
|
|
jsonbody = {'nfopath': gamepath, 'filepath': filepath_enc}
|
|
print(gamepath, filepath)
|
|
file = requests.get(apihost + '/getfile', json=jsonbody)
|
|
return Response(file, mimetype="application/pdf",
|
|
headers={
|
|
"Content-Disposition":
|
|
"attachment;filename=" + str(filepath)})
|