Add composers
This commit is contained in:
@@ -142,26 +142,23 @@ func ListSheets(c *gin.Context) {
|
||||
}
|
||||
|
||||
func DownloadSheet(c *gin.Context) {
|
||||
idStr := c.Param("id")
|
||||
id, err := strconv.ParseUint(idStr, 10, 32)
|
||||
uuid, err := uuid.Parse(c.Param("uuid"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid sheet ID"})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid sheet uuid"})
|
||||
return
|
||||
}
|
||||
|
||||
var sheet models.Sheet
|
||||
if err := database.DB.First(&sheet, uint(id)).Error; err != nil {
|
||||
if err := database.DB.First(&sheet, uuid).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Sheet not found"})
|
||||
return
|
||||
}
|
||||
|
||||
// Check if file exists
|
||||
if _, err := os.Stat(sheet.FilePath); os.IsNotExist(err) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "File not found"})
|
||||
return
|
||||
}
|
||||
|
||||
// Set headers for file download
|
||||
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filepath.Base(sheet.FilePath)))
|
||||
c.Header("Content-Type", "application/pdf")
|
||||
c.File(sheet.FilePath)
|
||||
|
||||
Reference in New Issue
Block a user