Переведите приём и чтение вложений на асинхронный контракт

This commit is contained in:
2026-11-18 15:33:32 +03:00
parent efc56b1382
commit bf970227d6
19 changed files with 667 additions and 367 deletions
+12 -1
View File
@@ -2,17 +2,20 @@ package config
import (
"fmt"
"math"
"strconv"
"time"
)
type S3 struct {
Endpoint, Region, Bucket string
AccessKey, SecretKey string
MaxBytes, MaxPixels int64
StagingRetention time.Duration
}
func LoadS3(lookup Lookup) (S3, error) {
cfg := S3{Endpoint: "http://s3:8333", Region: "us-east-1", Bucket: "messenger-attachments", MaxBytes: 10485760, MaxPixels: 40000000}
cfg := S3{Endpoint: "http://s3:8333", Region: "us-east-1", Bucket: "messenger-attachments", MaxBytes: 10485760, MaxPixels: 40000000, StagingRetention: 24 * time.Hour}
for key, dest := range map[string]*string{"S3_ENDPOINT": &cfg.Endpoint, "S3_REGION": &cfg.Region, "S3_BUCKET": &cfg.Bucket} {
if v, ok := lookup(key); ok {
*dest = v
@@ -38,6 +41,14 @@ func LoadS3(lookup Lookup) (S3, error) {
*p.dest = n
}
}
if raw, ok := lookup("STAGING_RETENTION_SECONDS"); ok {
const maxSeconds = math.MaxInt64 / int64(time.Second)
n, err := strconv.ParseInt(raw, 10, 64)
if err != nil || n < 1 || n > maxSeconds {
return S3{}, fmt.Errorf("STAGING_RETENTION_SECONDS must be between 1 and %d", maxSeconds)
}
cfg.StagingRetention = time.Duration(n) * time.Second
}
return cfg, nil
}