aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-19 21:16:33 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-10-19 21:16:33 +0300
commit07e8996579e7f6a8b0676ebb5e6951dd5010c441 (patch)
treefcdae5dd45a060901318031455eb09a07efd48b7 /backend
parentrefactor: update readme and rules. use sdp for early demo confirmation (diff)
downloadlphub-07e8996579e7f6a8b0676ebb5e6951dd5010c441.tar.gz
lphub-07e8996579e7f6a8b0676ebb5e6951dd5010c441.tar.bz2
lphub-07e8996579e7f6a8b0676ebb5e6951dd5010c441.zip
backend: fix download demo
Diffstat (limited to 'backend')
-rw-r--r--backend/handlers/record.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/backend/handlers/record.go b/backend/handlers/record.go
index ed9250d..6078f8d 100644
--- a/backend/handlers/record.go
+++ b/backend/handlers/record.go
@@ -356,21 +356,30 @@ func DeleteRecord(c *gin.Context) {
356// @Router /demos [get] 356// @Router /demos [get]
357func DownloadDemoWithID(c *gin.Context) { 357func DownloadDemoWithID(c *gin.Context) {
358 uuid := c.Query("uuid") 358 uuid := c.Query("uuid")
359 var locationID string
360 if uuid == "" { 359 if uuid == "" {
361 c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) 360 c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given."))
362 return 361 return
363 } 362 }
364 err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1`, uuid).Scan(&locationID) 363 srv, err := drive.New(serviceAccount())
365 if err != nil { 364 if err != nil {
366 c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) 365 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
367 return 366 return
368 } 367 }
369 if locationID == "" { 368
370 c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) 369 // Query drive instead of finding location id from db because SOMEONE reuploaded the demos.
370 // Tbf I had to reupload and will have to do time after time. Fuck you Google.
371 // I guess there's no need to store location id of demos anymore?
372 fileList, err := srv.Files.List().Q(fmt.Sprintf("name = '%s.dem'", uuid)).Do()
373 if err != nil {
374 c.JSON(http.StatusOK, models.ErrorResponse(err.Error()))
375 return
376 }
377 if len(fileList.Files) == 0 {
378 c.JSON(http.StatusOK, models.ErrorResponse("Demo not found."))
371 return 379 return
372 } 380 }
373 url := "https://drive.google.com/uc?export=download&id=" + locationID 381
382 url := "https://drive.google.com/uc?export=download&id=" + fileList.Files[0].Id
374 fileName := uuid + ".dem" 383 fileName := uuid + ".dem"
375 output, err := os.Create(fileName) 384 output, err := os.Create(fileName)
376 if err != nil { 385 if err != nil {