Skip to content
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

Update to Rust API #36

Merged
merged 2 commits into from
Mar 23, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ envs.py
.venv
venv/
users.sqlite3
launch.json
launch.json
.env
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM docker.io/python:3.8-buster
LABEL maintainer="Andrew Simonson <asimonson1125@gmail.com>"

WORKDIR /app
ADD ./src /app
#ADD ./src /app
COPY ./requirements.txt requirements.txt
RUN apt-get -yq update && \
pip install --no-cache-dir -r requirements.txt
Expand Down
26 changes: 10 additions & 16 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def homepage():

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

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

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

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

@app.route('/download/<id>')
def download(id):
r = requests.get(app.config["DEVCADE_API_URI"] + "games/download/" + id, stream=True)
r = requests.get(app.config["DEVCADE_API_URI"] + f"games/{id}/game", 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):
games = requests.get(app.config['DEVCADE_API_URI'] + "games/gamelist").json()
author = ""
for i in games:
if i['id'] == id:
author = i['author']
game = requests.get(app.config['DEVCADE_API_URI'] + "games/" + id).json()
author = game['author']
if(current_user.admin or current_user.id == author):
r = requests.post(app.config["DEVCADE_API_URI"] + "games/delete/" + id)
r = requests.delete(app.config["DEVCADE_API_URI"] + "games/" + id, headers={"frontend_api_key":app.config["FRONTEND_API_KEY"]})
if r.status_code != 200:
return r.text
else:
Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
OIDC_CLIENT_SECRET = env.get('OIDC_CLIENT_SECRET', 'NOT-A-SECRET')

DEVCADE_API_URI = env.get('DEVCADE_API_URI')
FRONTEND_API_KEY = env.get('FRONTEND_API_KEY')

DEVCADE_IS_DEV = env.get('DEVCADE_IS_DEV')
8 changes: 7 additions & 1 deletion src/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,11 @@
"link" : "",
"email" : hashlib.md5(b"chrisp@csh.rit.edu").hexdigest(),
"desc" : "Hardware Team, First Year GDD"
},
{
"name" : "Joe Abbate",
"link" : "https://joeabbate.me",
"email" : hashlib.md5(b"skyz@csh.rit.edu").hexdigest(),
"desc" : "Lead Security Engineer, Third Year Cyber Security"
}
]
]
6 changes: 3 additions & 3 deletions src/templates/header.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% macro gamecard(game) %}
<a href="/game/{{ game.id }}">
<div class="game-card" style="background-image: url({{ game.bannerLink }})">
<img class="game-icon" src="{{ game.iconLink }}" />
<a href="/game/{{ game.game_id }}">
<div class="game-card" style="background-image: url({{ config['DEVCADE_API_URI'] }}games/{{ game.game_id }}/banner)">
<img class="game-icon" src="{{ config['DEVCADE_API_URI'] }}games/{{ game.game_id }}/icon" />
<div class="game-name">
<div>
<h2>{{ game.name }}</h2>
Expand Down