188 lines
4.4 KiB
Go
188 lines
4.4 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
type ArtifactTransferDirection string
|
|
|
|
const (
|
|
ArtifactTransferDirectionUpload ArtifactTransferDirection = "upload"
|
|
)
|
|
|
|
type ArtifactTransferOpen struct {
|
|
RunEndpointID string
|
|
SessionToken string
|
|
ArtifactID string
|
|
Direction ArtifactTransferDirection
|
|
OwnerKind ArtifactOwnerKind
|
|
OwnerID string
|
|
SizeBytes int64
|
|
ChunkSizeBytes int
|
|
Checksum string
|
|
IdempotencyKey string
|
|
}
|
|
|
|
type ArtifactTransferOpenResult struct {
|
|
Accepted bool
|
|
TransferID string
|
|
Direction ArtifactTransferDirection
|
|
Artifact Artifact
|
|
TotalChunks int
|
|
ChunkSizeBytes int
|
|
ReceivedChunkIndexes []int
|
|
NextMissingChunkIndex int
|
|
Completed bool
|
|
Duplicate bool
|
|
ServerTime time.Time
|
|
}
|
|
|
|
type ArtifactChunkUpload struct {
|
|
RunEndpointID string
|
|
SessionToken string
|
|
TransferID string
|
|
ArtifactID string
|
|
ChunkIndex int
|
|
Offset int64
|
|
SizeBytes int
|
|
Checksum string
|
|
Payload []byte
|
|
}
|
|
|
|
type ArtifactChunkUploadResult struct {
|
|
Accepted bool
|
|
TransferID string
|
|
ArtifactID string
|
|
ChunkIndex int
|
|
ReceivedChunkIndexes []int
|
|
NextMissingChunkIndex int
|
|
Duplicate bool
|
|
ServerTime time.Time
|
|
}
|
|
|
|
type ArtifactTransferStatusQuery struct {
|
|
RunEndpointID string
|
|
SessionToken string
|
|
TransferID string
|
|
ArtifactID string
|
|
}
|
|
|
|
type ArtifactTransferStatusResult struct {
|
|
Accepted bool
|
|
TransferID string
|
|
ArtifactID string
|
|
Direction ArtifactTransferDirection
|
|
TotalChunks int
|
|
ChunkSizeBytes int
|
|
ReceivedChunkIndexes []int
|
|
NextMissingChunkIndex int
|
|
Completed bool
|
|
ServerTime time.Time
|
|
}
|
|
|
|
type ArtifactTransferComplete struct {
|
|
RunEndpointID string
|
|
SessionToken string
|
|
TransferID string
|
|
ArtifactID string
|
|
Checksum string
|
|
SizeBytes int64
|
|
}
|
|
|
|
type ArtifactTransferCompleteResult struct {
|
|
Accepted bool
|
|
TransferID string
|
|
Artifact Artifact
|
|
Completed bool
|
|
ServerTime time.Time
|
|
}
|
|
|
|
type ArtifactChunkRecord struct {
|
|
ChunkIndex int
|
|
Offset int64
|
|
SizeBytes int
|
|
Checksum string
|
|
Payload []byte
|
|
ReceivedAt time.Time
|
|
}
|
|
|
|
type ArtifactTransferSession struct {
|
|
TransferID string
|
|
RunEndpointID string
|
|
ArtifactID string
|
|
Direction ArtifactTransferDirection
|
|
OwnerKind ArtifactOwnerKind
|
|
OwnerID string
|
|
SizeBytes int64
|
|
ChunkSizeBytes int
|
|
Checksum string
|
|
IdempotencyKey string
|
|
TotalChunks int
|
|
ReceivedChunks map[int]ArtifactChunkRecord
|
|
Completed bool
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func CopyArtifactTransferOpen(open ArtifactTransferOpen) ArtifactTransferOpen {
|
|
return open
|
|
}
|
|
|
|
func CopyArtifactChunkUpload(chunk ArtifactChunkUpload) ArtifactChunkUpload {
|
|
chunk.Payload = CopyBytes(chunk.Payload)
|
|
return chunk
|
|
}
|
|
|
|
func CopyArtifactTransferOpenResult(result ArtifactTransferOpenResult) ArtifactTransferOpenResult {
|
|
result.Artifact = CopyArtifact(result.Artifact)
|
|
result.ReceivedChunkIndexes = CopyIntSlice(result.ReceivedChunkIndexes)
|
|
return result
|
|
}
|
|
|
|
func CopyArtifactChunkUploadResult(result ArtifactChunkUploadResult) ArtifactChunkUploadResult {
|
|
result.ReceivedChunkIndexes = CopyIntSlice(result.ReceivedChunkIndexes)
|
|
return result
|
|
}
|
|
|
|
func CopyArtifactTransferStatusResult(result ArtifactTransferStatusResult) ArtifactTransferStatusResult {
|
|
result.ReceivedChunkIndexes = CopyIntSlice(result.ReceivedChunkIndexes)
|
|
return result
|
|
}
|
|
|
|
func CopyArtifactTransferCompleteResult(result ArtifactTransferCompleteResult) ArtifactTransferCompleteResult {
|
|
result.Artifact = CopyArtifact(result.Artifact)
|
|
return result
|
|
}
|
|
|
|
func CopyArtifactChunkRecord(record ArtifactChunkRecord) ArtifactChunkRecord {
|
|
record.Payload = CopyBytes(record.Payload)
|
|
return record
|
|
}
|
|
|
|
func CopyArtifactTransferSession(session ArtifactTransferSession) ArtifactTransferSession {
|
|
if session.ReceivedChunks != nil {
|
|
chunks := make(map[int]ArtifactChunkRecord, len(session.ReceivedChunks))
|
|
for index, record := range session.ReceivedChunks {
|
|
chunks[index] = CopyArtifactChunkRecord(record)
|
|
}
|
|
session.ReceivedChunks = chunks
|
|
}
|
|
return session
|
|
}
|
|
|
|
func CopyBytes(values []byte) []byte {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
out := make([]byte, len(values))
|
|
copy(out, values)
|
|
return out
|
|
}
|
|
|
|
func CopyIntSlice(values []int) []int {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
out := make([]int, len(values))
|
|
copy(out, values)
|
|
return out
|
|
}
|