@@ -14,7 +14,7 @@ def homepage():
1414
1515@app .route ('/catalog' )
1616def 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>' )
2828def 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():
5451def 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>' )
6663def 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
7471def 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 :
0 commit comments