namespace ASC.Files.Api; public class OperationController : ApiControllerBase { private readonly FileOperationDtoHelper _fileOperationWraperHelper; private readonly FileStorageService _fileStorageServiceString; private readonly OperationControllerHelper _operationControllerHelperString; private readonly OperationControllerHelper _operationControllerHelperInt; public OperationController( FileOperationDtoHelper fileOperationWraperHelper, FileStorageService fileStorageServiceString, OperationControllerHelper operationControllerHelperString, OperationControllerHelper operationControllerHelperInt) { _fileOperationWraperHelper = fileOperationWraperHelper; _fileStorageServiceString = fileStorageServiceString; _operationControllerHelperString = operationControllerHelperString; _operationControllerHelperInt = operationControllerHelperInt; } /// /// Start downlaod process of files and folders with ID /// /// Finish file operations /// File ID list for download with convert to format /// File ID list /// Folder ID list /// File operations /// Operation result [Update("fileops/bulkdownload")] public Task> BulkDownload([FromBody] DownloadRequestDto inDto) { return _operationControllerHelperString.BulkDownloadAsync(inDto); } [Update("fileops/bulkdownload")] [Consumes("application/x-www-form-urlencoded")] public Task> BulkDownloadFromForm([FromForm][ModelBinder(BinderType = typeof(DownloadModelBinder))] DownloadRequestDto inDto) { return _operationControllerHelperString.BulkDownloadAsync(inDto); } /// /// Copies all the selected files and folders to the folder with the ID specified in the request /// /// Copy to folder /// File operations /// Destination folder ID /// Folder ID list /// File ID list /// Overwriting behavior: skip(0), overwrite(1) or duplicate(2) /// Delete after finished /// Operation result [Update("fileops/copy")] public Task> CopyBatchItemsFromBody([FromBody] BatchRequestDto inDto) { return _operationControllerHelperString.CopyBatchItemsAsync(inDto); } [Update("fileops/copy")] [Consumes("application/x-www-form-urlencoded")] public Task> CopyBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(BatchModelBinder))] BatchRequestDto inDto) { return _operationControllerHelperString.CopyBatchItemsAsync(inDto); } /// /// Deletes the files and folders with the IDs specified in the request /// /// Folder ID list /// File ID list /// Delete after finished /// Don't move to the Recycle Bin /// Delete files and folders /// File operations /// Operation result [Update("fileops/delete")] public async IAsyncEnumerable DeleteBatchItemsFromBody([FromBody] DeleteBatchRequestDto inDto) { var tasks = _fileStorageServiceString.DeleteItems("delete", inDto.FileIds.ToList(), inDto.FolderIds.ToList(), false, inDto.DeleteAfter, inDto.Immediately); foreach (var e in tasks) { yield return await _fileOperationWraperHelper.GetAsync(e); } } [Update("fileops/delete")] [Consumes("application/x-www-form-urlencoded")] public async IAsyncEnumerable DeleteBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(DeleteBatchModelBinder))] DeleteBatchRequestDto inDto) { var tasks = _fileStorageServiceString.DeleteItems("delete", inDto.FileIds.ToList(), inDto.FolderIds.ToList(), false, inDto.DeleteAfter, inDto.Immediately); foreach (var e in tasks) { yield return await _fileOperationWraperHelper.GetAsync(e); } } /// /// Deletes all files and folders from the recycle bin /// /// Clear recycle bin /// File operations /// Operation result [Update("fileops/emptytrash")] public Task> EmptyTrashAsync() { return _operationControllerHelperInt.EmptyTrashAsync(); } /// /// Returns the list of all active file operations /// /// Get file operations list /// File operations /// Operation result [Read("fileops")] public async Task> GetOperationStatuses() { var result = new List(); foreach (var e in _fileStorageServiceString.GetTasksStatuses()) { result.Add(await _fileOperationWraperHelper.GetAsync(e)); } return result; } /// /// Marks all files and folders as read /// /// Mark as read /// File operations /// Operation result [Update("fileops/markasread")] public Task> MarkAsReadFromBody([FromBody] BaseBatchRequestDto inDto) { return _operationControllerHelperString.MarkAsReadAsync(inDto); } [Update("fileops/markasread")] [Consumes("application/x-www-form-urlencoded")] public Task> MarkAsReadFromForm([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchRequestDto inDto) { return _operationControllerHelperString.MarkAsReadAsync(inDto); } /// /// Moves all the selected files and folders to the folder with the ID specified in the request /// /// Move to folder /// File operations /// Destination folder ID /// Folder ID list /// File ID list /// Overwriting behavior: skip(0), overwrite(1) or duplicate(2) /// Delete after finished /// Operation result [Update("fileops/move")] public Task> MoveBatchItemsFromBody([FromBody] BatchRequestDto inDto) { return _operationControllerHelperString.MoveBatchItemsAsync(inDto); } [Update("fileops/move")] [Consumes("application/x-www-form-urlencoded")] public Task> MoveBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(BatchModelBinder))] BatchRequestDto inDto) { return _operationControllerHelperString.MoveBatchItemsAsync(inDto); } /// /// Checking for conflicts /// /// File operations /// Destination folder ID /// Folder ID list /// File ID list /// Conflicts file ids [Read("fileops/move")] public IAsyncEnumerable MoveOrCopyBatchCheckAsync([ModelBinder(BinderType = typeof(BatchModelBinder))] BatchRequestDto inDto) { return _operationControllerHelperString.MoveOrCopyBatchCheckAsync(inDto); } /// /// Finishes all the active file operations /// /// Finish all /// File operations /// Operation result [Update("fileops/terminate")] public async IAsyncEnumerable TerminateTasks() { var tasks = _fileStorageServiceString.TerminateTasks(); foreach (var e in tasks) { yield return await _fileOperationWraperHelper.GetAsync(e); } } }