add configs from file, continue develpoment on hubs

This commit is contained in:
2026-04-23 14:34:47 +02:00
parent 35827f7214
commit 8a66a905cb
13 changed files with 151 additions and 82 deletions
+11 -11
View File
@@ -8,7 +8,7 @@ import (
"strconv"
"time"
"go-socket/packages/globals"
"go-socket/packages/config"
"github.com/google/uuid"
"github.com/minio/minio-go/v7"
@@ -68,15 +68,15 @@ func Init(ctx context.Context) {
panic(err)
}
exists, err := minClient.BucketExists(ctx, globals.FileStorageBucketName)
exists, err := minClient.BucketExists(ctx, config.FileStorageBucketName)
if err != nil {
panic(err)
}
if !exists {
err = minClient.MakeBucket(ctx, globals.FileStorageBucketName, minio.MakeBucketOptions{})
err = minClient.MakeBucket(ctx, config.FileStorageBucketName, minio.MakeBucketOptions{})
if err != nil {
exists, checkErr := minClient.BucketExists(ctx, globals.FileStorageBucketName)
exists, checkErr := minClient.BucketExists(ctx, config.FileStorageBucketName)
if checkErr != nil || !exists {
panic(err)
}
@@ -87,22 +87,22 @@ func Init(ctx context.Context) {
func Upload(ctx context.Context, key string, body io.Reader, size int64, contentType string, metadata map[string]string) error {
opt := minio.PutObjectOptions{
ContentType: contentType,
PartSize: globals.FileProcessingPartBytes,
NumThreads: globals.FileProcessingThreads,
PartSize: config.FileProcessingPartBytes,
NumThreads: config.FileProcessingThreads,
UserMetadata: metadata,
}
opt.SetMatchETagExcept("*")
_, err := minClient.PutObject(ctx, globals.FileStorageBucketName, key, body, size, opt)
_, err := minClient.PutObject(ctx, config.FileStorageBucketName, key, body, size, opt)
return err
}
func GetDownloadUrlAndMetadata(ctx context.Context, key string) (*url.URL, map[string]string, error) {
info, err := minClient.StatObject(ctx, globals.FileStorageBucketName, key, minio.StatObjectOptions{})
info, err := minClient.StatObject(ctx, config.FileStorageBucketName, key, minio.StatObjectOptions{})
if err != nil {
return nil, nil, err
}
u, err := minClient.PresignedGetObject(ctx, globals.FileStorageBucketName, key, globals.FileDownloadLinkTtl, nil)
u, err := minClient.PresignedGetObject(ctx, config.FileStorageBucketName, key, config.FileDownloadLinkTtl, nil)
if err != nil {
return nil, nil, err
}
@@ -110,11 +110,11 @@ func GetDownloadUrlAndMetadata(ctx context.Context, key string) (*url.URL, map[s
}
func DoesExist(ctx context.Context, key string) bool {
_, err := minClient.StatObject(ctx, globals.FileStorageBucketName, key, minio.StatObjectOptions{})
_, err := minClient.StatObject(ctx, config.FileStorageBucketName, key, minio.StatObjectOptions{})
return err == nil
}
func Delete(ctx context.Context, key string) error {
err := minClient.RemoveObject(ctx, globals.FileStorageBucketName, key, minio.RemoveObjectOptions{})
err := minClient.RemoveObject(ctx, config.FileStorageBucketName, key, minio.RemoveObjectOptions{})
return err
}