ultisuite-backend/internal/mail/storage/client.go
R3D347HR4Y 95196f7777 Add mail attachment and draft management features
- Introduced new functionality for managing email attachments and drafts in the mail API.
- Added handlers for listing, uploading, and downloading message attachments in `internal/api/mail/handlers_attachments.go`.
- Implemented draft management endpoints for creating, updating, and deleting drafts in `internal/api/mail/handlers_drafts.go`.
- Created new service methods for handling draft and attachment operations in `internal/api/mail/drafts.go` and `internal/api/mail/storage.go`.
- Added validation and error handling for draft and attachment operations.
- Included unit tests for draft and folder functionalities in `internal/api/mail/drafts_test.go` and `internal/api/mail/folders_test.go`.
- Updated API routes to support new draft and attachment features, enhancing overall mail management capabilities.
2026-05-22 17:14:36 +02:00

60 lines
1.6 KiB
Go

package storage
import (
"context"
"fmt"
"io"
"net/url"
"time"
"github.com/google/uuid"
"github.com/minio/minio-go/v7"
)
type Client struct {
mc *minio.Client
bucket string
}
func NewClient(mc *minio.Client, bucket string) *Client {
return &Client{mc: mc, bucket: bucket}
}
func (c *Client) EnsureBucket(ctx context.Context) error {
exists, err := c.mc.BucketExists(ctx, c.bucket)
if err != nil {
return err
}
if !exists {
return c.mc.MakeBucket(ctx, c.bucket, minio.MakeBucketOptions{})
}
return nil
}
func (c *Client) Put(ctx context.Context, objectKey string, reader io.Reader, size int64, contentType string) error {
_, err := c.mc.PutObject(ctx, c.bucket, objectKey, reader, size, minio.PutObjectOptions{
ContentType: contentType,
})
return err
}
func (c *Client) Get(ctx context.Context, objectKey string) (*minio.Object, error) {
return c.mc.GetObject(ctx, c.bucket, objectKey, minio.GetObjectOptions{})
}
func (c *Client) Delete(ctx context.Context, objectKey string) error {
return c.mc.RemoveObject(ctx, c.bucket, objectKey, minio.RemoveObjectOptions{})
}
func (c *Client) PresignedGet(ctx context.Context, objectKey string, expiry time.Duration) (*url.URL, error) {
return c.mc.PresignedGetObject(ctx, c.bucket, objectKey, expiry, nil)
}
func MessageObjectKey(userID, messageID, filename string) string {
return fmt.Sprintf("%s/messages/%s/%s/%s", userID, messageID, uuid.NewString(), filename)
}
func DraftObjectKey(userID, draftID, filename string) string {
return fmt.Sprintf("%s/drafts/%s/%s/%s", userID, draftID, uuid.NewString(), filename)
}