Skip to content

Add Game Download #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from flask_login import login_required, current_user
from auth import app
import requests
from io import BytesIO
from werkzeug.wsgi import FileWrapper

@app.route('/')
# @login_required
Expand Down Expand Up @@ -63,6 +65,13 @@ def uploadpage():
print("api offline")
return flask.render_template('upload.html', title='Devcade - Upload', gamelist=usergames)

@app.route('/download/<id>')
def download(id):
r = requests.get(app.config["DEVCADE_API_URI"] + "games/download/" + id, stream=True)
b = BytesIO(r.content)
game = FileWrapper(b)
return flask.Response(game, mimetype="application/zip", direct_passthrough=True)

@app.route('/admin/delete/<id>')
@login_required
def deleteGame(id):
Expand Down
4 changes: 4 additions & 0 deletions src/templates/game.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{% extends "header.html" %} {% block title %}Devcade - {{game.name}}
{%endblock %} {% block content %}
<div class="card-wrapper">{{ gamecard(game) }}</div>
<div class="card-wrapper">
<a class="btn btn-red" href="/download/{{ game.id }}">Download Game</a>
</div>
{% if current_user.admin or current_user.id == game.author %}
<h2>Admin stuff:</h2>
<div class="card-wrapper">
<a class="btn btn-red" href="/edit/{{ game.id }}">Edit</a>
<a class="btn btn-red" href="/admin/delete/{{ game.id }}">Delete</a>
Expand Down