Skip to content

Commit 61652e2

Browse files
authored
Merge pull request #36 from jabbate19/main
Update to Rust API
2 parents ef2b58d + 5ca1058 commit 61652e2

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ envs.py
33
.venv
44
venv/
55
users.sqlite3
6-
launch.json
6+
launch.json
7+
.env

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM docker.io/python:3.8-buster
22
LABEL maintainer="Andrew Simonson <[email protected]>"
33

44
WORKDIR /app
5-
ADD ./src /app
5+
#ADD ./src /app
66
COPY ./requirements.txt requirements.txt
77
RUN apt-get -yq update && \
88
pip install --no-cache-dir -r requirements.txt

src/app.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def homepage():
1414

1515
@app.route('/catalog')
1616
def catalogpage():
17-
games = requests.get(app.config["DEVCADE_API_URI"] + "games/gamelist").json()
17+
games = requests.get(app.config["DEVCADE_API_URI"] + "games/").json()
1818
return flask.render_template('catalog.html', gamelist=games)
1919

2020
@app.route('/user')
@@ -26,13 +26,10 @@ def user():
2626

2727
@app.route('/game/<id>')
2828
def getgame(id):
29-
games = requests.get(app.config["DEVCADE_API_URI"] + "games/gamelist").json()
30-
for i in range(len(games)):
31-
if games[i]['id'] == id:
32-
break
33-
else:
29+
game_req = requests.get(app.config["DEVCADE_API_URI"] + f"games/{id}")
30+
if game_req.status_code == 404:
3431
flask.render_template('404.html')
35-
return flask.render_template('game.html', game=games[i])
32+
return flask.render_template('game.html', game=game_req.json())
3633

3734
@app.route('/upload_game', methods = ['POST'])
3835
@login_required
@@ -44,7 +41,7 @@ def uploadgame():
4441
author = current_user.id
4542
file = {'file': ("game.zip", f.stream, "application/zip")}
4643
fields = {'title': title, 'description': description, 'author':author}
47-
r = requests.post(app.config["DEVCADE_API_URI"] + "games/upload", files=file, data=fields)
44+
r = requests.post(app.config["DEVCADE_API_URI"] + "games/", files=file, data=fields, headers={"frontend_api_key":app.config["FRONTEND_API_KEY"]})
4845
if r.status_code == 200:
4946
return flask.redirect('/catalog')
5047
return "<p>" + r.text + "</p>"
@@ -54,7 +51,7 @@ def uploadgame():
5451
def uploadpage():
5552
usergames = []
5653
try:
57-
games = requests.get(app.config["DEVCADE_API_URI"] + "games/gamelist").json()
54+
games = requests.get(app.config["DEVCADE_API_URI"] + "games/").json()
5855
for i in games:
5956
if i['author'] == current_user.id:
6057
usergames.append(i)
@@ -64,21 +61,18 @@ def uploadpage():
6461

6562
@app.route('/download/<id>')
6663
def download(id):
67-
r = requests.get(app.config["DEVCADE_API_URI"] + "games/download/" + id, stream=True)
64+
r = requests.get(app.config["DEVCADE_API_URI"] + f"games/{id}/game", stream=True)
6865
b = BytesIO(r.content)
6966
game = FileWrapper(b)
7067
return flask.Response(game, mimetype="application/zip", direct_passthrough=True)
7168

7269
@app.route('/admin/delete/<id>')
7370
@login_required
7471
def deleteGame(id):
75-
games = requests.get(app.config['DEVCADE_API_URI'] + "games/gamelist").json()
76-
author = ""
77-
for i in games:
78-
if i['id'] == id:
79-
author = i['author']
72+
game = requests.get(app.config['DEVCADE_API_URI'] + "games/" + id).json()
73+
author = game['author']
8074
if(current_user.admin or current_user.id == author):
81-
r = requests.post(app.config["DEVCADE_API_URI"] + "games/delete/" + id)
75+
r = requests.delete(app.config["DEVCADE_API_URI"] + "games/" + id, headers={"frontend_api_key":app.config["FRONTEND_API_KEY"]})
8276
if r.status_code != 200:
8377
return r.text
8478
else:

src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
OIDC_CLIENT_SECRET = env.get('OIDC_CLIENT_SECRET', 'NOT-A-SECRET')
3232

3333
DEVCADE_API_URI = env.get('DEVCADE_API_URI')
34+
FRONTEND_API_KEY = env.get('FRONTEND_API_KEY')
3435

3536
DEVCADE_IS_DEV = env.get('DEVCADE_IS_DEV')

src/contributors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,11 @@
7878
"link" : "",
7979
"email" : hashlib.md5(b"[email protected]").hexdigest(),
8080
"desc" : "Hardware Team, First Year GDD"
81+
},
82+
{
83+
"name" : "Joe Abbate",
84+
"link" : "https://joeabbate.me",
85+
"email" : hashlib.md5(b"[email protected]").hexdigest(),
86+
"desc" : "Lead Security Engineer, Third Year Cyber Security"
8187
}
82-
]
88+
]

src/templates/header.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% macro gamecard(game) %}
2-
<a href="/game/{{ game.id }}">
3-
<div class="game-card" style="background-image: url({{ game.bannerLink }})">
4-
<img class="game-icon" src="{{ game.iconLink }}" />
2+
<a href="/game/{{ game.game_id }}">
3+
<div class="game-card" style="background-image: url({{ config['DEVCADE_API_URI'] }}games/{{ game.game_id }}/banner)">
4+
<img class="game-icon" src="{{ config['DEVCADE_API_URI'] }}games/{{ game.game_id }}/icon" />
55
<div class="game-name">
66
<div>
77
<h2>{{ game.name }}</h2>

0 commit comments

Comments
 (0)