From 07e8996579e7f6a8b0676ebb5e6951dd5010c441 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Sat, 19 Oct 2024 21:16:33 +0300 Subject: backend: fix download demo --- backend/handlers/record.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'backend') 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) { // @Router /demos [get] func DownloadDemoWithID(c *gin.Context) { uuid := c.Query("uuid") - var locationID string if uuid == "" { c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) return } - err := database.DB.QueryRow(`SELECT location_id FROM demos WHERE id = $1`, uuid).Scan(&locationID) + srv, err := drive.New(serviceAccount()) if err != nil { c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) return } - if locationID == "" { - c.JSON(http.StatusOK, models.ErrorResponse("Invalid id given.")) + + // Query drive instead of finding location id from db because SOMEONE reuploaded the demos. + // Tbf I had to reupload and will have to do time after time. Fuck you Google. + // I guess there's no need to store location id of demos anymore? + fileList, err := srv.Files.List().Q(fmt.Sprintf("name = '%s.dem'", uuid)).Do() + if err != nil { + c.JSON(http.StatusOK, models.ErrorResponse(err.Error())) + return + } + if len(fileList.Files) == 0 { + c.JSON(http.StatusOK, models.ErrorResponse("Demo not found.")) return } - url := "https://drive.google.com/uc?export=download&id=" + locationID + + url := "https://drive.google.com/uc?export=download&id=" + fileList.Files[0].Id fileName := uuid + ".dem" output, err := os.Create(fileName) if err != nil { -- cgit v1.2.3