35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"kra/internal/modules/system/dto"
|
|
)
|
|
|
|
func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash string, size, chunkSize int64, total int) (*dto.InitUploadResponse, error) {
|
|
session, media, chunks, err := s.uc.InitUpload(ctx, userID, name, hash, size, chunkSize, total)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if media != nil {
|
|
// The compatible response leaves UploadedChunks nil on an instant-upload hit, producing
|
|
// JSON null while still returning uploadId: 0.
|
|
return &dto.InitUploadResponse{Instant: true, Media: mediaDTO(media)}, nil
|
|
}
|
|
return &dto.InitUploadResponse{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) (*dto.MediaResponse, 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)
|
|
}
|