93 lines
2.2 KiB
Go
93 lines
2.2 KiB
Go
package blob
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"mime/multipart"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/bus"
|
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
|
"github.com/oklog/ulid/v2"
|
|
)
|
|
|
|
const (
|
|
MessageNamespaceUploadRequest bus.MessageNamespace = "uploadRequest"
|
|
MessageNamespaceUploadResponse bus.MessageNamespace = "uploadResponse"
|
|
MessageNamespaceDownloadRequest bus.MessageNamespace = "downloadRequest"
|
|
MessageNamespaceDownloadResponse bus.MessageNamespace = "downloadResponse"
|
|
)
|
|
|
|
type MessageUploadRequest struct {
|
|
Context context.Context
|
|
RequestID string
|
|
FileHeader *multipart.FileHeader
|
|
Metadata map[string]interface{}
|
|
}
|
|
|
|
func (m *MessageUploadRequest) MessageNamespace() bus.MessageNamespace {
|
|
return MessageNamespaceUploadRequest
|
|
}
|
|
|
|
func NewMessageUploadRequest(ctx context.Context, fileHeader *multipart.FileHeader, metadata map[string]interface{}) *MessageUploadRequest {
|
|
return &MessageUploadRequest{
|
|
Context: ctx,
|
|
RequestID: ulid.Make().String(),
|
|
FileHeader: fileHeader,
|
|
Metadata: metadata,
|
|
}
|
|
}
|
|
|
|
type MessageUploadResponse struct {
|
|
RequestID string
|
|
BlobID storage.BlobID
|
|
Bucket string
|
|
Allow bool
|
|
}
|
|
|
|
func (m *MessageUploadResponse) MessageNamespace() bus.MessageNamespace {
|
|
return MessageNamespaceDownloadResponse
|
|
}
|
|
|
|
func NewMessageUploadResponse(requestID string) *MessageUploadResponse {
|
|
return &MessageUploadResponse{
|
|
RequestID: requestID,
|
|
}
|
|
}
|
|
|
|
type MessageDownloadRequest struct {
|
|
Context context.Context
|
|
RequestID string
|
|
Bucket string
|
|
BlobID storage.BlobID
|
|
}
|
|
|
|
func (m *MessageDownloadRequest) MessageNamespace() bus.MessageNamespace {
|
|
return MessageNamespaceDownloadRequest
|
|
}
|
|
|
|
func NewMessageDownloadRequest(ctx context.Context, bucket string, blobID storage.BlobID) *MessageDownloadRequest {
|
|
return &MessageDownloadRequest{
|
|
Context: ctx,
|
|
RequestID: ulid.Make().String(),
|
|
Bucket: bucket,
|
|
BlobID: blobID,
|
|
}
|
|
}
|
|
|
|
type MessageDownloadResponse struct {
|
|
RequestID string
|
|
Allow bool
|
|
BlobInfo storage.BlobInfo
|
|
Blob io.ReadSeekCloser
|
|
}
|
|
|
|
func (m *MessageDownloadResponse) MessageNamespace() bus.MessageNamespace {
|
|
return MessageNamespaceDownloadResponse
|
|
}
|
|
|
|
func NewMessageDownloadResponse(requestID string) *MessageDownloadResponse {
|
|
return &MessageDownloadResponse{
|
|
RequestID: requestID,
|
|
}
|
|
}
|