Added support for multiple manuals
This also added support for different documet/filetypes. Currenty defines ones are manual and patchnotes. [fixes #32]
This commit is contained in:
parent
5443e3b93e
commit
77bd652f94
@ -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)
|
||||
|
||||
@ -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", "<br />")
|
||||
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("/<lang_code>/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("/<lang_code>/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)})
|
||||
|
||||
@ -15,8 +15,12 @@
|
||||
<p>{{part}}</p>
|
||||
{% endfor %}
|
||||
<h3>{{lang_game_manual}}</h3>
|
||||
{% if 'manual' in game.game %}
|
||||
<a href="{{ url_for('getmanual', gamepath=game.path, manual=game.game.manual, lang_code=lang_code)}}">{{lang_game_get_manual}}</a>
|
||||
{% if game.game.documents %}
|
||||
{% for document in game.game.documents %}
|
||||
{% if document.type == 'manual' %}
|
||||
<a href="{{ url_for('getfile', gamepath=game.path, filepath=document.path, lang_code=lang_code)}}">{{lang_game_get_manual}} {{document.path}}</a><br />
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>{{lang_game_manual_not_found}}</p>
|
||||
{% endif %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user