31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash string, size, chunkSize int64, total int) (map[string]any, error) {
|
|
session, media, chunks, err := s.uc.InitUpload(ctx, userID, name, hash, size, chunkSize, total)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if media != nil {
|
|
return map[string]any{"instant": true, "media": mediaDTO(media), "uploadedChunks": []int{}}, nil
|
|
}
|
|
return map[string]any{"instant": false, "uploadId": session.ID, "uploadedChunks": chunks, "media": nil}, nil
|
|
}
|
|
func (s *MediaService) SaveChunk(ctx context.Context, userID, uploadID uint, index int, hash string, reader io.Reader) error {
|
|
return s.uc.SaveChunk(ctx, userID, uploadID, index, hash, reader)
|
|
}
|
|
func (s *MediaService) CompleteUpload(ctx context.Context, userID, uploadID uint) (map[string]any, error) {
|
|
v, err := s.uc.CompleteUpload(ctx, userID, uploadID, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return mediaDTO(v), nil
|
|
}
|
|
func (s *MediaService) CancelUpload(ctx context.Context, userID, uploadID uint) error {
|
|
return s.uc.CancelUpload(ctx, userID, uploadID)
|
|
}
|