/* * * (c) Copyright Ascensio System Limited 2010-2018 * * This program is freeware. You can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html). * In accordance with Section 7(a) of the GNU GPL 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 more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html * * You can contact Ascensio System SIA by email at sales@onlyoffice.com * * The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display * Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3. * * Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains * relevant author attributions when distributing the software. If the display of the logo in its graphic * form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE" * in every copy of the program you distribute. * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. * */ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Threading.Tasks; using ASC.Api.Core; using ASC.Api.Utils; using ASC.Common; using ASC.Core; using ASC.Core.Common.Configuration; using ASC.Core.Users; using ASC.FederatedLogin.Helpers; using ASC.FederatedLogin.LoginProviders; using ASC.Files.Core; using ASC.Files.Core.Model; using ASC.Files.Helpers; using ASC.Files.Model; using ASC.MessagingSystem; using ASC.Web.Api.Routing; using ASC.Web.Core.Files; using ASC.Web.Files.Classes; using ASC.Web.Files.Configuration; using ASC.Web.Files.Core.Compress; using ASC.Web.Files.Helpers; using ASC.Web.Files.Services.DocumentService; using ASC.Web.Files.Services.WCFService; using ASC.Web.Files.Services.WCFService.FileOperations; using ASC.Web.Files.Utils; using ASC.Web.Studio.Core; using ASC.Web.Studio.Utility; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json.Linq; namespace ASC.Api.Documents { /// /// Provides access to documents /// [Scope] [DefaultRoute] [ApiController] public class FilesController : ControllerBase { private readonly FileStorageService FileStorageService; private readonly RequestHelper _requestHelper; private FilesControllerHelper FilesControllerHelperString { get; } private FilesControllerHelper FilesControllerHelperInt { get; } private FileStorageService FileStorageServiceInt { get; } private GlobalFolderHelper GlobalFolderHelper { get; } private FilesSettingsHelper FilesSettingsHelper { get; } private FilesLinkUtility FilesLinkUtility { get; } private SecurityContext SecurityContext { get; } private FolderWrapperHelper FolderWrapperHelper { get; } private FileOperationWraperHelper FileOperationWraperHelper { get; } private EntryManager EntryManager { get; } private UserManager UserManager { get; } private CoreBaseSettings CoreBaseSettings { get; } private ThirdpartyConfiguration ThirdpartyConfiguration { get; } private MessageService MessageService { get; } private CommonLinkUtility CommonLinkUtility { get; } private DocumentServiceConnector DocumentServiceConnector { get; } private WordpressToken WordpressToken { get; } private WordpressHelper WordpressHelper { get; } private EasyBibHelper EasyBibHelper { get; } private ProductEntryPoint ProductEntryPoint { get; } private TenantManager TenantManager { get; } private FileUtility FileUtility { get; } private IServiceProvider ServiceProvider { get; } /// /// /// /// public FilesController( FilesControllerHelper filesControllerHelperString, FilesControllerHelper filesControllerHelperInt, FileStorageService fileStorageService, FileStorageService fileStorageServiceInt, GlobalFolderHelper globalFolderHelper, FilesSettingsHelper filesSettingsHelper, FilesLinkUtility filesLinkUtility, SecurityContext securityContext, FolderWrapperHelper folderWrapperHelper, FileOperationWraperHelper fileOperationWraperHelper, EntryManager entryManager, UserManager userManager, CoreBaseSettings coreBaseSettings, ThirdpartyConfiguration thirdpartyConfiguration, MessageService messageService, CommonLinkUtility commonLinkUtility, DocumentServiceConnector documentServiceConnector, WordpressToken wordpressToken, WordpressHelper wordpressHelper, ProductEntryPoint productEntryPoint, TenantManager tenantManager, FileUtility fileUtility, ConsumerFactory consumerFactory, RequestHelper requestHelper, IServiceProvider serviceProvider) { FilesControllerHelperString = filesControllerHelperString; FilesControllerHelperInt = filesControllerHelperInt; FileStorageService = fileStorageService; FileStorageServiceInt = fileStorageServiceInt; GlobalFolderHelper = globalFolderHelper; FilesSettingsHelper = filesSettingsHelper; FilesLinkUtility = filesLinkUtility; SecurityContext = securityContext; FolderWrapperHelper = folderWrapperHelper; FileOperationWraperHelper = fileOperationWraperHelper; EntryManager = entryManager; UserManager = userManager; CoreBaseSettings = coreBaseSettings; ThirdpartyConfiguration = thirdpartyConfiguration; MessageService = messageService; CommonLinkUtility = commonLinkUtility; DocumentServiceConnector = documentServiceConnector; WordpressToken = wordpressToken; WordpressHelper = wordpressHelper; EasyBibHelper = consumerFactory.Get(); ProductEntryPoint = productEntryPoint; TenantManager = tenantManager; FileUtility = fileUtility; this._requestHelper = requestHelper; ServiceProvider = serviceProvider; } [Read("info")] public Module GetModule() { ProductEntryPoint.Init(); return new Module(ProductEntryPoint); } [Read("@root")] public async Task>> GetRootFoldersAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders, bool withoutTrash, bool withoutAdditionalFolder) { var IsVisitor = UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor(UserManager); var IsOutsider = UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsOutsider(UserManager); var folders = new SortedSet(); if (IsOutsider) { withoutTrash = true; withoutAdditionalFolder = true; } if (!IsVisitor) { folders.Add(GlobalFolderHelper.FolderMy); } if (!CoreBaseSettings.Personal && !UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsOutsider(UserManager)) { folders.Add(await GlobalFolderHelper.FolderShareAsync); } if (!IsVisitor && !withoutAdditionalFolder) { if (FilesSettingsHelper.FavoritesSection) { folders.Add(await GlobalFolderHelper.FolderFavoritesAsync); } if (FilesSettingsHelper.RecentSection) { folders.Add(await GlobalFolderHelper.FolderRecentAsync); } if (!CoreBaseSettings.Personal && PrivacyRoomSettings.IsAvailable(TenantManager)) { folders.Add(await GlobalFolderHelper.FolderPrivacyAsync); } } if (!CoreBaseSettings.Personal) { folders.Add(await GlobalFolderHelper.FolderCommonAsync); } if (!IsVisitor && !withoutAdditionalFolder && FileUtility.ExtsWebTemplate.Count > 0 && FilesSettingsHelper.TemplatesSection) { folders.Add(await GlobalFolderHelper.FolderTemplatesAsync); } if (!withoutTrash) { folders.Add((int)GlobalFolderHelper.FolderTrash); } var result = new List>(); foreach (var folder in folders) { result.Add(await FilesControllerHelperInt.GetFolderAsync(folder, userIdOrGroupId, filterType, searchInContent, withsubfolders)); } return result; } [Read("@privacy")] public Task> GetPrivacyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { if (!IsAvailablePrivacyRoomSettings()) throw new System.Security.SecurityException(); return InternalGetPrivacyFolderAsync(userIdOrGroupId, filterType, searchInContent, withsubfolders); } private async Task> InternalGetPrivacyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(await GlobalFolderHelper.FolderPrivacyAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [Read("@privacy/available")] public bool IsAvailablePrivacyRoomSettings() { return PrivacyRoomSettings.IsAvailable(TenantManager); } /// /// Returns the detailed list of files and folders located in the current user 'My Documents' section /// /// /// My folder /// /// Folders /// My folder contents [Read("@my")] public Task> GetMyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderMy, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the current user 'Projects Documents' section /// /// /// Projects folder /// /// Folders /// Projects folder contents [Read("@projects")] public async Task> GetProjectsFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperString.GetFolderAsync(await GlobalFolderHelper.GetFolderProjectsAsync(), userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the 'Common Documents' section /// /// /// Common folder /// /// Folders /// Common folder contents [Read("@common")] public async Task> GetCommonFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(await GlobalFolderHelper.FolderCommonAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the 'Shared with Me' section /// /// /// Shared folder /// /// Folders /// Shared folder contents [Read("@share")] public async Task> GetShareFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(await GlobalFolderHelper.FolderShareAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of recent files /// /// Section Recent /// Folders /// Recent contents [Read("@recent")] public async Task> GetRecentFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(await GlobalFolderHelper.FolderRecentAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [Create("file/{fileId}/recent", order: int.MaxValue)] public Task> AddToRecentAsync(string fileId) { return FilesControllerHelperString.AddToRecentAsync(fileId); } [Create("file/{fileId:int}/recent", order: int.MaxValue - 1)] public Task> AddToRecentAsync(int fileId) { return FilesControllerHelperInt.AddToRecentAsync(fileId); } /// /// Returns the detailed list of favorites files /// /// Section Favorite /// Folders /// Favorites contents [Read("@favorites")] public async Task> GetFavoritesFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(await GlobalFolderHelper.FolderFavoritesAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of templates files /// /// Section Template /// Folders /// Templates contents [Read("@templates")] public async Task> GetTemplatesFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(await GlobalFolderHelper.FolderTemplatesAsync, userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the 'Recycle Bin' section /// /// /// Trash folder /// /// Folders /// Trash folder contents [Read("@trash")] public Task> GetTrashFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return FilesControllerHelperInt.GetFolderAsync(Convert.ToInt32(GlobalFolderHelper.FolderTrash), userIdOrGroupId, filterType, searchInContent, withsubfolders); } /// /// Returns the detailed list of files and folders located in the folder with the ID specified in the request /// /// /// Folder by ID /// /// Folders /// Folder ID /// User or group ID /// Filter type /// Folder contents [Read("{folderId}", order: int.MaxValue, DisableFormat = true)] public async Task> GetFolderAsync(string folderId, Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { var folder = await FilesControllerHelperString.GetFolderAsync(folderId, userIdOrGroupId, filterType, searchInContent, withsubfolders); return folder.NotFoundIfNull(); } [Read("{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> GetFolderAsync(int folderId, Guid userIdOrGroupId, FilterType filterType, bool searchInContent, bool withsubfolders) { return FilesControllerHelperInt.GetFolderAsync(folderId, userIdOrGroupId, filterType, searchInContent, withsubfolders); } [Read("{folderId}/subfolders")] public IAsyncEnumerable GetFoldersAsync(string folderId) { return FilesControllerHelperString.GetFoldersAsync(folderId); } [Read("{folderId:int}/subfolders")] public IAsyncEnumerable GetFoldersAsync(int folderId) { return FilesControllerHelperInt.GetFoldersAsync(folderId); } [Read("{folderId}/news")] public Task> GetNewItemsAsync(string folderId) { return FilesControllerHelperString.GetNewItemsAsync(folderId); } [Read("{folderId:int}/news")] public Task> GetNewItemsAsync(int folderId) { return FilesControllerHelperInt.GetNewItemsAsync(folderId); } /// /// Uploads the file specified with single file upload or standart multipart/form-data method to 'My Documents' section /// /// Upload to My /// Uploads /// /// ///
  • Single file upload. You should set Content-Type & Content-Disposition header to specify filename and content type, and send file in request body
  • ///
  • Using standart multipart/form-data method
  • /// ]]> ///
    /// Request Input stream /// Content-Type Header /// Content-Disposition Header /// List of files when posted as multipart/form-data /// Uploaded file [Create("@my/upload")] public Task UploadFileToMyAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return FilesControllerHelperInt.UploadFileAsync(GlobalFolderHelper.FolderMy, uploadModel); } /// /// Uploads the file specified with single file upload or standart multipart/form-data method to 'Common Documents' section /// /// Upload to Common /// Uploads /// /// ///
  • Single file upload. You should set Content-Type & Content-Disposition header to specify filename and content type, and send file in request body
  • ///
  • Using standart multipart/form-data method
  • /// ]]> ///
    /// Request Input stream /// Content-Type Header /// Content-Disposition Header /// List of files when posted as multipart/form-data /// Uploaded file [Create("@common/upload")] public async Task UploadFileToCommonAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return await FilesControllerHelperInt.UploadFileAsync(await GlobalFolderHelper.FolderCommonAsync, uploadModel); } /// /// Uploads the file specified with single file upload or standart multipart/form-data method to the selected folder /// /// Upload to folder /// Uploads /// /// ///
  • Single file upload. You should set Content-Type & Content-Disposition header to specify filename and content type, and send file in request body
  • ///
  • Using standart multipart/form-data method
  • /// ]]> ///
    /// Folder ID to upload to /// Request Input stream /// Content-Type Header /// Content-Disposition Header /// List of files when posted as multipart/form-data /// Create New If Exist /// If True, upload documents in original formats as well /// Keep status conversation after finishing /// Uploaded file [Create("{folderId}/upload", order: int.MaxValue)] public Task UploadFileAsync(string folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { return FilesControllerHelperString.UploadFileAsync(folderId, uploadModel); } [Create("{folderId:int}/upload", order: int.MaxValue - 1)] public Task UploadFileAsync(int folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { return FilesControllerHelperInt.UploadFileAsync(folderId, uploadModel); } /// /// Uploads the file specified with single file upload to 'Common Documents' section /// /// Request Input stream /// Name of file which has to be uploaded /// Create New If Exist /// Keep status conversation after finishing /// Uploads /// [Create("@my/insert")] public Task> InsertFileToMyFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return InsertFileAsync(GlobalFolderHelper.FolderMy, model); } /// /// Uploads the file specified with single file upload to 'Common Documents' section /// /// Request Input stream /// Name of file which has to be uploaded /// Create New If Exist /// Keep status conversation after finishing /// Uploads /// [Create("@common/insert")] public async Task> InsertFileToCommonFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return await InsertFileAsync(await GlobalFolderHelper.FolderCommonAsync, model); } /// /// Uploads the file specified with single file upload /// /// Folder ID to upload to /// Request Input stream /// Name of file which has to be uploaded /// Create New If Exist /// Keep status conversation after finishing /// Uploads /// [Create("{folderId}/insert", order: int.MaxValue)] public Task> InsertFileAsync(string folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return FilesControllerHelperString.InsertFileAsync(folderId, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } [Create("{folderId:int}/insert", order: int.MaxValue - 1)] public Task> InsertFileFromFormAsync(int folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return InsertFileAsync(folderId, model); } private Task> InsertFileAsync(int folderId, InsertFileModel model) { return FilesControllerHelperInt.InsertFileAsync(folderId, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } /// /// /// /// /// /// /// /// false [Update("{fileId}/update")] public Task> UpdateFileStreamFromFormAsync(string fileId, [FromForm] FileStreamModel model) { return FilesControllerHelperString.UpdateFileStreamAsync(FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(), fileId, model.FileExtension, model.Encrypted, model.Forcesave); } [Update("{fileId:int}/update")] public Task> UpdateFileStreamFromFormAsync(int fileId, [FromForm] FileStreamModel model) { return FilesControllerHelperInt.UpdateFileStreamAsync(FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(), fileId, model.FileExtension, model.Encrypted, model.Forcesave); } /// /// /// /// File ID /// /// /// /// /// /// Files /// [Update("file/{fileId}/saveediting")] public Task> SaveEditingFromFormAsync(string fileId, [FromForm] SaveEditingModel model) { using var stream = FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(); return FilesControllerHelperString.SaveEditingAsync(fileId, model.FileExtension, model.DownloadUri, stream, model.Doc, model.Forcesave); } [Update("file/{fileId:int}/saveediting")] public Task> SaveEditingFromFormAsync(int fileId, [FromForm] SaveEditingModel model) { using var stream = FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(); return FilesControllerHelperInt.SaveEditingAsync(fileId, model.FileExtension, model.DownloadUri, stream, model.Doc, model.Forcesave); } /// /// /// /// File ID /// /// /// Files /// [Create("file/{fileId}/startedit")] [Consumes("application/json")] public async Task StartEditFromBodyAsync(string fileId, [FromBody] StartEditModel model) { return await FilesControllerHelperString.StartEditAsync(fileId, model.EditingAlone, model.Doc); } [Create("file/{fileId}/startedit")] [Consumes("application/x-www-form-urlencoded")] public async Task StartEditFromFormAsync(string fileId, [FromForm] StartEditModel model) { return await FilesControllerHelperString.StartEditAsync(fileId, model.EditingAlone, model.Doc); } [Create("file/{fileId:int}/startedit")] [Consumes("application/json")] public async Task StartEditFromBodyAsync(int fileId, [FromBody] StartEditModel model) { return await FilesControllerHelperInt.StartEditAsync(fileId, model.EditingAlone, model.Doc); } [Create("file/{fileId:int}/startedit")] public async Task StartEditAsync(int fileId) { return await FilesControllerHelperInt.StartEditAsync(fileId, false, null); } [Create("file/{fileId:int}/startedit")] [Consumes("application/x-www-form-urlencoded")] public async Task StartEditFromFormAsync(int fileId, [FromForm] StartEditModel model) { return await FilesControllerHelperInt.StartEditAsync(fileId, model.EditingAlone, model.Doc); } /// /// /// /// File ID /// /// /// /// /// Files /// [Read("file/{fileId}/trackeditfile")] public Task> TrackEditFileAsync(string fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish) { return FilesControllerHelperString.TrackEditFileAsync(fileId, tabId, docKeyForTrack, doc, isFinish); } [Read("file/{fileId:int}/trackeditfile")] public Task> TrackEditFileAsync(int fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish) { return FilesControllerHelperInt.TrackEditFileAsync(fileId, tabId, docKeyForTrack, doc, isFinish); } /// /// /// /// File ID /// /// /// Files /// [AllowAnonymous] [Read("file/{fileId}/openedit", Check = false)] public Task> OpenEditAsync(string fileId, int version, string doc, bool view) { return FilesControllerHelperString.OpenEditAsync(fileId, version, doc, view); } [AllowAnonymous] [Read("file/{fileId:int}/openedit", Check = false)] public Task> OpenEditAsync(int fileId, int version, string doc, bool view) { return FilesControllerHelperInt.OpenEditAsync(fileId, version, doc, view); } /// /// Creates session to upload large files in multiple chunks. /// /// Chunked upload /// Uploads /// Id of the folder in which file will be uploaded /// Name of file which has to be uploaded /// Length in bytes of file which has to be uploaded /// Relative folder from folderId /// /// /// 512 and greater or equal than 10 mb. Last chunk can have any size. /// After initial request respond with status 200 OK you must obtain value of 'location' field from the response. Send all your chunks to that location. /// Each chunk must be sent in strict order in which chunks appears in file. /// After receiving each chunk if no errors occured server will respond with current information about upload session. /// When number of uploaded bytes equal to the number of bytes you send in initial request server will respond with 201 Created and will send you info about uploaded file. /// ]]> /// /// /// ///
  • id: unique id of this upload session
  • ///
  • created: UTC time when session was created
  • ///
  • expired: UTC time when session will be expired if no chunks will be sent until that time
  • ///
  • location: URL to which you must send your next chunk
  • ///
  • bytes_uploaded: If exists contains number of bytes uploaded for specific upload id
  • ///
  • bytes_total: Number of bytes which has to be uploaded
  • /// /// ]]> ///
    [Create("{folderId}/upload/create_session")] public Task CreateUploadSessionFromBodyAsync(string folderId, [FromBody] SessionModel sessionModel) { return FilesControllerHelperString.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } [Create("{folderId}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public Task CreateUploadSessionFromFormAsync(string folderId, [FromForm] SessionModel sessionModel) { return FilesControllerHelperString.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] public Task CreateUploadSessionFromBodyAsync(int folderId, [FromBody] SessionModel sessionModel) { return FilesControllerHelperInt.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public Task CreateUploadSessionFromFormAsync(int folderId, [FromForm] SessionModel sessionModel) { return FilesControllerHelperInt.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.LastModified, sessionModel.Encrypted); } /// /// 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] CreateTextOrHtmlFileModel model) { return CreateTextFileAsync(GlobalFolderHelper.FolderMy, model); } [Create("@my/text")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateTextFileInMyFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return CreateTextFileAsync(GlobalFolderHelper.FolderMy, model); } /// /// 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] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(await GlobalFolderHelper.FolderCommonAsync, model); } [Create("@common/text")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateTextFileInCommonFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(await GlobalFolderHelper.FolderCommonAsync, model); } /// /// 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(string folderId, [FromBody] CreateTextOrHtmlFileModel model) { return CreateTextFileAsync(folderId, model); } [Create("{folderId}/text")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateTextFileFromFormAsync(string folderId, [FromForm] CreateTextOrHtmlFileModel model) { return CreateTextFileAsync(folderId, model); } private Task> CreateTextFileAsync(string folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperString.CreateTextFileAsync(folderId, model.Title, model.Content); } [Create("{folderId:int}/text")] public Task> CreateTextFileFromBodyAsync(int folderId, [FromBody] CreateTextOrHtmlFileModel model) { return CreateTextFileAsync(folderId, model); } [Create("{folderId:int}/text")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateTextFileFromFormAsync(int folderId, [FromForm] CreateTextOrHtmlFileModel model) { return CreateTextFileAsync(folderId, model); } private Task> CreateTextFileAsync(int folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperInt.CreateTextFileAsync(folderId, model.Title, model.Content); } /// /// 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(string folderId, [FromBody] CreateTextOrHtmlFileModel model) { return CreateHtmlFileAsync(folderId, model); } [Create("{folderId}/html")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateHtmlFileFromFormAsync(string folderId, [FromForm] CreateTextOrHtmlFileModel model) { return CreateHtmlFileAsync(folderId, model); } private Task> CreateHtmlFileAsync(string folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperString.CreateHtmlFileAsync(folderId, model.Title, model.Content); } [Create("{folderId:int}/html")] public Task> CreateHtmlFileFromBodyAsync(int folderId, [FromBody] CreateTextOrHtmlFileModel model) { return CreateHtmlFileAsync(folderId, model); } [Create("{folderId:int}/html")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateHtmlFileFromFormAsync(int folderId, [FromForm] CreateTextOrHtmlFileModel model) { return CreateHtmlFileAsync(folderId, model); } private Task> CreateHtmlFileAsync(int folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperInt.CreateHtmlFileAsync(folderId, model.Title, model.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] CreateTextOrHtmlFileModel model) { return CreateHtmlFileAsync(GlobalFolderHelper.FolderMy, model); } [Create("@my/html")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateHtmlFileInMyFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return CreateHtmlFileAsync(GlobalFolderHelper.FolderMy, model); } /// /// 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] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(await GlobalFolderHelper.FolderCommonAsync, model); } [Create("@common/html")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateHtmlFileInCommonFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(await GlobalFolderHelper.FolderCommonAsync, model); } /// /// Creates a new folder with the title sent in the request. The ID of a parent folder can be also specified. /// /// /// New folder /// /// Folders /// Parent folder ID /// Title of new folder /// New folder contents [Create("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> CreateFolderFromBodyAsync(string folderId, [FromBody] CreateFolderModel folderModel) { return FilesControllerHelperString.CreateFolderAsync(folderId, folderModel.Title); } [Create("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFolderFromFormAsync(string folderId, [FromForm] CreateFolderModel folderModel) { return FilesControllerHelperString.CreateFolderAsync(folderId, folderModel.Title); } [Create("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> CreateFolderFromBodyAsync(int folderId, [FromBody] CreateFolderModel folderModel) { return FilesControllerHelperInt.CreateFolderAsync(folderId, folderModel.Title); } [Create("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFolderFromFormAsync(int folderId, [FromForm] CreateFolderModel folderModel) { return FilesControllerHelperInt.CreateFolderAsync(folderId, folderModel.Title); } /// /// 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] CreateFileModel model) { return FilesControllerHelperInt.CreateFileAsync(GlobalFolderHelper.FolderMy, model.Title, model.TemplateId, model.FormId, model.EnableExternalExt); } [Create("@my/file")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFileFromFormAsync([FromForm] CreateFileModel model) { return FilesControllerHelperInt.CreateFileAsync(GlobalFolderHelper.FolderMy, model.Title, model.TemplateId, model.FormId, model.EnableExternalExt); } /// /// 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(string folderId, [FromBody] CreateFileModel model) { return FilesControllerHelperString.CreateFileAsync(folderId, model.Title, model.TemplateId, model.FormId, model.EnableExternalExt); } [Create("{folderId}/file")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFileFromFormAsync(string folderId, [FromForm] CreateFileModel model) { return FilesControllerHelperString.CreateFileAsync(folderId, model.Title, model.TemplateId, model.FormId, model.EnableExternalExt); } [Create("{folderId:int}/file")] public Task> CreateFileFromBodyAsync(int folderId, [FromBody] CreateFileModel model) { return FilesControllerHelperInt.CreateFileAsync(folderId, model.Title, model.TemplateId, model.FormId, model.EnableExternalExt); } [Create("{folderId:int}/file")] [Consumes("application/x-www-form-urlencoded")] public Task> CreateFileFromFormAsync(int folderId, [FromForm] CreateFileModel model) { return FilesControllerHelperInt.CreateFileAsync(folderId, model.Title, model.TemplateId, model.FormId, model.EnableExternalExt); } /// /// Renames the selected folder to the new title specified in the request /// /// /// Rename folder /// /// Folders /// Folder ID /// New title /// Folder contents [Update("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> RenameFolderFromBodyAsync(string folderId, [FromBody] CreateFolderModel folderModel) { return FilesControllerHelperString.RenameFolderAsync(folderId, folderModel.Title); } [Update("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> RenameFolderFromFormAsync(string folderId, [FromForm] CreateFolderModel folderModel) { return FilesControllerHelperString.RenameFolderAsync(folderId, folderModel.Title); } [Update("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> RenameFolderFromBodyAsync(int folderId, [FromBody] CreateFolderModel folderModel) { return FilesControllerHelperInt.RenameFolderAsync(folderId, folderModel.Title); } [Update("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> RenameFolderFromFormAsync(int folderId, [FromForm] CreateFolderModel folderModel) { return FilesControllerHelperInt.RenameFolderAsync(folderId, folderModel.Title); } [Create("owner")] public async Task> ChangeOwnerFromBodyAsync([FromBody] ChangeOwnerModel model) { return await ChangeOwnerAsync(model); } [Create("owner")] [Consumes("application/x-www-form-urlencoded")] public async Task> ChangeOwnerFromFormAsync([FromForm] ChangeOwnerModel model) { return await ChangeOwnerAsync(model); } public async Task> ChangeOwnerAsync(ChangeOwnerModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); var data = Enumerable.Empty(); data = data.Concat(await FileStorageServiceInt.ChangeOwnerAsync(folderIntIds, fileIntIds, model.UserId)); data = data.Concat(await FileStorageService.ChangeOwnerAsync(folderStringIds, fileStringIds, model.UserId)); var result = new List(); foreach (var e in data) { result.Add(await FilesControllerHelperInt.GetFileEntryWrapperAsync(e)); } return result; } /// /// Returns a detailed information about the folder with the ID specified in the request /// /// Folder information /// Folders /// Folder info [Read("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] public Task> GetFolderInfoAsync(string folderId) { return FilesControllerHelperString.GetFolderInfoAsync(folderId); } [Read("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> GetFolderInfoAsync(int folderId) { return FilesControllerHelperInt.GetFolderInfoAsync(folderId); } /// /// Returns parent folders /// /// /// Folders /// Parent folders [Read("folder/{folderId}/path")] public IAsyncEnumerable GetFolderPathAsync(string folderId) { return FilesControllerHelperString.GetFolderPathAsync(folderId); } [Read("folder/{folderId:int}/path")] public IAsyncEnumerable GetFolderPathAsync(int folderId) { return FilesControllerHelperInt.GetFolderPathAsync(folderId); } /// /// 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(string fileId, int version = -1) { return FilesControllerHelperString.GetFileInfoAsync(fileId, version); } [Read("file/{fileId:int}")] public Task> GetFileInfoAsync(int fileId, int version = -1) { return FilesControllerHelperInt.GetFileInfoAsync(fileId, version); } [Create("file/{fileId:int}/copyas", order: int.MaxValue - 1)] public Task CopyFileAsFromBody(int fileId, [FromBody] CopyAsModel model) { return CopyFile(fileId, model); } [Create("file/{fileId:int}/copyas", order: int.MaxValue - 1)] [Consumes("application/x-www-form-urlencoded")] public Task CopyFileAsFromForm(int fileId, [FromForm] CopyAsModel model) { return CopyFile(fileId, model); } [Create("file/{fileId}/copyas", order: int.MaxValue)] public Task CopyFileAsFromBody(string fileId, [FromBody] CopyAsModel model) { return CopyFile(fileId, model); } [Create("file/{fileId}/copyas", order: int.MaxValue)] [Consumes("application/x-www-form-urlencoded")] public Task CopyFileAsFromForm(string fileId, [FromForm] CopyAsModel model) { return CopyFile(fileId, model); } private async Task CopyFile(T fileId, CopyAsModel model) { var helper = ServiceProvider.GetService>(); if (model.DestFolderId.ValueKind == JsonValueKind.Number) { return await helper.CopyFileAsAsync(fileId, model.DestFolderId.GetInt32(), model.DestTitle, model.Password); } else if (model.DestFolderId.ValueKind == JsonValueKind.String) { return await helper.CopyFileAsAsync(fileId, model.DestFolderId.GetString(), model.DestTitle, model.Password); } return null; } /// /// 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(string fileId, [FromBody] UpdateFileModel model) { return FilesControllerHelperString.UpdateFileAsync(fileId, model.Title, model.LastVersion); } [Update("file/{fileId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> UpdateFileFromFormAsync(string fileId, [FromForm] UpdateFileModel model) { return FilesControllerHelperString.UpdateFileAsync(fileId, model.Title, model.LastVersion); } [Update("file/{fileId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> UpdateFileFromBodyAsync(int fileId, [FromBody] UpdateFileModel model) { return FilesControllerHelperInt.UpdateFileAsync(fileId, model.Title, model.LastVersion); } [Update("file/{fileId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public Task> UpdateFileFromFormAsync(int fileId, [FromForm] UpdateFileModel model) { return FilesControllerHelperInt.UpdateFileAsync(fileId, model.Title, model.LastVersion); } /// /// 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(string fileId, [FromBody] DeleteModel model) { return FilesControllerHelperString.DeleteFileAsync(fileId, model.DeleteAfter, model.Immediately); } [Delete("file/{fileId:int}", order: int.MaxValue - 1, DisableFormat = true)] public Task> DeleteFile(int fileId, [FromBody] DeleteModel model) { return FilesControllerHelperInt.DeleteFileAsync(fileId, model.DeleteAfter, model.Immediately); } /// /// Start conversion /// /// Convert /// File operations /// /// Operation result [Update("file/{fileId}/checkconversion")] public IAsyncEnumerable> StartConversion(string fileId, [FromBody(EmptyBodyBehavior = Microsoft.AspNetCore.Mvc.ModelBinding.EmptyBodyBehavior.Allow)] CheckConversionModel model) { if (model == null) { model = new CheckConversionModel(); } model.FileId = fileId; return FilesControllerHelperString.StartConversionAsync(model); } [Update("file/{fileId:int}/checkconversion")] public IAsyncEnumerable> StartConversion(int fileId, [FromBody(EmptyBodyBehavior = Microsoft.AspNetCore.Mvc.ModelBinding.EmptyBodyBehavior.Allow)] CheckConversionModel model) { if (model == null) { model = new CheckConversionModel(); } model.FileId = fileId; return FilesControllerHelperInt.StartConversionAsync(model); } /// /// Check conversion status /// /// Convert /// File operations /// /// /// Operation result [Read("file/{fileId}/checkconversion")] public IAsyncEnumerable> CheckConversionAsync(string fileId, bool start) { return FilesControllerHelperString.CheckConversionAsync(new CheckConversionModel() { FileId = fileId, StartConvert = start }); } [Read("file/{fileId:int}/checkconversion")] public IAsyncEnumerable> CheckConversionAsync(int fileId, bool start) { return FilesControllerHelperInt.CheckConversionAsync(new CheckConversionModel() { FileId = fileId, StartConvert = start }); } /// /// Deletes the folder with the ID specified in the request /// /// Delete folder /// Folders /// Folder ID /// Delete after finished /// Don't move to the Recycle Bin /// Operation result [Delete("folder/{folderId}", order: int.MaxValue - 1, DisableFormat = true)] public Task> DeleteFolder(string folderId, bool deleteAfter, bool immediately) { return FilesControllerHelperString.DeleteFolder(folderId, deleteAfter, immediately); } [Delete("folder/{folderId:int}")] public Task> DeleteFolder(int folderId, bool deleteAfter, bool immediately) { return FilesControllerHelperInt.DeleteFolder(folderId, deleteAfter, immediately); } /// /// 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))] BatchModel batchModel) { return FilesControllerHelperString.MoveOrCopyBatchCheckAsync(batchModel); } /// /// 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] BatchModel batchModel) { return FilesControllerHelperString.MoveBatchItemsAsync(batchModel); } [Update("fileops/move")] [Consumes("application/x-www-form-urlencoded")] public Task> MoveBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(BatchModelBinder))] BatchModel batchModel) { return FilesControllerHelperString.MoveBatchItemsAsync(batchModel); } /// /// 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] BatchModel batchModel) { return FilesControllerHelperString.CopyBatchItemsAsync(batchModel); } [Update("fileops/copy")] [Consumes("application/x-www-form-urlencoded")] public Task> CopyBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(BatchModelBinder))] BatchModel batchModel) { return FilesControllerHelperString.CopyBatchItemsAsync(batchModel); } /// /// Marks all files and folders as read /// /// Mark as read /// File operations /// Operation result [Update("fileops/markasread")] public Task> MarkAsReadFromBody([FromBody] BaseBatchModel model) { return FilesControllerHelperString.MarkAsReadAsync(model); } [Update("fileops/markasread")] [Consumes("application/x-www-form-urlencoded")] public Task> MarkAsReadFromForm([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchModel model) { return FilesControllerHelperString.MarkAsReadAsync(model); } /// /// Finishes all the active file operations /// /// Finish all /// File operations /// Operation result [Update("fileops/terminate")] public async IAsyncEnumerable TerminateTasks() { var tasks = FileStorageService.TerminateTasks(); foreach (var e in tasks) { yield return await FileOperationWraperHelper.GetAsync(e); } } /// /// 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 FileStorageService.GetTasksStatuses()) { result.Add(await FileOperationWraperHelper.GetAsync(e)); } return result; } /// /// 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] DownloadModel model) { return FilesControllerHelperString.BulkDownloadAsync(model); } [Update("fileops/bulkdownload")] [Consumes("application/x-www-form-urlencoded")] public Task> BulkDownloadFromForm([FromForm] DownloadModel model) { return FilesControllerHelperString.BulkDownloadAsync(model); } /// /// 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] DeleteBatchModel batch) { var tasks = FileStorageService.DeleteItems("delete", batch.FileIds.ToList(), batch.FolderIds.ToList(), false, batch.DeleteAfter, batch.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))] DeleteBatchModel batch) { var tasks = FileStorageService.DeleteItems("delete", batch.FileIds.ToList(), batch.FolderIds.ToList(), false, batch.DeleteAfter, batch.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 FilesControllerHelperInt.EmptyTrashAsync(); } /// /// 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(string fileId) { return FilesControllerHelperString.GetFileVersionInfoAsync(fileId); } [Read("file/{fileId:int}/history")] public Task>> GetFileVersionInfoAsync(int fileId) { return FilesControllerHelperInt.GetFileVersionInfoAsync(fileId); } [Read("file/{fileId}/presigned")] public Task GetPresignedUriAsync(string fileId) { return FilesControllerHelperString.GetPresignedUriAsync(fileId); } [Read("file/{fileId:int}/presigned")] public Task GetPresignedUriAsync(int fileId) { return FilesControllerHelperInt.GetPresignedUriAsync(fileId); } /// /// Change version history /// /// File ID /// Version of history /// Mark as version or revision /// Files /// [Update("file/{fileId}/history")] public Task>> ChangeHistoryFromBodyAsync(string fileId, [FromBody] ChangeHistoryModel model) { return FilesControllerHelperString.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId}/history")] [Consumes("application/x-www-form-urlencoded")] public Task>> ChangeHistoryFromFormAsync(string fileId, [FromForm] ChangeHistoryModel model) { return FilesControllerHelperString.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId:int}/history")] public Task>> ChangeHistoryFromBodyAsync(int fileId, [FromBody] ChangeHistoryModel model) { return FilesControllerHelperInt.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId:int}/history")] [Consumes("application/x-www-form-urlencoded")] public Task>> ChangeHistoryFromFormAsync(int fileId, [FromForm] ChangeHistoryModel model) { return FilesControllerHelperInt.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId}/lock")] public Task> LockFileFromBodyAsync(string fileId, [FromBody] LockFileModel model) { return FilesControllerHelperString.LockFileAsync(fileId, model.LockFile); } [Update("file/{fileId}/lock")] [Consumes("application/x-www-form-urlencoded")] public Task> LockFileFromFormAsync(string fileId, [FromForm] LockFileModel model) { return FilesControllerHelperString.LockFileAsync(fileId, model.LockFile); } [Update("file/{fileId:int}/lock")] public Task> LockFileFromBodyAsync(int fileId, [FromBody] LockFileModel model) { return FilesControllerHelperInt.LockFileAsync(fileId, model.LockFile); } [Update("file/{fileId:int}/lock")] [Consumes("application/x-www-form-urlencoded")] public Task> LockFileFromFormAsync(int fileId, [FromForm] LockFileModel model) { return FilesControllerHelperInt.LockFileAsync(fileId, model.LockFile); } [AllowAnonymous] [Read("file/{fileId}/edit/history")] public Task> GetEditHistoryAsync(string fileId, string doc = null) { return FilesControllerHelperString.GetEditHistoryAsync(fileId, doc); } [AllowAnonymous] [Read("file/{fileId:int}/edit/history")] public Task> GetEditHistoryAsync(int fileId, string doc = null) { return FilesControllerHelperInt.GetEditHistoryAsync(fileId, doc); } [AllowAnonymous] [Read("file/{fileId}/edit/diff")] public Task GetEditDiffUrlAsync(string fileId, int version = 0, string doc = null) { return FilesControllerHelperString.GetEditDiffUrlAsync(fileId, version, doc); } [AllowAnonymous] [Read("file/{fileId:int}/edit/diff")] public Task GetEditDiffUrlAsync(int fileId, int version = 0, string doc = null) { return FilesControllerHelperInt.GetEditDiffUrlAsync(fileId, version, doc); } [AllowAnonymous] [Read("file/{fileId}/restoreversion")] public Task> RestoreVersionAsync(string fileId, int version = 0, string url = null, string doc = null) { return FilesControllerHelperString.RestoreVersionAsync(fileId, version, url, doc); } [AllowAnonymous] [Read("file/{fileId:int}/restoreversion")] public Task> RestoreVersionAsync(int fileId, int version = 0, string url = null, string doc = null) { return FilesControllerHelperInt.RestoreVersionAsync(fileId, version, url, doc); } [Update("file/{fileId}/comment")] public async Task UpdateCommentFromBodyAsync(string fileId, [FromBody] UpdateCommentModel model) { return await FilesControllerHelperString.UpdateCommentAsync(fileId, model.Version, model.Comment); } [Update("file/{fileId}/comment")] [Consumes("application/x-www-form-urlencoded")] public async Task UpdateCommentFromFormAsync(string fileId, [FromForm] UpdateCommentModel model) { return await FilesControllerHelperString.UpdateCommentAsync(fileId, model.Version, model.Comment); } [Update("file/{fileId:int}/comment")] public async Task UpdateCommentFromBodyAsync(int fileId, [FromBody] UpdateCommentModel model) { return await FilesControllerHelperInt.UpdateCommentAsync(fileId, model.Version, model.Comment); } [Update("file/{fileId:int}/comment")] [Consumes("application/x-www-form-urlencoded")] public async Task UpdateCommentFromFormAsync(int fileId, [FromForm] UpdateCommentModel model) { return await FilesControllerHelperInt.UpdateCommentAsync(fileId, model.Version, model.Comment); } /// /// Returns the detailed information about shared file with the ID specified in the request /// /// File sharing /// Sharing /// File ID /// Shared file information [Read("file/{fileId}/share")] public Task> GetFileSecurityInfoAsync(string fileId) { return FilesControllerHelperString.GetFileSecurityInfoAsync(fileId); } [Read("file/{fileId:int}/share")] public Task> GetFileSecurityInfoAsync(int fileId) { return FilesControllerHelperInt.GetFileSecurityInfoAsync(fileId); } /// /// Returns the detailed information about shared folder with the ID specified in the request /// /// Folder sharing /// Folder ID /// Sharing /// Shared folder information [Read("folder/{folderId}/share")] public Task> GetFolderSecurityInfoAsync(string folderId) { return FilesControllerHelperString.GetFolderSecurityInfoAsync(folderId); } [Read("folder/{folderId:int}/share")] public Task> GetFolderSecurityInfoAsync(int folderId) { return FilesControllerHelperInt.GetFolderSecurityInfoAsync(folderId); } [Create("share")] public async Task> GetSecurityInfoFromBodyAsync([FromBody] BaseBatchModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); var result = new List(); result.AddRange(await FilesControllerHelperInt.GetSecurityInfoAsync(fileIntIds, folderIntIds)); result.AddRange(await FilesControllerHelperString.GetSecurityInfoAsync(fileStringIds, folderStringIds)); return result; } [Create("share")] [Consumes("application/x-www-form-urlencoded")] public async Task> GetSecurityInfoFromFormAsync([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); var result = new List(); result.AddRange(await FilesControllerHelperInt.GetSecurityInfoAsync(fileIntIds, folderIntIds)); result.AddRange(await FilesControllerHelperString.GetSecurityInfoAsync(fileStringIds, folderStringIds)); return result; } /// /// Sets sharing settings for the file with the ID specified in the request /// /// File ID /// Collection of sharing rights /// Should notify people /// Sharing message to send when notifying /// Share file /// Sharing /// /// Each of the FileShareParams must contain two parameters: 'ShareTo' - ID of the user with whom we want to share and 'Access' - access type which we want to grant to the user (Read, ReadWrite, etc) /// /// Shared file information [Update("file/{fileId}/share")] public Task> SetFileSecurityInfoFromBodyAsync(string fileId, [FromBody] SecurityInfoModel model) { return FilesControllerHelperString.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFileSecurityInfoFromFormAsync(string fileId, [FromForm] SecurityInfoModel model) { return FilesControllerHelperString.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId:int}/share")] public Task> SetFileSecurityInfoFromBodyAsync(int fileId, [FromBody] SecurityInfoModel model) { return FilesControllerHelperInt.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFileSecurityInfoFromFormAsync(int fileId, [FromForm] SecurityInfoModel model) { return FilesControllerHelperInt.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("share")] public Task> SetSecurityInfoFromBodyAsync([FromBody] SecurityInfoModel model) { return SetSecurityInfoAsync(model); } [Update("share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetSecurityInfoFromFormAsync([FromForm] SecurityInfoModel model) { return SetSecurityInfoAsync(model); } public async Task> SetSecurityInfoAsync(SecurityInfoModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); var result = new List(); result.AddRange(await FilesControllerHelperInt.SetSecurityInfoAsync(fileIntIds, folderIntIds, model.Share, model.Notify, model.SharingMessage)); result.AddRange(await FilesControllerHelperString.SetSecurityInfoAsync(fileStringIds, folderStringIds, model.Share, model.Notify, model.SharingMessage)); return result; } /// /// Sets sharing settings for the folder with the ID specified in the request /// /// Share folder /// Folder ID /// Collection of sharing rights /// Should notify people /// Sharing message to send when notifying /// /// Each of the FileShareParams must contain two parameters: 'ShareTo' - ID of the user with whom we want to share and 'Access' - access type which we want to grant to the user (Read, ReadWrite, etc) /// /// Sharing /// Shared folder information [Update("folder/{folderId}/share")] public Task> SetFolderSecurityInfoFromBodyAsync(string folderId, [FromBody] SecurityInfoModel model) { return FilesControllerHelperString.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFolderSecurityInfoFromFormAsync(string folderId, [FromForm] SecurityInfoModel model) { return FilesControllerHelperString.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId:int}/share")] public Task> SetFolderSecurityInfoFromBodyAsync(int folderId, [FromBody] SecurityInfoModel model) { return FilesControllerHelperInt.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public Task> SetFolderSecurityInfoFromFormAsync(int folderId, [FromForm] SecurityInfoModel model) { return FilesControllerHelperInt.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } /// /// Removes sharing rights for the group with the ID specified in the request /// /// Folders ID /// Files ID /// Remove group sharing rights /// Sharing /// Shared file information [Delete("share")] public async Task RemoveSecurityInfoAsync(BaseBatchModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); await FilesControllerHelperInt.RemoveSecurityInfoAsync(fileIntIds, folderIntIds); await FilesControllerHelperString.RemoveSecurityInfoAsync(fileStringIds, folderStringIds); return true; } /// /// Returns the external link to the shared file with the ID specified in the request /// /// /// File external link /// /// File ID /// Access right /// Files /// Shared file link [Update("{fileId}/sharedlinkAsync")] public async Task GenerateSharedLinkFromBodyAsync(string fileId, [FromBody] GenerateSharedLinkModel model) { return await FilesControllerHelperString.GenerateSharedLinkAsync(fileId, model.Share); } [Update("{fileId}/sharedlinkAsync")] [Consumes("application/x-www-form-urlencoded")] public async Task GenerateSharedLinkFromFormAsync(string fileId, [FromForm] GenerateSharedLinkModel model) { return await FilesControllerHelperString.GenerateSharedLinkAsync(fileId, model.Share); } [Update("{fileId:int}/sharedlinkAsync")] public async Task GenerateSharedLinkFromBodyAsync(int fileId, [FromBody] GenerateSharedLinkModel model) { return await FilesControllerHelperInt.GenerateSharedLinkAsync(fileId, model.Share); } [Update("{fileId:int}/sharedlinkAsync")] [Consumes("application/x-www-form-urlencoded")] public async Task GenerateSharedLinkFromFormAsync(int fileId, [FromForm] GenerateSharedLinkModel model) { return await FilesControllerHelperInt.GenerateSharedLinkAsync(fileId, model.Share); } [Update("{fileId:int}/setacelink")] public Task SetAceLinkAsync(int fileId, [FromBody] GenerateSharedLinkModel model) { return FilesControllerHelperInt.SetAceLinkAsync(fileId, model.Share); } [Update("{fileId}/setacelink")] public Task SetAceLinkAsync(string fileId, [FromBody] GenerateSharedLinkModel model) { return FilesControllerHelperString.SetAceLinkAsync(fileId, model.Share); } /// /// Get a list of available providers /// /// Third-Party Integration /// List of provider key /// List of provider key: DropboxV2, Box, WebDav, Yandex, OneDrive, SharePoint, GoogleDrive /// [Read("thirdparty/capabilities")] public List> Capabilities() { var result = new List>(); if (UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor(UserManager) || (!FilesSettingsHelper.EnableThirdParty && !CoreBaseSettings.Personal)) { return result; } return ThirdpartyConfiguration.GetProviders(); } /// /// Saves the third party file storage service account /// /// Save third party account /// Connection url for SharePoint /// Login /// Password /// Authentication token /// /// Title /// Provider Key /// Provider ID /// Third-Party Integration /// Folder contents /// List of provider key: DropboxV2, Box, WebDav, Yandex, OneDrive, SharePoint, GoogleDrive /// [Create("thirdparty")] public Task> SaveThirdPartyFromBodyAsync([FromBody] ThirdPartyModel model) { return SaveThirdPartyAsync(model); } [Create("thirdparty")] [Consumes("application/x-www-form-urlencoded")] public Task> SaveThirdPartyFromFormAsync([FromForm] ThirdPartyModel model) { return SaveThirdPartyAsync(model); } private async Task> SaveThirdPartyAsync(ThirdPartyModel model) { var thirdPartyParams = new ThirdPartyParams { AuthData = new AuthData(model.Url, model.Login, model.Password, model.Token), Corporate = model.IsCorporate, CustomerTitle = model.CustomerTitle, ProviderId = model.ProviderId, ProviderKey = model.ProviderKey, }; var folder = await FileStorageService.SaveThirdPartyAsync(thirdPartyParams); return await FolderWrapperHelper.GetAsync(folder); } /// /// Returns the list of all connected third party services /// /// Third-Party Integration /// Get third party list /// Connected providers [Read("thirdparty")] public async Task> GetThirdPartyAccountsAsync() { return await FileStorageService.GetThirdPartyAsync(); } /// /// Returns the list of third party services connected in the 'Common Documents' section /// /// Third-Party Integration /// Get third party folder /// Connected providers folder [Read("thirdparty/common")] public async Task>> GetCommonThirdPartyFoldersAsync() { var parent = await FileStorageServiceInt.GetFolderAsync(await GlobalFolderHelper.FolderCommonAsync); var thirdpartyFolders = await EntryManager.GetThirpartyFoldersAsync(parent); var result = new List>(); foreach (var r in thirdpartyFolders) { result.Add(await FolderWrapperHelper.GetAsync(r)); } return result; } /// /// Removes the third party file storage service account with the ID specified in the request /// /// Provider ID. Provider id is part of folder id. /// Example, folder id is "sbox-123", then provider id is "123" /// /// Remove third party account /// Third-Party Integration /// Folder id /// [Delete("thirdparty/{providerId:int}")] public Task DeleteThirdPartyAsync(int providerId) { return FileStorageService.DeleteThirdPartyAsync(providerId.ToString(CultureInfo.InvariantCulture)); } ///// ///// ///// ///// ///// //[Read(@"@search/{query}")] //public IEnumerable Search(string query) //{ // var searcher = new SearchHandler(); // var files = searcher.SearchFiles(query).Select(r => (FileEntryWrapper)FileWrapperHelper.Get(r)); // var folders = searcher.SearchFolders(query).Select(f => (FileEntryWrapper)FolderWrapperHelper.Get(f)); // return files.Concat(folders); //} /// /// Adding files to favorite list /// /// Favorite add /// Files /// /// File IDs /// [Create("favorites")] public Task AddFavoritesFromBodyAsync([FromBody] BaseBatchModel model) { return AddFavoritesAsync(model); } [Create("favorites")] [Consumes("application/x-www-form-urlencoded")] public async Task AddFavoritesFromFormAsync([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchModel model) { return await AddFavoritesAsync(model); } private async Task AddFavoritesAsync(BaseBatchModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); await FileStorageServiceInt.AddToFavoritesAsync(folderIntIds, fileIntIds); await FileStorageService.AddToFavoritesAsync(folderStringIds, fileStringIds); return true; } [Read("favorites/{fileId}")] public Task ToggleFileFavoriteAsync(string fileId, bool favorite) { return FileStorageService.ToggleFileFavoriteAsync(fileId, favorite); } [Read("favorites/{fileId:int}")] public Task ToggleFavoriteFromFormAsync(int fileId, bool favorite) { return FileStorageServiceInt.ToggleFileFavoriteAsync(fileId, favorite); } /// /// Removing files from favorite list /// /// Favorite delete /// Files /// /// File IDs /// [Delete("favorites")] [Consumes("application/json")] public Task DeleteFavoritesFromBodyAsync([FromBody] BaseBatchModel model) { return DeleteFavoritesAsync(model); } [Delete("favorites")] public async Task DeleteFavoritesFromQueryAsync([FromQuery][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchModel model) { return await DeleteFavoritesAsync(model); } private async Task DeleteFavoritesAsync(BaseBatchModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); await FileStorageServiceInt.DeleteFavoritesAsync(folderIntIds, fileIntIds); await FileStorageService.DeleteFavoritesAsync(folderStringIds, fileStringIds); return true; } /// /// Adding files to template list /// /// Template add /// Files /// File IDs /// [Create("templates")] public async Task AddTemplatesFromBodyAsync([FromBody] TemplatesModel model) { await FileStorageServiceInt.AddToTemplatesAsync(model.FileIds); return true; } [Create("templates")] [Consumes("application/x-www-form-urlencoded")] public async Task AddTemplatesFromFormAsync([FromForm] TemplatesModel model) { await FileStorageServiceInt.AddToTemplatesAsync(model.FileIds); return true; } /// /// Removing files from template list /// /// Template delete /// Files /// File IDs /// [Delete("templates")] public async Task DeleteTemplatesAsync(IEnumerable fileIds) { await FileStorageServiceInt.DeleteTemplatesAsync(fileIds); return true; } /// /// /// /// /// [Update(@"storeoriginal")] public bool StoreOriginalFromBody([FromBody] SettingsModel model) { return FileStorageService.StoreOriginal(model.Set); } [Update(@"storeoriginal")] [Consumes("application/x-www-form-urlencoded")] public bool StoreOriginalFromForm([FromForm] SettingsModel model) { return FileStorageService.StoreOriginal(model.Set); } /// /// /// /// [Read(@"settings")] public FilesSettingsHelper GetFilesSettings() { return FilesSettingsHelper; } /// /// /// /// /// false /// [Update(@"hideconfirmconvert")] public bool HideConfirmConvertFromBody([FromBody] HideConfirmConvertModel model) { return FileStorageService.HideConfirmConvert(model.Save); } [Update(@"hideconfirmconvert")] [Consumes("application/x-www-form-urlencoded")] public bool HideConfirmConvertFromForm([FromForm] HideConfirmConvertModel model) { return FileStorageService.HideConfirmConvert(model.Save); } /// /// /// /// /// [Update(@"updateifexist")] public bool UpdateIfExistFromBody([FromBody] SettingsModel model) { return FileStorageService.UpdateIfExist(model.Set); } [Update(@"updateifexist")] [Consumes("application/x-www-form-urlencoded")] public bool UpdateIfExistFromForm([FromForm] SettingsModel model) { return FileStorageService.UpdateIfExist(model.Set); } /// /// /// /// /// [Update(@"changedeleteconfrim")] public bool ChangeDeleteConfrimFromBody([FromBody] SettingsModel model) { return FileStorageService.ChangeDeleteConfrim(model.Set); } [Update(@"changedeleteconfrim")] [Consumes("application/x-www-form-urlencoded")] public bool ChangeDeleteConfrimFromForm([FromForm] SettingsModel model) { return FileStorageService.ChangeDeleteConfrim(model.Set); } /// /// /// /// /// [Update(@"storeforcesave")] public bool StoreForcesaveFromBody([FromBody] SettingsModel model) { return FileStorageService.StoreForcesave(model.Set); } [Update(@"storeforcesave")] [Consumes("application/x-www-form-urlencoded")] public bool StoreForcesaveFromForm([FromForm] SettingsModel model) { return FileStorageService.StoreForcesave(model.Set); } /// /// /// /// /// [Update(@"forcesave")] public bool ForcesaveFromBody([FromBody] SettingsModel model) { return FileStorageService.Forcesave(model.Set); } [Update(@"forcesave")] [Consumes("application/x-www-form-urlencoded")] public bool ForcesaveFromForm([FromForm] SettingsModel model) { return FileStorageService.Forcesave(model.Set); } /// /// /// /// /// [Update(@"thirdparty")] public bool ChangeAccessToThirdpartyFromBody([FromBody] SettingsModel model) { return FileStorageService.ChangeAccessToThirdparty(model.Set); } [Update(@"thirdparty")] [Consumes("application/x-www-form-urlencoded")] public bool ChangeAccessToThirdpartyFromForm([FromForm] SettingsModel model) { return FileStorageService.ChangeAccessToThirdparty(model.Set); } /// /// Display recent folder /// /// /// Settings /// [Update(@"displayRecent")] public bool DisplayRecentFromBody([FromBody] DisplayModel model) { return FileStorageService.DisplayRecent(model.Set); } [Update(@"displayRecent")] [Consumes("application/x-www-form-urlencoded")] public bool DisplayRecentFromForm([FromForm] DisplayModel model) { return FileStorageService.DisplayRecent(model.Set); } /// /// Display favorite folder /// /// /// Settings /// [Update(@"settings/favorites")] public bool DisplayFavoriteFromBody([FromBody] DisplayModel model) { return FileStorageService.DisplayFavorite(model.Set); } [Update(@"settings/favorites")] [Consumes("application/x-www-form-urlencoded")] public bool DisplayFavoriteFromForm([FromForm] DisplayModel model) { return FileStorageService.DisplayFavorite(model.Set); } /// /// Display template folder /// /// /// Settings /// [Update(@"settings/templates")] public bool DisplayTemplatesFromBody([FromBody] DisplayModel model) { return FileStorageService.DisplayTemplates(model.Set); } [Update(@"settings/templates")] [Consumes("application/x-www-form-urlencoded")] public bool DisplayTemplatesFromForm([FromForm] DisplayModel model) { return FileStorageService.DisplayTemplates(model.Set); } /// /// /// /// /// Settings /// [Update(@"settings/downloadtargz")] public ICompress ChangeDownloadZipFromBody([FromBody] DisplayModel model) { return FileStorageService.ChangeDownloadTarGz(model.Set); } [Update(@"settings/downloadtargz")] public ICompress ChangeDownloadZipFromForm([FromForm] DisplayModel model) { return FileStorageService.ChangeDownloadTarGz(model.Set); } /// /// Checking document service location /// /// Document editing service Domain /// Document command service Domain /// Community Server Address /// [Update("docservice")] public Task> CheckDocServiceUrlFromBodyAsync([FromBody] CheckDocServiceUrlModel model) { return CheckDocServiceUrlAsync(model); } [Update("docservice")] [Consumes("application/x-www-form-urlencoded")] public Task> CheckDocServiceUrlFromFormAsync([FromForm] CheckDocServiceUrlModel model) { return CheckDocServiceUrlAsync(model); } /// /// Create thumbnails for files with the IDs specified in the request /// /// Create thumbnails /// Files /// File IDs /// false /// [Create("thumbnails")] public Task> CreateThumbnailsFromBodyAsync([FromBody] BaseBatchModel model) { return FileStorageService.CreateThumbnailsAsync(model.FileIds.ToList()); } [Create("thumbnails")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateThumbnailsFromFormAsync([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchModel model) { return await FileStorageService.CreateThumbnailsAsync(model.FileIds.ToList()); } [Create("masterform/{fileId}/checkfillformdraft")] public async Task CheckFillFormDraftFromBodyAsync(string fileId, [FromBody] CheckFillFormDraftModel model) { return await FilesControllerHelperString.CheckFillFormDraftAsync(fileId, model.Version, model.Doc, !model.RequestEmbedded, model.RequestView); } [Create("masterform/{fileId}/checkfillformdraft")] [Consumes("application/x-www-form-urlencoded")] public async Task CheckFillFormDraftFromFormAsync(string fileId, [FromForm] CheckFillFormDraftModel model) { return await FilesControllerHelperString.CheckFillFormDraftAsync(fileId, model.Version, model.Doc, !model.RequestEmbedded, model.RequestView); } [Create("masterform/{fileId:int}/checkfillformdraft")] public async Task CheckFillFormDraftFromBodyAsync(int fileId, [FromBody] CheckFillFormDraftModel model) { return await FilesControllerHelperInt.CheckFillFormDraftAsync(fileId, model.Version, model.Doc, !model.RequestEmbedded, model.RequestView); } [Create("masterform/{fileId:int}/checkfillformdraft")] [Consumes("application/x-www-form-urlencoded")] public async Task CheckFillFormDraftFromFormAsync(int fileId, [FromForm] CheckFillFormDraftModel model) { return await FilesControllerHelperInt.CheckFillFormDraftAsync(fileId, model.Version, model.Doc, !model.RequestEmbedded, model.RequestView); } public Task> CheckDocServiceUrlAsync(CheckDocServiceUrlModel model) { FilesLinkUtility.DocServiceUrl = model.DocServiceUrl; FilesLinkUtility.DocServiceUrlInternal = model.DocServiceUrlInternal; FilesLinkUtility.DocServicePortalUrl = model.DocServiceUrlPortal; MessageService.Send(MessageAction.DocumentServiceLocationSetting); var https = new Regex(@"^https://", RegexOptions.IgnoreCase); var http = new Regex(@"^http://", RegexOptions.IgnoreCase); if (https.IsMatch(CommonLinkUtility.GetFullAbsolutePath("")) && http.IsMatch(FilesLinkUtility.DocServiceUrl)) { throw new Exception("Mixed Active Content is not allowed. HTTPS address for Document Server is required."); } return InternalCheckDocServiceUrlAsync(); } private async Task> InternalCheckDocServiceUrlAsync() { await DocumentServiceConnector.CheckDocServiceUrlAsync(); return new[] { FilesLinkUtility.DocServiceUrl, FilesLinkUtility.DocServiceUrlInternal, FilesLinkUtility.DocServicePortalUrl }; } /// false [AllowAnonymous] [Read("docservice")] public Task GetDocServiceUrlAsync(bool version) { var url = CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.DocServiceApiUrl); if (!version) { return Task.FromResult(url); } return InternalGetDocServiceUrlAsync(url); } private async Task InternalGetDocServiceUrlAsync(string url) { var dsVersion = await DocumentServiceConnector.GetVersionAsync(); return new { version = dsVersion, docServiceUrlApi = url, }; } #region wordpress /// false [Read("wordpress-info")] public object GetWordpressInfo() { var token = WordpressToken.GetToken(); if (token != null) { var meInfo = WordpressHelper.GetWordpressMeInfo(token.AccessToken); var blogId = JObject.Parse(meInfo).Value("token_site_id"); var wordpressUserName = JObject.Parse(meInfo).Value("username"); var blogInfo = _requestHelper.PerformRequest(WordpressLoginProvider.WordpressSites + blogId, "", "GET", ""); var jsonBlogInfo = JObject.Parse(blogInfo); jsonBlogInfo.Add("username", wordpressUserName); blogInfo = jsonBlogInfo.ToString(); return new { success = true, data = blogInfo }; } return new { success = false }; } /// false [Read("wordpress-delete")] public object DeleteWordpressInfo() { var token = WordpressToken.GetToken(); if (token != null) { WordpressToken.DeleteToken(token); return new { success = true }; } return new { success = false }; } /// false [Create("wordpress-save")] public object WordpressSaveFromBody([FromBody] WordpressSaveModel model) { return WordpressSave(model); } [Create("wordpress-save")] [Consumes("application/x-www-form-urlencoded")] public object WordpressSaveFromForm([FromForm] WordpressSaveModel model) { return WordpressSave(model); } private object WordpressSave(WordpressSaveModel model) { if (model.Code.Length == 0) { return new { success = false }; } try { var token = WordpressToken.SaveTokenFromCode(model.Code); var meInfo = WordpressHelper.GetWordpressMeInfo(token.AccessToken); var blogId = JObject.Parse(meInfo).Value("token_site_id"); var wordpressUserName = JObject.Parse(meInfo).Value("username"); var blogInfo = _requestHelper.PerformRequest(WordpressLoginProvider.WordpressSites + blogId, "", "GET", ""); var jsonBlogInfo = JObject.Parse(blogInfo); jsonBlogInfo.Add("username", wordpressUserName); blogInfo = jsonBlogInfo.ToString(); return new { success = true, data = blogInfo }; } catch (Exception) { return new { success = false }; } } /// false [Create("wordpress")] public bool CreateWordpressPostFromBody([FromBody] CreateWordpressPostModel model) { return CreateWordpressPost(model); } [Create("wordpress")] [Consumes("application/x-www-form-urlencoded")] public bool CreateWordpressPostFromForm([FromForm] CreateWordpressPostModel model) { return CreateWordpressPost(model); } private bool CreateWordpressPost(CreateWordpressPostModel model) { try { var token = WordpressToken.GetToken(); var meInfo = WordpressHelper.GetWordpressMeInfo(token.AccessToken); var parser = JObject.Parse(meInfo); if (parser == null) return false; var blogId = parser.Value("token_site_id"); if (blogId != null) { var createPost = WordpressHelper.CreateWordpressPost(model.Title, model.Content, model.Status, blogId, token); return createPost; } return false; } catch (Exception) { return false; } } #endregion #region easybib /// false [Read("easybib-citation-list")] public object GetEasybibCitationList(int source, string data) { try { var citationList = EasyBibHelper.GetEasyBibCitationsList(source, data); return new { success = true, citations = citationList }; } catch (Exception) { return new { success = false }; } } /// false [Read("easybib-styles")] public object GetEasybibStyles() { try { var data = EasyBibHelper.GetEasyBibStyles(); return new { success = true, styles = data }; } catch (Exception) { return new { success = false }; } } /// false [Create("easybib-citation")] public object EasyBibCitationBookFromBody([FromBody] EasyBibCitationBookModel model) { return EasyBibCitationBook(model); } [Create("easybib-citation")] [Consumes("application/x-www-form-urlencoded")] public object EasyBibCitationBookFromForm([FromForm] EasyBibCitationBookModel model) { return EasyBibCitationBook(model); } private object EasyBibCitationBook(EasyBibCitationBookModel model) { try { var citat = EasyBibHelper.GetEasyBibCitation(model.CitationData); if (citat != null) { return new { success = true, citation = citat }; } else { return new { success = false }; } } catch (Exception) { return new { success = false }; } } #endregion /// /// Result of file conversation operation. /// public class ConversationResult { /// /// Operation Id. /// public string Id { get; set; } /// /// Operation type. /// [JsonPropertyName("Operation")] public FileOperationType OperationType { get; set; } /// /// Operation progress. /// public int Progress { get; set; } /// /// Source files for operation. /// public string Source { get; set; } /// /// Result file of operation. /// [JsonPropertyName("result")] public object File { get; set; } /// /// Error during conversation. /// public string Error { get; set; } /// /// Is operation processed. /// public string Processed { get; set; } } } }