namespace ASC.Files.Api; [ConstraintRoute("int")] public class FilesControllerInternal : FilesController { public FilesControllerInternal(IServiceProvider serviceProvider, FilesControllerHelper filesControllerHelper) : base(serviceProvider, filesControllerHelper) { } } public class FilesControllerThirdparty : FilesController { public FilesControllerThirdparty(IServiceProvider serviceProvider, FilesControllerHelper filesControllerHelper) : base(serviceProvider, filesControllerHelper) { } } public abstract class FilesController : ApiControllerBase { private readonly IServiceProvider _serviceProvider; private readonly FilesControllerHelper _filesControllerHelper; public FilesController( IServiceProvider serviceProvider, FilesControllerHelper filesControllerHelper) { _serviceProvider = serviceProvider; _filesControllerHelper = filesControllerHelper; } /// /// Change version history /// /// File ID /// Version of history /// Mark as version or revision /// Files /// [Update("file/{fileId}/history")] public Task>> ChangeHistoryFromBodyAsync(T fileId, [FromBody] ChangeHistoryRequestDto inDto) { return _filesControllerHelper.ChangeHistoryAsync(fileId, inDto.Version, inDto.ContinueVersion); } [Update("file/{fileId}/history")] [Consumes("application/x-www-form-urlencoded")] public Task>> ChangeHistoryFromFormAsync(T fileId, [FromForm] ChangeHistoryRequestDto inDto) { return _filesControllerHelper.ChangeHistoryAsync(fileId, inDto.Version, inDto.ContinueVersion); } /// /// Check conversion status /// /// Convert /// File operations /// /// /// Operation result [Read("file/{fileId}/checkconversion")] public IAsyncEnumerable> CheckConversionAsync(T fileId, bool start) { return _filesControllerHelper.CheckConversionAsync(new CheckConversionRequestDto() { FileId = fileId, StartConvert = start }); } [Create("file/{fileId}/copyas", order: int.MaxValue)] public object CopyFileAsFromBody(T fileId, [FromBody] CopyAsRequestDto inDto) { return CopyFile(fileId, inDto); } [Create("file/{fileId}/copyas", order: int.MaxValue)] [Consumes("application/x-www-form-urlencoded")] public object CopyFileAsFromForm(T fileId, [FromForm] CopyAsRequestDto inDto) { return CopyFile(fileId, inDto); } /// /// Creates a new file in the specified folder with the title sent in the request /// /// Create file /// File Creation /// Folder ID /// File title /// In case the extension for the file title differs from DOCX/XLSX/PPTX and belongs to one of the known text, spreadsheet or presentation formats, it will be changed to DOCX/XLSX/PPTX accordingly. If the file extension is not set or is unknown, the DOCX extension will be added to the file title. /// New file info [Create("{folderId}/file")] public Task> CreateFileFromBodyAsync(T folderId, [FromBody] CreateFileRequestDto inDto) { return _filesControllerHelper.CreateFileAsync(folderId, inDto.Title, inDto.TemplateId, inDto.EnableExternalExt); } [Create("{folderId}/file")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFileFromFormAsync(T folderId, [FromForm] CreateFileRequestDto inDto) { return _filesControllerHelper.CreateFileAsync(folderId, inDto.Title, inDto.TemplateId, inDto.EnableExternalExt); } /// /// Creates an html (.html) file in the selected folder with the title and contents sent in the request /// /// Create html /// File Creation /// Folder ID /// File title /// File contents /// Folder contents [Create("{folderId}/html")] public Task> CreateHtmlFileFromBodyAsync(T folderId, [FromBody] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelper.CreateHtmlFileAsync(folderId, inDto.Title, inDto.Content); } [Create("{folderId}/html")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateHtmlFileFromFormAsync(T folderId, [FromForm] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelper.CreateHtmlFileAsync(folderId, inDto.Title, inDto.Content); } /// /// Creates a text (.txt) file in the selected folder with the title and contents sent in the request /// /// Create txt /// File Creation /// Folder ID /// File title /// File contents /// Folder contents [Create("{folderId}/text")] public Task> CreateTextFileFromBodyAsync(T folderId, [FromBody] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelper.CreateTextFileAsync(folderId, inDto.Title, inDto.Content); } [Create("{folderId}/text")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateTextFileFromFormAsync(T folderId, [FromForm] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelper.CreateTextFileAsync(folderId, inDto.Title, inDto.Content); } /// /// Deletes the file with the ID specified in the request /// /// Delete file /// Files /// File ID /// Delete after finished /// Don't move to the Recycle Bin /// Operation result [Delete("file/{fileId}", order: int.MaxValue, DisableFormat = true)] public Task> DeleteFile(T fileId, [FromBody] DeleteRequestDto inDto) { return _filesControllerHelper.DeleteFileAsync(fileId, inDto.DeleteAfter, inDto.Immediately); } [AllowAnonymous] [Read("file/{fileId}/edit/diff")] public Task GetEditDiffUrlAsync(T fileId, int version = 0, string doc = null) { return _filesControllerHelper.GetEditDiffUrlAsync(fileId, version, doc); } [AllowAnonymous] [Read("file/{fileId}/edit/history")] public Task> GetEditHistoryAsync(T fileId, string doc = null) { return _filesControllerHelper.GetEditHistoryAsync(fileId, doc); } /// /// Returns a detailed information about the file with the ID specified in the request /// /// File information /// Files /// File info [Read("file/{fileId}", order: int.MaxValue, DisableFormat = true)] public Task> GetFileInfoAsync(T fileId, int version = -1) { return _filesControllerHelper.GetFileInfoAsync(fileId, version); } /// /// Returns the detailed information about all the available file versions with the ID specified in the request /// /// File versions /// Files /// File ID /// File information [Read("file/{fileId}/history")] public Task>> GetFileVersionInfoAsync(T fileId) { return _filesControllerHelper.GetFileVersionInfoAsync(fileId); } [Update("file/{fileId}/lock")] public Task> LockFileFromBodyAsync(T fileId, [FromBody] LockFileRequestDto inDto) { return _filesControllerHelper.LockFileAsync(fileId, inDto.LockFile); } [Update("file/{fileId}/lock")] [Consumes("application/x-www-form-urlencoded")] public Task> LockFileFromFormAsync(T fileId, [FromForm] LockFileRequestDto inDto) { return _filesControllerHelper.LockFileAsync(fileId, inDto.LockFile); } [AllowAnonymous] [Read("file/{fileId}/restoreversion")] public Task> RestoreVersionAsync(T fileId, int version = 0, string url = null, string doc = null) { return _filesControllerHelper.RestoreVersionAsync(fileId, version, url, doc); } /// /// Start conversion /// /// Convert /// File operations /// /// Operation result [Update("file/{fileId}/checkconversion")] public IAsyncEnumerable> StartConversion(T fileId, [FromBody(EmptyBodyBehavior = Microsoft.AspNetCore.Mvc.ModelBinding.EmptyBodyBehavior.Allow)] CheckConversionRequestDto inDto) { if (inDto == null) { inDto = new CheckConversionRequestDto(); } inDto.FileId = fileId; return _filesControllerHelper.StartConversionAsync(inDto); } [Update("file/{fileId}/comment")] public async Task UpdateCommentFromBodyAsync(T fileId, [FromBody] UpdateCommentRequestDto inDto) { return await _filesControllerHelper.UpdateCommentAsync(fileId, inDto.Version, inDto.Comment); } [Update("file/{fileId}/comment")] [Consumes("application/x-www-form-urlencoded")] public async Task UpdateCommentFromFormAsync(T fileId, [FromForm] UpdateCommentRequestDto inDto) { return await _filesControllerHelper.UpdateCommentAsync(fileId, inDto.Version, inDto.Comment); } /// /// Updates the information of the selected file with the parameters specified in the request /// /// Update file info /// Files /// File ID /// New title /// File last version number /// File info [Update("file/{fileId}", order: int.MaxValue, DisableFormat = true)] public Task> UpdateFileFromBodyAsync(T fileId, [FromBody] UpdateFileRequestDto inDto) { return _filesControllerHelper.UpdateFileAsync(fileId, inDto.Title, inDto.LastVersion); } [Update("file/{fileId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> UpdateFileFromFormAsync(T fileId, [FromForm] UpdateFileRequestDto inDto) { return _filesControllerHelper.UpdateFileAsync(fileId, inDto.Title, inDto.LastVersion); } /// /// /// /// /// /// /// /// false [Update("{fileId}/update")] public Task> UpdateFileStreamFromFormAsync(T fileId, [FromForm] FileStreamRequestDto inDto) { return _filesControllerHelper.UpdateFileStreamAsync(_filesControllerHelper.GetFileFromRequest(inDto).OpenReadStream(), fileId, inDto.FileExtension, inDto.Encrypted, inDto.Forcesave); } private object CopyFile(T fileId, CopyAsRequestDto inDto) { var helper = _serviceProvider.GetService>(); if (inDto.DestFolderId.ValueKind == JsonValueKind.Number) { return helper.CopyFileAsAsync(fileId, inDto.DestFolderId.GetInt32(), inDto.DestTitle, inDto.Password); } else if (inDto.DestFolderId.ValueKind == JsonValueKind.String) { return helper.CopyFileAsAsync(fileId, inDto.DestFolderId.GetString(), inDto.DestTitle, inDto.Password); } return null; } } public class FilesControllerCommon : ApiControllerBase { private readonly GlobalFolderHelper _globalFolderHelper; private readonly FileStorageService _fileStorageServiceThirdparty; private readonly FilesControllerHelper _filesControllerHelperInternal; public FilesControllerCommon( GlobalFolderHelper globalFolderHelper, FileStorageService fileStorageServiceThirdparty, FilesControllerHelper filesControllerHelperInternal) { _globalFolderHelper = globalFolderHelper; _fileStorageServiceThirdparty = fileStorageServiceThirdparty; _filesControllerHelperInternal = filesControllerHelperInternal; } /// /// Creates a new file in the 'My Documents' section with the title sent in the request /// /// Create file /// File Creation /// File title /// In case the extension for the file title differs from DOCX/XLSX/PPTX and belongs to one of the known text, spreadsheet or presentation formats, it will be changed to DOCX/XLSX/PPTX accordingly. If the file extension is not set or is unknown, the DOCX extension will be added to the file title. /// New file info [Create("@my/file")] public Task> CreateFileFromBodyAsync([FromBody] CreateFileRequestDto inDto) { return _filesControllerHelperInternal.CreateFileAsync(_globalFolderHelper.FolderMy, inDto.Title, inDto.TemplateId, inDto.EnableExternalExt); } [Create("@my/file")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFileFromFormAsync([FromForm] CreateFileRequestDto inDto) { return _filesControllerHelperInternal.CreateFileAsync(_globalFolderHelper.FolderMy, inDto.Title, inDto.TemplateId, inDto.EnableExternalExt); } /// /// Creates an html (.html) file in 'Common Documents' section with the title and contents sent in the request /// /// Create html in 'Common' /// File Creation /// File title /// File contents /// Folder contents [Create("@common/html")] public async Task> CreateHtmlFileInCommonFromBodyAsync([FromBody] CreateTextOrHtmlFileRequestDto inDto) { return await _filesControllerHelperInternal.CreateHtmlFileAsync(await _globalFolderHelper.FolderCommonAsync, inDto.Title, inDto.Content); } [Create("@common/html")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateHtmlFileInCommonFromFormAsync([FromForm] CreateTextOrHtmlFileRequestDto inDto) { return await _filesControllerHelperInternal.CreateHtmlFileAsync(await _globalFolderHelper.FolderCommonAsync, inDto.Title, inDto.Content); } /// /// Creates an html (.html) file in 'My Documents' section with the title and contents sent in the request /// /// Create html in 'My' /// File Creation /// File title /// File contents /// Folder contents [Create("@my/html")] public Task> CreateHtmlFileInMyFromBodyAsync([FromBody] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelperInternal.CreateHtmlFileAsync(_globalFolderHelper.FolderMy, inDto.Title, inDto.Content); } [Create("@my/html")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateHtmlFileInMyFromFormAsync([FromForm] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelperInternal.CreateHtmlFileAsync(_globalFolderHelper.FolderMy, inDto.Title, inDto.Content); } /// /// Creates a text (.txt) file in 'Common Documents' section with the title and contents sent in the request /// /// Create txt in 'Common' /// File Creation /// File title /// File contents /// Folder contents [Create("@common/text")] public async Task> CreateTextFileInCommonFromBodyAsync([FromBody] CreateTextOrHtmlFileRequestDto inDto) { return await _filesControllerHelperInternal.CreateTextFileAsync(await _globalFolderHelper.FolderCommonAsync, inDto.Title, inDto.Content); } [Create("@common/text")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateTextFileInCommonFromFormAsync([FromForm] CreateTextOrHtmlFileRequestDto inDto) { return await _filesControllerHelperInternal.CreateTextFileAsync(await _globalFolderHelper.FolderCommonAsync, inDto.Title, inDto.Content); } /// /// Creates a text (.txt) file in 'My Documents' section with the title and contents sent in the request /// /// Create txt in 'My' /// File Creation /// File title /// File contents /// Folder contents [Create("@my/text")] public Task> CreateTextFileInMyFromBodyAsync([FromBody] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelperInternal.CreateTextFileAsync(_globalFolderHelper.FolderMy, inDto.Title, inDto.Content); } [Create("@my/text")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateTextFileInMyFromFormAsync([FromForm] CreateTextOrHtmlFileRequestDto inDto) { return _filesControllerHelperInternal.CreateTextFileAsync(_globalFolderHelper.FolderMy, inDto.Title, inDto.Content); } [Create("thumbnails")] public Task> CreateThumbnailsFromBodyAsync([FromBody] BaseBatchRequestDto inDto) { return _fileStorageServiceThirdparty.CreateThumbnailsAsync(inDto.FileIds.ToList()); } [Create("thumbnails")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateThumbnailsFromFormAsync([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchRequestDto inDto) { return await _fileStorageServiceThirdparty.CreateThumbnailsAsync(inDto.FileIds.ToList()); } }