From 1506201913fff1dd02136e5a4ec8d5ee49e84261 Mon Sep 17 00:00:00 2001 From: nocci Date: Fri, 9 May 2025 11:31:50 +0200 Subject: [PATCH] double redeem block deleted --- setup.sh | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/setup.sh b/setup.sh index 9cad0fd..be7212f 100644 --- a/setup.sh +++ b/setup.sh @@ -259,6 +259,7 @@ ITAD_API_KEY_PLACEHOLDER = "your_api_key_here" TZ = os.getenv('TZ', 'UTC') os.environ['TZ'] = TZ app = Flask(__name__) +app.jinja_env.globals['getattr'] = getattr # UNIX-Systems (Linux, Docker) try: @@ -535,11 +536,13 @@ class GameForm(FlaskForm): steam_appid = StringField('Steam App ID') PLATFORM_CHOICES = [ - ('pc', 'PC'), + ('steam', 'Steam'), + ('gog', 'GOG'), ('xbox', 'XBox'), ('playstation', 'PlayStation'), ('switch', 'Nintendo Switch'), - ('other', 'Andere') + ('other', 'Other'), + ('pc', 'PC') ] STATUS_CHOICES = [ @@ -1119,7 +1122,6 @@ def import_games(): return render_template('import.html') - @app.route('/generate_redeem/', methods=['POST']) @login_required def generate_redeem(game_id): @@ -1149,31 +1151,45 @@ def generate_redeem(game_id): db.session.rollback() return jsonify({'error': str(e)}), 500 - @app.route('/redeem/', endpoint='redeem') def redeem_page(token): redeem_token = RedeemToken.query.filter_by(token=token).first() - if not redeem_token: abort(404) - - # Zeit in UTC umwandeln expires_utc = redeem_token.expires.astimezone(pytz.UTC) - if datetime.now(pytz.UTC) > expires_utc: db.session.delete(redeem_token) db.session.commit() abort(404) - game = Game.query.get(redeem_token.game_id) redeem_token.used = True db.session.commit() - return render_template('redeem.html', - game=game, - redeem_token=redeem_token, - expires_timestamp=int(expires_utc.timestamp() * 1000), # Millisekunden - platform_link='https://store.steampowered.com/account/registerkey?key=' if game.steam_appid else 'https://www.gog.com/redeem') + # which Plattform + if game.platform == "steam" or game.steam_appid: + platform_link = 'https://store.steampowered.com/account/registerkey?key=' + platform_label = "Steam" + elif game.platform == "gog": + platform_link = 'https://www.gog.com/redeem/' + platform_label = "GOG" + elif game.platform == "xbox": + platform_link = 'https://redeem.microsoft.com/' + platform_label = "XBOX" + elif game.platform == "playstation": + platform_link = 'https://store.playstation.com/redeem' + platform_label = "PlayStation" + else: + platform_link = '#' + platform_label = game.platform.capitalize() if game.platform else "Unknown" + + return render_template( + 'redeem.html', + game=game, + redeem_token=redeem_token, + expires_timestamp=int(expires_utc.timestamp() * 1000), + platform_link=platform_link, + platform_label=platform_label + ) @app.route('/admin/users') @login_required @@ -2251,9 +2267,9 @@ cat <<'HTML_END' > templates/redeem.html {{ game.steam_key }} - {{ _('Redeem now on') }} {% if game.steam_appid %}Steam{% else %}GOG{% endif %} + class="btn btn-primary btn-lg mb-3" + target="_blank"> + {{ _('Redeem now on') }} {{ platform_label }}