diff --git a/api/modules/game.py b/api/modules/game.py index b995c8f..a1432e4 100644 --- a/api/modules/game.py +++ b/api/modules/game.py @@ -86,15 +86,15 @@ def artwork(size='max'): return jsonify(artlist) -# Server game manual -@app.route('/getmanual', methods=["GET"]) -def getmanual(): - nfopath = base64.b64decode(request.json).decode() - nfo = json.load(open(nfopath, 'r')) - nfo['path'] = base64.b64encode(nfopath.encode('utf-8')).decode() - manualname = nfo['game']['manual'] - manualpath = os.path.dirname(nfopath)+'/' - return send_from_directory(manualpath, manualname, as_attachment=True) +# Serve a file. Takes the following object parameters: +# nfopath base64-encoded full path to specific game nfo-file +# filepath base64-encoded path to file starting from game dir +@app.route('/getfile', methods=["GET"]) +def getfile(): + nfopath = os.path.dirname( + base64.b64decode(request.json['nfopath']).decode()) + filepath = base64.b64decode(request.json['filepath']).decode() + return send_from_directory(nfopath, filepath, as_attachment=True) # Game folder as ZIP-file (kinda slow) diff --git a/site/modules/game.py b/site/modules/game.py index 9a5433c..7cdbfc1 100644 --- a/site/modules/game.py +++ b/site/modules/game.py @@ -1,6 +1,7 @@ from __main__ import app import json import requests +import base64 from flask import render_template, request, Response import modules.init @@ -25,7 +26,6 @@ def game(lang_code): game = json.loads((requests.post( host_endpoint + '/game', json=gamepath).content).decode()) -# game['game']['plot'] = game['game']['plot'].replace("\\n", "
") game['game']['plot'] = game['game']['plot'].split('\\n') if 'linuxinstructions' in game['game']: if game['game']['linuxinstructions'] != "": @@ -63,12 +63,18 @@ def download(lang_code): # Download manual -@app.route("//game/getmanual") -def getmanual(lang_code): +# 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 +@app.route("//game/getfile") +def getfile(lang_code): gamepath = request.args.get("gamepath") - manualname = request.args.get("manual") - manual = requests.get(host_endpoint + '/getmanual', json=gamepath) - return Response(manual, mimetype="application/pdf", + 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(host_endpoint + '/getfile', json=jsonbody) + return Response(file, mimetype="application/pdf", headers={ "Content-Disposition": - "attachment;filename=" + str(manualname)}) + "attachment;filename=" + str(filepath)}) diff --git a/site/templates/game.html b/site/templates/game.html index 52a7267..303cd55 100644 --- a/site/templates/game.html +++ b/site/templates/game.html @@ -15,11 +15,15 @@

{{part}}

{% endfor %}

{{lang_game_manual}}

- {% if 'manual' in game.game %} - {{lang_game_get_manual}} + {% if game.game.documents %} + {% for document in game.game.documents %} + {% if document.type == 'manual' %} + {{lang_game_get_manual}} {{document.path}}
+ {% endif %} + {% endfor %} {% else %}

{{lang_game_manual_not_found}}

- {% endif%} + {% endif %}

{{lang_game_download_header}}

{{lang_game_download_ingress}}