2022-03-15 18:00:53 +00:00
|
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
|
//
|
|
|
|
|
// This program is a free software product.
|
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
|
|
|
|
|
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
|
|
|
|
|
// any third-party rights.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
|
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
|
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
|
//
|
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
|
//
|
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
|
//
|
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
|
//
|
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
|
|
|
|
|
|
namespace ASC.Files.Api;
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
public class OperationController : ApiControllerBase
|
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
private readonly FileOperationDtoHelper _fileOperationDtoHelper;
|
2022-08-04 10:47:18 +00:00
|
|
|
|
private readonly FileStorageService<string> _fileStorageServiceString;
|
|
|
|
|
private readonly FileStorageService<int> _fileStorageService;
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
public OperationController(
|
2022-08-03 14:29:20 +00:00
|
|
|
|
FileOperationDtoHelper fileOperationDtoHelper,
|
|
|
|
|
FileStorageService<string> fileStorageServiceString,
|
|
|
|
|
FolderDtoHelper folderDtoHelper,
|
2022-08-04 10:47:18 +00:00
|
|
|
|
FileDtoHelper fileDtoHelper,
|
|
|
|
|
FileStorageService<int> fileStorageService) : base(folderDtoHelper, fileDtoHelper)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
_fileOperationDtoHelper = fileOperationDtoHelper;
|
2022-08-04 10:47:18 +00:00
|
|
|
|
_fileStorageServiceString = fileStorageServiceString;
|
|
|
|
|
_fileStorageService = fileStorageService;
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Start downlaod process of files and folders with ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Finish file operations</short>
|
|
|
|
|
/// <param name="fileConvertIds" visible="false">File ID list for download with convert to format</param>
|
|
|
|
|
/// <param name="fileIds">File ID list</param>
|
|
|
|
|
/// <param name="folderIds">Folder ID list</param>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/bulkdownload")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> BulkDownload(DownloadRequestDto inDto)
|
|
|
|
|
{
|
|
|
|
|
var folders = new Dictionary<JsonElement, string>();
|
|
|
|
|
var files = new Dictionary<JsonElement, string>();
|
|
|
|
|
|
|
|
|
|
foreach (var fileId in inDto.FileConvertIds.Where(fileId => !files.ContainsKey(fileId.Key)))
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileId.Key, fileId.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var fileId in inDto.FileIds.Where(fileId => !files.ContainsKey(fileId)))
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileId, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var folderId in inDto.FolderIds.Where(folderId => !folders.ContainsKey(folderId)))
|
|
|
|
|
{
|
|
|
|
|
folders.Add(folderId, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var e in _fileStorageServiceString.BulkDownload(folders, files))
|
|
|
|
|
{
|
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Copies all the selected files and folders to the folder with the ID specified in the request
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Copy to folder</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <param name="destFolderId">Destination folder ID</param>
|
|
|
|
|
/// <param name="folderIds">Folder ID list</param>
|
|
|
|
|
/// <param name="fileIds">File ID list</param>
|
|
|
|
|
/// <param name="conflictResolveType">Overwriting behavior: skip(0), overwrite(1) or duplicate(2)</param>
|
|
|
|
|
/// <param name="deleteAfter">Delete after finished</param>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/copy")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> CopyBatchItems(BatchRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
foreach (var e in _fileStorageServiceString.MoveOrCopyItems(inDto.FolderIds.ToList(), inDto.FileIds.ToList(), inDto.DestFolderId, inDto.ConflictResolveType, true, inDto.DeleteAfter))
|
|
|
|
|
{
|
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the files and folders with the IDs specified in the request
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="folderIds">Folder ID list</param>
|
|
|
|
|
/// <param name="fileIds">File ID list</param>
|
|
|
|
|
/// <param name="deleteAfter">Delete after finished</param>
|
|
|
|
|
/// <param name="immediately">Don't move to the Recycle Bin</param>
|
|
|
|
|
/// <short>Delete files and folders</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/delete")]
|
2022-05-17 09:29:24 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> DeleteBatchItems(DeleteBatchRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-03-05 14:41:47 +00:00
|
|
|
|
var tasks = _fileStorageServiceString.DeleteItems("delete", inDto.FileIds.ToList(), inDto.FolderIds.ToList(), false, inDto.DeleteAfter, inDto.Immediately);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
|
|
|
|
|
foreach (var e in tasks)
|
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes all files and folders from the recycle bin
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Clear recycle bin</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/emptytrash")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> EmptyTrashAsync()
|
|
|
|
|
{
|
2022-08-04 10:47:18 +00:00
|
|
|
|
var emptyTrash = await _fileStorageService.EmptyTrashAsync();
|
2022-08-03 14:29:20 +00:00
|
|
|
|
|
|
|
|
|
foreach (var e in emptyTrash)
|
|
|
|
|
{
|
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the list of all active file operations
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Get file operations list</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("fileops")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> GetOperationStatuses()
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var e in _fileStorageServiceString.GetTasksStatuses())
|
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Marks all files and folders as read
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Mark as read</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/markasread")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> MarkAsRead(BaseBatchRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
foreach (var e in _fileStorageServiceString.MarkAsRead(inDto.FolderIds.ToList(), inDto.FileIds.ToList()))
|
|
|
|
|
{
|
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Moves all the selected files and folders to the folder with the ID specified in the request
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Move to folder</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <param name="destFolderId">Destination folder ID</param>
|
|
|
|
|
/// <param name="folderIds">Folder ID list</param>
|
|
|
|
|
/// <param name="fileIds">File ID list</param>
|
|
|
|
|
/// <param name="conflictResolveType">Overwriting behavior: skip(0), overwrite(1) or duplicate(2)</param>
|
|
|
|
|
/// <param name="deleteAfter">Delete after finished</param>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/move")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> MoveBatchItems(BatchRequestDto inDto)
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
foreach (var e in _fileStorageServiceString.MoveOrCopyItems(inDto.FolderIds.ToList(), inDto.FileIds.ToList(), inDto.DestFolderId, inDto.ConflictResolveType, false, inDto.DeleteAfter))
|
|
|
|
|
{
|
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checking for conflicts
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <param name="destFolderId">Destination folder ID</param>
|
|
|
|
|
/// <param name="folderIds">Folder ID list</param>
|
|
|
|
|
/// <param name="fileIds">File ID list</param>
|
|
|
|
|
/// <returns>Conflicts file ids</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("fileops/move")]
|
2022-08-03 14:29:20 +00:00
|
|
|
|
public async IAsyncEnumerable<FileEntryDto> MoveOrCopyBatchCheckAsync([ModelBinder(BinderType = typeof(BatchModelBinder))] BatchRequestDto inDto)
|
|
|
|
|
{
|
|
|
|
|
List<object> checkedFiles;
|
|
|
|
|
List<object> checkedFolders;
|
|
|
|
|
|
|
|
|
|
if (inDto.DestFolderId.ValueKind == JsonValueKind.Number)
|
|
|
|
|
{
|
|
|
|
|
(checkedFiles, checkedFolders) = await _fileStorageServiceString.MoveOrCopyFilesCheckAsync(inDto.FileIds.ToList(), inDto.FolderIds.ToList(), inDto.DestFolderId.GetInt32());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(checkedFiles, checkedFolders) = await _fileStorageServiceString.MoveOrCopyFilesCheckAsync(inDto.FileIds.ToList(), inDto.FolderIds.ToList(), inDto.DestFolderId.GetString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entries = await _fileStorageServiceString.GetItemsAsync(checkedFiles.OfType<int>().Select(Convert.ToInt32), checkedFiles.OfType<int>().Select(Convert.ToInt32), FilterType.FilesOnly, false, "", "");
|
|
|
|
|
|
|
|
|
|
entries.AddRange(await _fileStorageServiceString.GetItemsAsync(checkedFiles.OfType<string>(), checkedFiles.OfType<string>(), FilterType.FilesOnly, false, "", ""));
|
|
|
|
|
|
|
|
|
|
foreach (var e in entries)
|
|
|
|
|
{
|
|
|
|
|
yield return await GetFileEntryWrapperAsync(e);
|
|
|
|
|
}
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finishes all the active file operations
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <short>Finish all</short>
|
|
|
|
|
/// <category>File operations</category>
|
|
|
|
|
/// <returns>Operation result</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("fileops/terminate")]
|
2022-03-04 10:25:12 +00:00
|
|
|
|
public async IAsyncEnumerable<FileOperationDto> TerminateTasks()
|
2022-03-03 17:33:11 +00:00
|
|
|
|
{
|
|
|
|
|
var tasks = _fileStorageServiceString.TerminateTasks();
|
|
|
|
|
|
|
|
|
|
foreach (var e in tasks)
|
|
|
|
|
{
|
2022-08-03 14:29:20 +00:00
|
|
|
|
yield return await _fileOperationDtoHelper.GetAsync(e);
|
2022-03-03 17:33:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|