75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
from __main__ import app
|
|
import json
|
|
import requests
|
|
from flask import render_template, request, Response
|
|
import modules.init
|
|
|
|
host_endpoint = modules.init.host_endpoint()
|
|
languages = modules.init.get_languages()
|
|
app_language = modules.init.app_language
|
|
|
|
|
|
# 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
|
|
@app.route("/<lang_code>/game")
|
|
def game(lang_code):
|
|
lang_code = lang(lang_code)
|
|
gamepath = request.args.get("gamepath")
|
|
|
|
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'] != "":
|
|
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
|
|
@app.route("/<lang_code>/game/artwork")
|
|
def artwork(lang_code):
|
|
pass
|
|
|
|
|
|
# Download a game
|
|
@app.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(host_endpoint + '/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
|
|
@app.route("/<lang_code>/game/getmanual")
|
|
def getmanual(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",
|
|
headers={
|
|
"Content-Disposition":
|
|
"attachment;filename=" + str(manualname)})
|