Use config from .env and update api

This commit is contained in:
2026-01-24 18:09:24 +01:00
parent 1e02e659ab
commit 1c26770db0
11 changed files with 171 additions and 44 deletions

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"sheetless-server/config"
"sheetless-server/database"
"sheetless-server/models"
"sheetless-server/utils"
@@ -16,15 +17,6 @@ import (
"github.com/google/uuid"
)
const uploadDir = "./uploads"
func init() {
// Create uploads directory if it doesn't exist
if err := os.MkdirAll(uploadDir, 0755); err != nil {
panic("Failed to create uploads directory: " + err.Error())
}
}
func UploadSheet(c *gin.Context) {
// Get form data
title := c.PostForm("title")
@@ -69,7 +61,7 @@ func UploadSheet(c *gin.Context) {
// Generate unique filename
filename := fmt.Sprintf("%d%s", time.Now().Unix(), filepath.Ext(header.Filename))
filePath := filepath.Join(uploadDir, filename)
filePath := filepath.Join(config.AppConfig.SheetsDirectory, filename)
// Save file
out, err := os.Create(filePath)
@@ -106,15 +98,15 @@ func UploadSheet(c *gin.Context) {
// Create database record
sheet := models.Sheet{
Uuid: *uuid,
Title: title,
Description: description,
FilePath: filePath,
FileSize: fileInfo.Size(),
FileHash: fileHash,
ComposerId: composer.Uuid,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Uuid: *uuid,
Title: title,
Description: description,
FilePath: filePath,
FileSize: fileInfo.Size(),
FileHash: fileHash,
ComposerUuid: composer.Uuid,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if err := database.DB.Create(&sheet).Error; err != nil {