diff --git a/mobilesdk/zbox/storage.go b/mobilesdk/zbox/storage.go index 2dc193193..3e88bb6ef 100644 --- a/mobilesdk/zbox/storage.go +++ b/mobilesdk/zbox/storage.go @@ -26,13 +26,14 @@ type MultiOperationOption struct { } type MultiUploadOption struct { - FilePath string `json:"filePath,omitempty"` - FileName string `json:"fileName,omitempty"` - RemotePath string `json:"remotePath,omitempty"` - ThumbnailPath string `json:"thumbnailPath,omitempty"` - Encrypt bool `json:"encrypt,omitempty"` - ChunkNumber int `json:"chunkNumber,omitempty"` - IsUpdate bool `json:"isUpdate,omitempty"` + FilePath string `json:"filePath,omitempty"` + FileName string `json:"fileName,omitempty"` + RemotePath string `json:"remotePath,omitempty"` + ThumbnailPath string `json:"thumbnailPath,omitempty"` + Encrypt bool `json:"encrypt,omitempty"` + ChunkNumber int `json:"chunkNumber,omitempty"` + IsUpdate bool `json:"isUpdate,omitempty"` + IsWebstreaming bool `json:"isWebstreaming,omitempty"` } type MultiDownloadOption struct { @@ -336,6 +337,7 @@ func MultiUpload(allocationID string, workdir string, jsonMultiUploadOptions str encrypts := make([]bool, totalUploads) chunkNumbers := make([]int, totalUploads) isUpdates := make([]bool, totalUploads) + isWebstreaming := make([]bool, totalUploads) for idx, option := range options { filePaths[idx] = option.FilePath fileNames[idx] = option.FileName @@ -344,13 +346,14 @@ func MultiUpload(allocationID string, workdir string, jsonMultiUploadOptions str chunkNumbers[idx] = option.ChunkNumber encrypts[idx] = option.Encrypt isUpdates[idx] = false + isWebstreaming[idx] = option.IsWebstreaming } a, err := getAllocation(allocationID) if err != nil { return err } - return a.StartMultiUpload(workdir, filePaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdates, &StatusCallbackWrapped{Callback: statusCb}) + return a.StartMultiUpload(workdir, filePaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdates, isWebstreaming, &StatusCallbackWrapped{Callback: statusCb}) } @@ -373,6 +376,7 @@ func MultiUpdate(allocationID string, workdir string, jsonMultiUploadOptions str encrypts := make([]bool, totalUploads) chunkNumbers := make([]int, totalUploads) isUpdates := make([]bool, totalUploads) + isWebstreaming := make([]bool, totalUploads) for idx, option := range options { filePaths[idx] = option.FilePath fileNames[idx] = option.FileName @@ -381,6 +385,7 @@ func MultiUpdate(allocationID string, workdir string, jsonMultiUploadOptions str chunkNumbers[idx] = option.ChunkNumber encrypts[idx] = option.Encrypt isUpdates[idx] = true + isWebstreaming[idx] = option.IsWebstreaming } if err != nil { return err @@ -390,7 +395,7 @@ func MultiUpdate(allocationID string, workdir string, jsonMultiUploadOptions str if err != nil { return err } - return a.StartMultiUpload(workdir, filePaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdates, &StatusCallbackWrapped{Callback: statusCb}) + return a.StartMultiUpload(workdir, filePaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdates, isWebstreaming, &StatusCallbackWrapped{Callback: statusCb}) } diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 7b06e9121..e7a6b110f 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -475,6 +475,7 @@ type BulkUploadOption struct { Webstreaming bool `json:"webstreaming,omitempty"` IsUpdate bool `json:"isUpdate,omitempty"` IsRepair bool `json:"isRepair,omitempty"` + IsWebstreaming bool `json:"isWebstreaming,omitempty"` NumBlocks int `json:"numBlocks,omitempty"` FileSize int64 `json:"fileSize,omitempty"` @@ -671,11 +672,12 @@ func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) { sdk.WithChunkNumber(numBlocks), } operationRequests[idx] = sdk.OperationRequest{ - FileMeta: fileMeta, - FileReader: fileReader, - OperationType: FileOperationInsert, - Opts: options, - Workdir: "/", + FileMeta: fileMeta, + FileReader: fileReader, + OperationType: FileOperationInsert, + Opts: options, + Workdir: "/", + IsWebstreaming: option.IsWebstreaming, } } diff --git a/winsdk/models.go b/winsdk/models.go index 8fb2723d7..ef86b5238 100644 --- a/winsdk/models.go +++ b/winsdk/models.go @@ -5,9 +5,10 @@ type UploadFile struct { Path string ThumbnailPath string - RemotePath string - Encrypt bool - IsUpdate bool + RemotePath string + Encrypt bool + IsUpdate bool + IsWebstreaming bool ChunkNumber int } diff --git a/winsdk/storage.go b/winsdk/storage.go index 00ffb40ad..005c3798f 100644 --- a/winsdk/storage.go +++ b/winsdk/storage.go @@ -163,13 +163,14 @@ type MultiOperationOption struct { } type MultiUploadOption struct { - FilePath string `json:"filePath,omitempty"` - FileName string `json:"fileName,omitempty"` - RemotePath string `json:"remotePath,omitempty"` - ThumbnailPath string `json:"thumbnailPath,omitempty"` - Encrypt bool `json:"encrypt,omitempty"` - ChunkNumber int `json:"chunkNumber,omitempty"` - IsUpdate bool `json:"isUpdate,omitempty"` + FilePath string `json:"filePath,omitempty"` + FileName string `json:"fileName,omitempty"` + RemotePath string `json:"remotePath,omitempty"` + ThumbnailPath string `json:"thumbnailPath,omitempty"` + Encrypt bool `json:"encrypt,omitempty"` + ChunkNumber int `json:"chunkNumber,omitempty"` + IsUpdate bool `json:"isUpdate,omitempty"` + IsWebstreaming bool `json:"isWebstreaming,omitempty"` } // MultiOperation - do copy, move, delete and createdir operation together @@ -323,6 +324,7 @@ func BulkUpload(uploadID, allocationID, files *C.char) *C.char { chunkNumbers := make([]int, totalUploads) encrypts := make([]bool, totalUploads) isUpdates := make([]bool, totalUploads) + isWebstreaming := make([]bool, totalUploads) statusBar := &StatusCallback{ status: make(map[string]*Status), @@ -335,6 +337,7 @@ func BulkUpload(uploadID, allocationID, files *C.char) *C.char { remotePaths[idx] = option.RemotePath chunkNumbers[idx] = option.ChunkNumber isUpdates[idx] = option.IsUpdate + isWebstreaming[idx] = option.IsWebstreaming encrypts[idx] = option.Encrypt statusBar.status[option.RemotePath+option.Name] = &Status{} } @@ -346,7 +349,7 @@ func BulkUpload(uploadID, allocationID, files *C.char) *C.char { statusCaches.Add(C.GoString(uploadID), statusBar) - err = a.StartMultiUpload(workdir, filePaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdates, statusBar) + err = a.StartMultiUpload(workdir, filePaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdates, isWebstreaming, statusBar) if err != nil { return WithJSON(nil, err) } diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 809febafc..30b84d973 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -208,12 +208,13 @@ type Allocation struct { } type OperationRequest struct { - OperationType string - LocalPath string - RemotePath string - DestName string // Required only for rename operation - DestPath string // Required for copy and move operation - IsUpdate bool + OperationType string + LocalPath string + RemotePath string + DestName string // Required only for rename operation + DestPath string // Required for copy and move operation + IsUpdate bool + IsWebstreaming bool // Required for uploads Workdir string @@ -495,7 +496,7 @@ func (a *Allocation) EncryptAndUploadFileWithThumbnail( ) } -func (a *Allocation) StartMultiUpload(workdir string, localPaths []string, fileNames []string, thumbnailPaths []string, encrypts []bool, chunkNumbers []int, remotePaths []string, isUpdate []bool, status StatusCallback) error { +func (a *Allocation) StartMultiUpload(workdir string, localPaths []string, fileNames []string, thumbnailPaths []string, encrypts []bool, chunkNumbers []int, remotePaths []string, isUpdate []bool, isWebstreaming []bool, status StatusCallback) error { if len(localPaths) != len(thumbnailPaths) { return errors.New("invalid_value", "length of localpaths and thumbnailpaths must be equal") } @@ -588,6 +589,9 @@ func (a *Allocation) StartMultiUpload(workdir string, localPaths []string, fileN if isUpdate[idx] { operationRequests[idx].OperationType = constants.FileOperationUpdate } + if isWebstreaming[idx] { + operationRequests[idx].IsWebstreaming = true + } } err := a.DoMultiOperation(operationRequests) @@ -873,13 +877,13 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest) error { operation = NewMoveOperation(op.RemotePath, op.DestPath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx) case constants.FileOperationInsert: - operation = NewUploadOperation(op.Workdir, op.FileMeta, op.FileReader, false, op.Opts...) + operation = NewUploadOperation(op.Workdir, op.FileMeta, op.FileReader, false, op.IsWebstreaming, op.Opts...) case constants.FileOperationDelete: operation = NewDeleteOperation(op.RemotePath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx) case constants.FileOperationUpdate: - operation = NewUploadOperation(op.Workdir, op.FileMeta, op.FileReader, true, op.Opts...) + operation = NewUploadOperation(op.Workdir, op.FileMeta, op.FileReader, true, op.IsWebstreaming, op.Opts...) case constants.FileOperationCreateDir: operation = NewDirOperation(op.RemotePath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx) diff --git a/zboxcore/sdk/upload_worker.go b/zboxcore/sdk/upload_worker.go index f548ab1e5..5e90ec375 100644 --- a/zboxcore/sdk/upload_worker.go +++ b/zboxcore/sdk/upload_worker.go @@ -19,12 +19,13 @@ type UploadOperation struct { opts []ChunkedUploadOption refs []*fileref.FileRef isUpdate bool + isWebstreaming bool statusCallback StatusCallback opCode int } func (uo *UploadOperation) Process(allocObj *Allocation, connectionID string) ([]fileref.RefEntity, zboxutil.Uint128, error) { - cu, err := CreateChunkedUpload(uo.workdir, allocObj, uo.fileMeta, uo.fileReader, uo.isUpdate, false, false, connectionID, uo.opts...) + cu, err := CreateChunkedUpload(uo.workdir, allocObj, uo.fileMeta, uo.fileReader, uo.isUpdate, false, uo.isWebstreaming, connectionID, uo.opts...) if err != nil { uploadMask := zboxutil.NewUint128(1).Lsh(uint64(len(allocObj.Blobbers))).Sub64(1) return nil, uploadMask, err @@ -123,12 +124,13 @@ func (uo *UploadOperation) Error(allocObj *Allocation, consensus int, err error) } } -func NewUploadOperation(workdir string, fileMeta FileMeta, fileReader io.Reader, isUpdate bool, opts ...ChunkedUploadOption) *UploadOperation { +func NewUploadOperation(workdir string, fileMeta FileMeta, fileReader io.Reader, isUpdate, isWebstreaming bool, opts ...ChunkedUploadOption) *UploadOperation { uo := &UploadOperation{} uo.workdir = workdir uo.fileMeta = fileMeta uo.fileReader = fileReader uo.opts = opts uo.isUpdate = isUpdate + uo.isWebstreaming = isWebstreaming return uo }