@@ -7,11 +7,13 @@ import (
77 "io"
88 "log"
99 "mime/multipart"
10+ "strings"
1011 "time"
1112
1213 "novissima/internal/logging"
1314
1415 "github.com/google/uuid"
16+ storage_go "github.com/supabase-community/storage-go"
1517 "github.com/supabase-community/supabase-go"
1618)
1719
@@ -57,13 +59,39 @@ func (s *Service) AddContent(contentEnglish string, contentLatin string, file mu
5759 if file != nil && header != nil {
5860 defer file .Close ()
5961
60- filename := fmt .Sprintf ("%s/%s" , theme , header .Filename )
62+ fileExt := ""
63+ if idx := strings .LastIndex (header .Filename , "." ); idx != - 1 {
64+ fileExt = header .Filename [idx :]
65+ }
66+ filename := fmt .Sprintf ("%s/%s%s" , theme , uuid .New ().String (), fileExt )
67+
6168 fileBytes , err := io .ReadAll (file )
6269 if err != nil {
6370 return Content {}, fmt .Errorf ("failed to read file: %w" , err )
64- }
71+ }
6572
66- _ , err = s .dbClient .Storage .UploadFile (s .bucketName , filename , bytes .NewReader (fileBytes ))
73+
74+ fileReader := bytes .NewReader (fileBytes )
75+
76+
77+ contentType := header .Header .Get ("Content-Type" )
78+ if contentType == "" {
79+ switch fileExt {
80+ case ".jpg" , ".jpeg" :
81+ contentType = "image/jpeg"
82+ case ".png" :
83+ contentType = "image/png"
84+ case ".gif" :
85+ contentType = "image/gif"
86+ default :
87+ contentType = "application/octet-stream"
88+ }
89+ }
90+
91+ fileOptions := storage_go.FileOptions {
92+ ContentType : & contentType ,
93+ }
94+ _ , err = s .dbClient .Storage .UploadFile (s .bucketName , filename , fileReader , fileOptions )
6795 if err != nil {
6896 return Content {}, fmt .Errorf ("failed to upload to storage: %w" , err )
6997 }
@@ -94,7 +122,7 @@ func (s *Service) AddContent(contentEnglish string, contentLatin string, file mu
94122}
95123
96124func (s * Service ) GetDailyContent () (* Content , error ) {
97- themes := []string {"heaven" , "hell" , "judgment" , "death" }
125+ themes := []string { "death" }
98126 startDate := time .Date (2025 , 7 , 1 , 0 , 0 , 0 , 0 , time .UTC )
99127
100128 now := time .Now ()
@@ -103,13 +131,11 @@ func (s *Service) GetDailyContent() (*Content, error) {
103131
104132 currentTheme := themes [cycleDay ]
105133
106- thirtyDaysAgo := now .AddDate (0 , 0 , - 30 )
134+ // thirtyDaysAgo := now.AddDate(0, 0, -30)
107135
108136 content , _ , err := s .dbClient .From ("content" ).
109137 Select ("*" , "" , false ).
110138 Eq ("theme" , currentTheme ).
111- Or ("last_sent.is.null" , "" ).
112- Or ("last_sent.lt." + thirtyDaysAgo .Format ("2006-01-02" ), "" ).
113139 Limit (1 , "" ).
114140 Execute ()
115141 if err != nil {
0 commit comments