diff --git a/.gitignore b/.gitignore index fc1e5cf..10c696d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ envs.py .venv venv/ users.sqlite3 -launch.json \ No newline at end of file +launch.json +.env diff --git a/Dockerfile b/Dockerfile index dd85f69..5eaf1d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM docker.io/python:3.8-buster LABEL maintainer="Andrew Simonson " 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 diff --git a/src/app.py b/src/app.py index 7d57737..80dfe3b 100644 --- a/src/app.py +++ b/src/app.py @@ -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') @@ -26,13 +26,10 @@ def user(): @app.route('/game/') 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 @@ -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 "

" + r.text + "

" @@ -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) @@ -64,7 +61,7 @@ def uploadpage(): @app.route('/download/') 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) @@ -72,13 +69,10 @@ def download(id): @app.route('/admin/delete/') @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: diff --git a/src/config.py b/src/config.py index b59d8cb..84abdc1 100644 --- a/src/config.py +++ b/src/config.py @@ -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') diff --git a/src/contributors.py b/src/contributors.py index 8138017..5d52445 100644 --- a/src/contributors.py +++ b/src/contributors.py @@ -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" } -] \ No newline at end of file +] diff --git a/src/templates/header.html b/src/templates/header.html index 9553add..a4d6337 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -1,7 +1,7 @@ {% macro gamecard(game) %} - -