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)
|
return jsonify(artlist)
|
||||||
|
|
||||||
|
|
||||||
# Server game manual
|
# Serve a file. Takes the following object parameters:
|
||||||
@app.route('/getmanual', methods=["GET"])
|
# nfopath base64-encoded full path to specific game nfo-file
|
||||||
def getmanual():
|
# filepath base64-encoded path to file starting from game dir
|
||||||
nfopath = base64.b64decode(request.json).decode()
|
@app.route('/getfile', methods=["GET"])
|
||||||
nfo = json.load(open(nfopath, 'r'))
|
def getfile():
|
||||||
nfo['path'] = base64.b64encode(nfopath.encode('utf-8')).decode()
|
nfopath = os.path.dirname(
|
||||||
manualname = nfo['game']['manual']
|
base64.b64decode(request.json['nfopath']).decode())
|
||||||
manualpath = os.path.dirname(nfopath)+'/'
|
filepath = base64.b64decode(request.json['filepath']).decode()
|
||||||
return send_from_directory(manualpath, manualname, as_attachment=True)
|
return send_from_directory(nfopath, filepath, as_attachment=True)
|
||||||
|
|
||||||
|
|
||||||
# Game folder as ZIP-file (kinda slow)
|
# Game folder as ZIP-file (kinda slow)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
from __main__ import app
|
from __main__ import app
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
import base64
|
||||||
from flask import render_template, request, Response
|
from flask import render_template, request, Response
|
||||||
import modules.init
|
import modules.init
|
||||||
|
|
||||||
@ -25,7 +26,6 @@ def game(lang_code):
|
|||||||
game = json.loads((requests.post(
|
game = json.loads((requests.post(
|
||||||
host_endpoint + '/game', json=gamepath).content).decode())
|
host_endpoint + '/game', json=gamepath).content).decode())
|
||||||
|
|
||||||
# game['game']['plot'] = game['game']['plot'].replace("\\n", "<br />")
|
|
||||||
game['game']['plot'] = game['game']['plot'].split('\\n')
|
game['game']['plot'] = game['game']['plot'].split('\\n')
|
||||||
if 'linuxinstructions' in game['game']:
|
if 'linuxinstructions' in game['game']:
|
||||||
if game['game']['linuxinstructions'] != "":
|
if game['game']['linuxinstructions'] != "":
|
||||||
@ -63,12 +63,18 @@ def download(lang_code):
|
|||||||
|
|
||||||
|
|
||||||
# Download manual
|
# Download manual
|
||||||
@app.route("/<lang_code>/game/getmanual")
|
# Download file from backend. Could be documents, patches etc.
|
||||||
def getmanual(lang_code):
|
# 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")
|
gamepath = request.args.get("gamepath")
|
||||||
manualname = request.args.get("manual")
|
filepath = request.args.get("filepath")
|
||||||
manual = requests.get(host_endpoint + '/getmanual', json=gamepath)
|
filepath_enc = base64.b64encode(filepath.encode('utf-8')).decode()
|
||||||
return Response(manual, mimetype="application/pdf",
|
jsonbody = {'nfopath': gamepath, 'filepath': filepath_enc}
|
||||||
|
print(gamepath, filepath)
|
||||||
|
file = requests.get(host_endpoint + '/getfile', json=jsonbody)
|
||||||
|
return Response(file, mimetype="application/pdf",
|
||||||
headers={
|
headers={
|
||||||
"Content-Disposition":
|
"Content-Disposition":
|
||||||
"attachment;filename=" + str(manualname)})
|
"attachment;filename=" + str(filepath)})
|
||||||
|
|||||||
@ -15,8 +15,12 @@
|
|||||||
<p>{{part}}</p>
|
<p>{{part}}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<h3>{{lang_game_manual}}</h3>
|
<h3>{{lang_game_manual}}</h3>
|
||||||
{% if 'manual' in game.game %}
|
{% if game.game.documents %}
|
||||||
<a href="{{ url_for('getmanual', gamepath=game.path, manual=game.game.manual, lang_code=lang_code)}}">{{lang_game_get_manual}}</a>
|
{% 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 %}
|
{% else %}
|
||||||
<p>{{lang_game_manual_not_found}}</p>
|
<p>{{lang_game_manual_not_found}}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user