/* * * (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.Diagnostics; using System.Globalization; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Threading; 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.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.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; namespace ASC.Api.Documents { /// /// Provides access to documents /// [Scope] [DefaultRoute] [ApiController] public class FilesController : ControllerBase { private readonly FileStorageService FileStorageService; 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; } /// /// /// /// 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) { 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; } [Read("info")] public Module GetModule() { ProductEntryPoint.Init(); return new Module(ProductEntryPoint); } [Read("@root")] public async Task>> GetRootFoldersAsync(Guid userIdOrGroupId, FilterType filterType, 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(GlobalFolderHelper.FolderShare); } if (!IsVisitor && !withoutAdditionalFolder) { if (FilesSettingsHelper.FavoritesSection) { folders.Add(GlobalFolderHelper.FolderFavorites); } if (FilesSettingsHelper.RecentSection) { folders.Add(GlobalFolderHelper.FolderRecent); } if (!CoreBaseSettings.Personal && PrivacyRoomSettings.IsAvailable(TenantManager)) { folders.Add(GlobalFolderHelper.FolderPrivacy); } } if (!CoreBaseSettings.Personal) { folders.Add(GlobalFolderHelper.FolderCommon); } if (!IsVisitor && !withoutAdditionalFolder && FileUtility.ExtsWebTemplate.Any() && FilesSettingsHelper.TemplatesSection) { folders.Add(GlobalFolderHelper.FolderTemplates); } if (!withoutTrash) { folders.Add((int)GlobalFolderHelper.FolderTrash); } var result = new List>(); foreach (var folder in folders) { result.Add(await FilesControllerHelperInt.GetFolderAsync(folder, userIdOrGroupId, filterType, withsubfolders)); } return result; } [Read("@privacy")] public async Task> GetPrivacyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { if (!IsAvailablePrivacyRoomSettings()) throw new System.Security.SecurityException(); return await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderPrivacy, userIdOrGroupId, filterType, 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 async Task> GetMyFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var res = await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderMy, userIdOrGroupId, filterType, withsubfolders); stopWatch.Stop(); TimeSpan sw = stopWatch.Elapsed; return res; } /// /// 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 withsubfolders) { return await FilesControllerHelperString.GetFolderAsync(GlobalFolderHelper.GetFolderProjects(), userIdOrGroupId, filterType, 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 withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderCommon, userIdOrGroupId, filterType, 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 withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderShare, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of recent files /// /// Section Recent /// Folders /// Recent contents [Read("@recent")] public async Task> GetRecentFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderRecent, userIdOrGroupId, filterType, withsubfolders); } [Create("file/{fileId}/recent", order: int.MaxValue)] public async Task> AddToRecentAsync(string fileId) { return await FilesControllerHelperString.AddToRecentAsync(fileId); } [Create("file/{fileId:int}/recent", order: int.MaxValue - 1)] public async Task> AddToRecentAsync(int fileId) { return await 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 withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderFavorites, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of templates files /// /// Section Template /// Folders /// Templates contents [Read("@templates")] public async Task> GetTemplatesFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(GlobalFolderHelper.FolderTemplates, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of files and folders located in the 'Recycle Bin' section /// /// /// Trash folder /// /// Folders /// Trash folder contents [Read("@trash")] public async Task> GetTrashFolderAsync(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(Convert.ToInt32(GlobalFolderHelper.FolderTrash), userIdOrGroupId, filterType, 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 withsubfolders) { var folder = await FilesControllerHelperString.GetFolderAsync(folderId, userIdOrGroupId, filterType, withsubfolders); return folder.NotFoundIfNull(); } [Read("{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public async Task> GetFolderAsync(int folderId, Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return await FilesControllerHelperInt.GetFolderAsync(folderId, userIdOrGroupId, filterType, withsubfolders); } [Read("{folderId}/subfolders")] public async Task> GetFoldersAsync(string folderId) { return await FilesControllerHelperString.GetFoldersAsync(folderId).ToListAsync(); } [Read("{folderId:int}/subfolders")] public async Task> GetFoldersAsync(int folderId) { return await FilesControllerHelperInt.GetFoldersAsync(folderId).ToListAsync(); } [Read("{folderId}/news")] public async Task> GetNewItemsAsync(string folderId) { return await FilesControllerHelperString.GetNewItemsAsync(folderId); } [Read("{folderId:int}/news")] public async Task> GetNewItemsAsync(int folderId) { return await 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 async Task UploadFileToMyAsync([ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return await 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(GlobalFolderHelper.FolderCommon, 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 async Task UploadFileAsync(string folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { return await FilesControllerHelperString.UploadFileAsync(folderId, uploadModel); } [Create("{folderId:int}/upload", order: int.MaxValue - 1)] public async Task UploadFileAsync(int folderId, [ModelBinder(BinderType = typeof(UploadModelBinder))] UploadModel uploadModel) { return await 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 async Task> InsertFileToMyFromBodyAsync([FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return await 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(GlobalFolderHelper.FolderCommon, 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 async Task> InsertFileAsync(string folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return await FilesControllerHelperString.InsertFileAsync(folderId, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } [Create("{folderId:int}/insert", order: int.MaxValue - 1)] public async Task> InsertFileFromFormAsync(int folderId, [FromForm][ModelBinder(BinderType = typeof(InsertFileModelBinder))] InsertFileModel model) { return await InsertFileAsync(folderId, model); } private async Task> InsertFileAsync(int folderId, InsertFileModel model) { return await FilesControllerHelperInt.InsertFileAsync(folderId, model.Stream, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } /// /// /// /// /// /// /// /// false [Update("{fileId}/update")] public FileWrapper UpdateFileStreamFromForm(string fileId, [FromForm] FileStreamModel model) { return FilesControllerHelperString.UpdateFileStream(FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(), fileId, model.Encrypted, model.Forcesave); } [Update("{fileId:int}/update")] public FileWrapper UpdateFileStreamFromForm(int fileId, [FromForm] FileStreamModel model) { return FilesControllerHelperInt.UpdateFileStream(FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(), fileId, model.Encrypted, model.Forcesave); } /// /// /// /// File ID /// /// /// /// /// /// Files /// [Update("file/{fileId}/saveediting")] public async Task> SaveEditingFromFormAsync(string fileId, [FromForm] SaveEditingModel model) { using var stream = FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(); return await FilesControllerHelperString.SaveEditingAsync(fileId, model.FileExtension, model.DownloadUri, stream, model.Doc, model.Forcesave); } [Update("file/{fileId:int}/saveediting")] public async Task> SaveEditingFromFormAsync(int fileId, [FromForm] SaveEditingModel model) { using var stream = FilesControllerHelperInt.GetFileFromRequest(model).OpenReadStream(); return await 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 async Task> TrackEditFileAsync(string fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish) { return await FilesControllerHelperString.TrackEditFileAsync(fileId, tabId, docKeyForTrack, doc, isFinish); } [Read("file/{fileId:int}/trackeditfile")] public async Task> TrackEditFileAsync(int fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish) { return await FilesControllerHelperInt.TrackEditFileAsync(fileId, tabId, docKeyForTrack, doc, isFinish); } /// /// /// /// File ID /// /// /// Files /// [AllowAnonymous] [Read("file/{fileId}/openedit", Check = false)] public async Task> OpenEditAsync(string fileId, int version, string doc, bool view) { return await FilesControllerHelperString.OpenEditAsync(fileId, version, doc, view); } [AllowAnonymous] [Read("file/{fileId:int}/openedit", Check = false)] public async Task> OpenEditAsync(int fileId, int version, string doc, bool view) { return await 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 async Task CreateUploadSessionFromBodyAsync(string folderId, [FromBody] SessionModel sessionModel) { return await FilesControllerHelperString.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.Encrypted); } [Create("{folderId}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public async Task CreateUploadSessionFromFormAsync(string folderId, [FromForm] SessionModel sessionModel) { return await FilesControllerHelperString.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] public async Task CreateUploadSessionFromBodyAsync(int folderId, [FromBody] SessionModel sessionModel) { return await FilesControllerHelperInt.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public async Task CreateUploadSessionFromFormAsync(int folderId, [FromForm] SessionModel sessionModel) { return await FilesControllerHelperInt.CreateUploadSessionAsync(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, 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 async Task> CreateTextFileInMyFromBodyAsync([FromBody] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(GlobalFolderHelper.FolderMy, model); } [Create("@my/text")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateTextFileInMyFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return await 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(GlobalFolderHelper.FolderCommon, model); } [Create("@common/text")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateTextFileInCommonFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(GlobalFolderHelper.FolderCommon, 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 async Task> CreateTextFileFromBodyAsync(string folderId, [FromBody] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(folderId, model); } [Create("{folderId}/text")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateTextFileFromFormAsync(string folderId, [FromForm] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(folderId, model); } private async Task> CreateTextFileAsync(string folderId, CreateTextOrHtmlFileModel model) { return await FilesControllerHelperString.CreateTextFileAsync(folderId, model.Title, model.Content); } [Create("{folderId:int}/text")] public async Task> CreateTextFileFromBodyAsync(int folderId, [FromBody] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(folderId, model); } [Create("{folderId:int}/text")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateTextFileFromFormAsync(int folderId, [FromForm] CreateTextOrHtmlFileModel model) { return await CreateTextFileAsync(folderId, model); } private async Task> CreateTextFileAsync(int folderId, CreateTextOrHtmlFileModel model) { return await 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 async Task> CreateHtmlFileFromBodyAsync(string folderId, [FromBody] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(folderId, model); } [Create("{folderId}/html")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateHtmlFileFromFormAsync(string folderId, [FromForm] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(folderId, model); } private async Task> CreateHtmlFileAsync(string folderId, CreateTextOrHtmlFileModel model) { return await FilesControllerHelperString.CreateHtmlFileAsync(folderId, model.Title, model.Content); } [Create("{folderId:int}/html")] public async Task> CreateHtmlFileFromBodyAsync(int folderId, [FromBody] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(folderId, model); } [Create("{folderId:int}/html")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateHtmlFileFromFormAsync(int folderId, [FromForm] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(folderId, model); } private async Task> CreateHtmlFileAsync(int folderId, CreateTextOrHtmlFileModel model) { return await 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 async Task> CreateHtmlFileInMyFromBodyAsync([FromBody] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(GlobalFolderHelper.FolderMy, model); } [Create("@my/html")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateHtmlFileInMyFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return await 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(GlobalFolderHelper.FolderCommon, model); } [Create("@common/html")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateHtmlFileInCommonFromFormAsync([FromForm] CreateTextOrHtmlFileModel model) { return await CreateHtmlFileAsync(GlobalFolderHelper.FolderCommon, 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 async Task> CreateFolderFromBodyAsync(string folderId, [FromBody] CreateFolderModel folderModel) { return await FilesControllerHelperString.CreateFolderAsync(folderId, folderModel.Title); } [Create("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateFolderFromFormAsync(string folderId, [FromForm] CreateFolderModel folderModel) { return await FilesControllerHelperString.CreateFolderAsync(folderId, folderModel.Title); } [Create("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public async Task> CreateFolderFromBodyAsync(int folderId, [FromBody] CreateFolderModel folderModel) { return await FilesControllerHelperInt.CreateFolderAsync(folderId, folderModel.Title); } [Create("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateFolderFromFormAsync(int folderId, [FromForm] CreateFolderModel folderModel) { return await 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 async Task> CreateFileFromBodyAsync([FromBody] CreateFileModel model) { return await FilesControllerHelperInt.CreateFileAsync(GlobalFolderHelper.FolderMy, model.Title, model.TemplateId, model.EnableExternalExt); } [Create("@my/file")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateFileFromFormAsync([FromForm] CreateFileModel model) { return await FilesControllerHelperInt.CreateFileAsync(GlobalFolderHelper.FolderMy, model.Title, model.TemplateId, 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 async Task> CreateFileFromBodyAsync(string folderId, [FromBody] CreateFileModel model) { return await FilesControllerHelperString.CreateFileAsync(folderId, model.Title, model.TemplateId, model.EnableExternalExt); } [Create("{folderId}/file")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateFileFromFormAsync(string folderId, [FromForm] CreateFileModel model) { return await FilesControllerHelperString.CreateFileAsync(folderId, model.Title, model.TemplateId, model.EnableExternalExt); } [Create("{folderId:int}/file")] public async Task> CreateFileFromBodyAsync(int folderId, [FromBody] CreateFileModel model) { return await FilesControllerHelperInt.CreateFileAsync(folderId, model.Title, model.TemplateId, model.EnableExternalExt); } [Create("{folderId:int}/file")] [Consumes("application/x-www-form-urlencoded")] public async Task> CreateFileFromFormAsync(int folderId, [FromForm] CreateFileModel model) { return await FilesControllerHelperInt.CreateFileAsync(folderId, model.Title, model.TemplateId, 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 async Task> RenameFolderFromBodyAsync(string folderId, [FromBody] CreateFolderModel folderModel) { return await FilesControllerHelperString.RenameFolderAsync(folderId, folderModel.Title); } [Update("folder/{folderId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public async Task> RenameFolderFromFormAsync(string folderId, [FromForm] CreateFolderModel folderModel) { return await FilesControllerHelperString.RenameFolderAsync(folderId, folderModel.Title); } [Update("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public async Task> RenameFolderFromBodyAsync(int folderId, [FromBody] CreateFolderModel folderModel) { return await FilesControllerHelperInt.RenameFolderAsync(folderId, folderModel.Title); } [Update("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public async Task> RenameFolderFromFormAsync(int folderId, [FromForm] CreateFolderModel folderModel) { return await FilesControllerHelperInt.RenameFolderAsync(folderId, folderModel.Title); } [Create("owner")] public async Task> ChangeOwnerFromBodyAsync([FromBody] ChangeOwnerModel model) { return await ChangeOwnerAsync(model).ToListAsync(); } [Create("owner")] [Consumes("application/x-www-form-urlencoded")] public async Task> ChangeOwnerFromFormAsync([FromForm] ChangeOwnerModel model) { return await ChangeOwnerAsync(model).ToListAsync(); } public async IAsyncEnumerable ChangeOwnerAsync(ChangeOwnerModel model) { var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(model.FolderIds); var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(model.FileIds); var result = new List(); result.AddRange(await FileStorageServiceInt.ChangeOwnerAsync(folderIntIds, fileIntIds, model.UserId)); result.AddRange(await FileStorageService.ChangeOwnerAsync(folderStringIds, fileStringIds, model.UserId)); foreach(var e in result) { yield return await FilesControllerHelperInt.GetFileEntryWrapperAsync(e); } } /// /// 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 async Task> GetFolderInfoAsync(string folderId) { return await FilesControllerHelperString.GetFolderInfoAsync(folderId); } [Read("folder/{folderId:int}", order: int.MaxValue - 1, DisableFormat = true)] public async Task> GetFolderInfoAsync(int folderId) { return await FilesControllerHelperInt.GetFolderInfoAsync(folderId); } /// /// Returns parent folders /// /// /// Folders /// Parent folders [Read("folder/{folderId}/path")] public async Task> GetFolderPathAsync(string folderId) { return await FilesControllerHelperString.GetFolderPathAsync(folderId).ToListAsync(); } [Read("folder/{folderId:int}/path")] public async Task> GetFolderPathAsync(int folderId) { return await FilesControllerHelperInt.GetFolderPathAsync(folderId).ToListAsync(); } /// /// Returns a detailed information about the file with the ID specified in the request /// /// File information /// Files /// File info [Read("fileAsync/{fileId}", order: int.MaxValue, DisableFormat = true)] public async Task> GetFileInfoAsync(string fileId, int version = -1) { return await FilesControllerHelperString.GetFileInfoAsync(fileId, version); } [Read("fileAsync/{fileId:int}")] public async Task> GetFileInfoAsync(int fileId, int version = -1) { return await FilesControllerHelperInt.GetFileInfoAsync(fileId, version); } /// /// 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("fileAsync/{fileId}", order: int.MaxValue, DisableFormat = true)] public async Task> UpdateFileFromBodyAsync(string fileId, [FromBody] UpdateFileModel model) { return await FilesControllerHelperString.UpdateFileAsync(fileId, model.Title, model.LastVersion); } [Update("fileAsync/{fileId}", order: int.MaxValue, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public async Task> UpdateFileFromFormAsync(string fileId, [FromForm] UpdateFileModel model) { return await FilesControllerHelperString.UpdateFileAsync(fileId, model.Title, model.LastVersion); } [Update("fileAsync/{fileId:int}", order: int.MaxValue - 1, DisableFormat = true)] public async Task> UpdateFileFromBodyAsync(int fileId, [FromBody] UpdateFileModel model) { return await FilesControllerHelperInt.UpdateFileAsync(fileId, model.Title, model.LastVersion); } [Update("fileAsync/{fileId:int}", order: int.MaxValue - 1, DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public async Task> UpdateFileFromFormAsync(int fileId, [FromForm] UpdateFileModel model) { return await 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 IEnumerable DeleteFile(string fileId, [FromBody] DeleteModel model) { return FilesControllerHelperString.DeleteFile(fileId, model.DeleteAfter, model.Immediately); } [Delete("file/{fileId:int}", order: int.MaxValue - 1, DisableFormat = true)] public IEnumerable DeleteFile(int fileId, [FromBody] DeleteModel model) { return FilesControllerHelperInt.DeleteFile(fileId, model.DeleteAfter, model.Immediately); } /// /// Start conversion /// /// Convert /// File operations /// /// Operation result [Update("file/{fileId}/checkconversion")] public async Task>> StartConversionAsync(string fileId, [FromBody(EmptyBodyBehavior = Microsoft.AspNetCore.Mvc.ModelBinding.EmptyBodyBehavior.Allow)] CheckConversionModel model) { return await FilesControllerHelperString.StartConversionAsync(fileId, model?.Sync ?? false).ToListAsync(); } [Update("file/{fileId:int}/checkconversion")] public async Task>> StartConversionAsync(int fileId, [FromBody(EmptyBodyBehavior = Microsoft.AspNetCore.Mvc.ModelBinding.EmptyBodyBehavior.Allow)] CheckConversionModel model) { return await FilesControllerHelperInt.StartConversionAsync(fileId, model?.Sync ?? false).ToListAsync(); } /// /// Check conversion status /// /// Convert /// File operations /// /// /// Operation result [Read("file/{fileId}/checkconversion")] public async Task>> CheckConversionAsync(string fileId, bool start) { return await FilesControllerHelperString.CheckConversionAsync(fileId, start).ToListAsync(); } [Read("file/{fileId:int}/checkconversion")] public async Task>> CheckConversionAsync(int fileId, bool start) { return await FilesControllerHelperInt.CheckConversionAsync(fileId, start).ToListAsync(); } /// /// 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 IEnumerable DeleteFolder(string folderId, bool deleteAfter, bool immediately) { return FilesControllerHelperString.DeleteFolder(folderId, deleteAfter, immediately); } [Delete("folder/{folderId:int}")] public IEnumerable 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 async Task> MoveOrCopyBatchCheckAsync([ModelBinder(BinderType = typeof(BatchModelBinder))] BatchModel batchModel) { return await FilesControllerHelperString.MoveOrCopyBatchCheckAsync(batchModel).ToListAsync(); } /// /// 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 IEnumerable MoveBatchItemsFromBody([FromBody] BatchModel batchModel) { return FilesControllerHelperString.MoveBatchItems(batchModel); } [Update("fileops/move")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable MoveBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(BatchModelBinder))] BatchModel batchModel) { return FilesControllerHelperString.MoveBatchItems(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 IEnumerable CopyBatchItemsFromBody([FromBody] BatchModel batchModel) { return FilesControllerHelperString.CopyBatchItems(batchModel); } [Update("fileops/copy")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable CopyBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(BatchModelBinder))] BatchModel batchModel) { return FilesControllerHelperString.CopyBatchItems(batchModel); } /// /// Marks all files and folders as read /// /// Mark as read /// File operations /// Operation result [Update("fileops/markasread")] public IEnumerable MarkAsReadFromBody([FromBody] BaseBatchModel model) { return FilesControllerHelperString.MarkAsRead(model); } [Update("fileops/markasread")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable MarkAsReadFromForm([FromForm][ModelBinder(BinderType = typeof(BaseBatchModelBinder))] BaseBatchModel model) { return FilesControllerHelperString.MarkAsRead(model); } /// /// Finishes all the active file operations /// /// Finish all /// File operations /// Operation result [Update("fileops/terminate")] public IEnumerable TerminateTasks() { return FileStorageService.TerminateTasks().Select(FileOperationWraperHelper.Get); } /// /// Returns the list of all active file operations /// /// Get file operations list /// File operations /// Operation result [Read("fileops")] public IEnumerable GetOperationStatuses() { return FileStorageService.GetTasksStatuses().Select(FileOperationWraperHelper.Get); } /// /// 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 IEnumerable BulkDownload([FromBody] DownloadModel model) { return FilesControllerHelperString.BulkDownload(model); } [Update("fileops/bulkdownload")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable BulkDownloadFromForm([FromForm] DownloadModel model) { return FilesControllerHelperString.BulkDownload(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 IEnumerable DeleteBatchItemsFromBody([FromBody] DeleteBatchModel batch) { return FileStorageService.DeleteItems("delete", batch.FileIds.ToList(), batch.FolderIds.ToList(), false, batch.DeleteAfter, batch.Immediately) .Select(FileOperationWraperHelper.Get); } [Update("fileops/delete")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable DeleteBatchItemsFromForm([FromForm][ModelBinder(BinderType = typeof(DeleteBatchModelBinder))] DeleteBatchModel batch) { return FileStorageService.DeleteItems("delete", batch.FileIds.ToList(), batch.FolderIds.ToList(), false, batch.DeleteAfter, batch.Immediately) .Select(FileOperationWraperHelper.Get); } /// /// Deletes all files and folders from the recycle bin /// /// Clear recycle bin /// File operations /// Operation result [Update("fileops/emptytrash")] public IEnumerable EmptyTrash() { return FilesControllerHelperInt.EmptyTrash(); } /// /// 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 async Task>> GetFileVersionInfoAsync(string fileId) { return await FilesControllerHelperString.GetFileVersionInfoAsync(fileId); } [Read("file/{fileId:int}/history")] public async Task>> GetFileVersionInfoAsync(int fileId) { return await FilesControllerHelperInt.GetFileVersionInfoAsync(fileId); } [Read("file/{fileId}/presigned")] public async Task GetPresignedUriAsync(string fileId) { return await FilesControllerHelperString.GetPresignedUriAsync(fileId); } [Read("file/{fileId:int}/presigned")] public async Task GetPresignedUriAsync(int fileId) { return await FilesControllerHelperInt.GetPresignedUriAsync(fileId); } /// /// Change version history /// /// File ID /// Version of history /// Mark as version or revision /// Files /// [Update("file/{fileId}/history")] public async Task>> ChangeHistoryFromBodyAsync(string fileId, [FromBody] ChangeHistoryModel model) { return await FilesControllerHelperString.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId}/history")] [Consumes("application/x-www-form-urlencoded")] public async Task>> ChangeHistoryFromFormAsync(string fileId, [FromForm] ChangeHistoryModel model) { return await FilesControllerHelperString.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId:int}/history")] public async Task>> ChangeHistoryFromBodyAsync(int fileId, [FromBody] ChangeHistoryModel model) { return await FilesControllerHelperInt.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId:int}/history")] [Consumes("application/x-www-form-urlencoded")] public async Task>> ChangeHistoryFromFormAsync(int fileId, [FromForm] ChangeHistoryModel model) { return await FilesControllerHelperInt.ChangeHistoryAsync(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId}/lock")] public async Task> LockFileFromBodyAsync(string fileId, [FromBody] LockFileModel model) { return await FilesControllerHelperString.LockFileAsync(fileId, model.LockFile); } [Update("file/{fileId}/lock")] [Consumes("application/x-www-form-urlencoded")] public async Task> LockFileFromFormAsync(string fileId, [FromForm] LockFileModel model) { return await FilesControllerHelperString.LockFileAsync(fileId, model.LockFile); } [Update("file/{fileId:int}/lock")] public async Task> LockFileFromBodyAsync(int fileId, [FromBody] LockFileModel model) { return await FilesControllerHelperInt.LockFileAsync(fileId, model.LockFile); } [Update("file/{fileId:int}/lock")] [Consumes("application/x-www-form-urlencoded")] public async Task> LockFileFromFormAsync(int fileId, [FromForm] LockFileModel model) { return await FilesControllerHelperInt.LockFileAsync(fileId, model.LockFile); } [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 async Task> GetFileSecurityInfoAsync(string fileId) { return await FilesControllerHelperString.GetFileSecurityInfoAsync(fileId); } [Read("file/{fileId:int}/share")] public async Task> GetFileSecurityInfoAsync(int fileId) { return await 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 async Task> GetFolderSecurityInfoAsync(string folderId) { return await FilesControllerHelperString.GetFolderSecurityInfoAsync(folderId); } [Read("folder/{folderId:int}/share")] public async Task> GetFolderSecurityInfoAsync(int folderId) { return await 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 async Task> SetFileSecurityInfoFromBodyAsync(string fileId, [FromBody] SecurityInfoModel model) { return await FilesControllerHelperString.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId}/share")] [Consumes("application/x-www-form-urlencoded")] public async Task> SetFileSecurityInfoFromFormAsync(string fileId, [FromForm] SecurityInfoModel model) { return await FilesControllerHelperString.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId:int}/share")] public async Task> SetFileSecurityInfoFromBodyAsync(int fileId, [FromBody] SecurityInfoModel model) { return await FilesControllerHelperInt.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public async Task> SetFileSecurityInfoFromFormAsync(int fileId, [FromForm] SecurityInfoModel model) { return await FilesControllerHelperInt.SetFileSecurityInfoAsync(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("share")] public async Task> SetSecurityInfoFromBodyAsync([FromBody] SecurityInfoModel model) { return await SetSecurityInfoAsync(model); } [Update("share")] [Consumes("application/x-www-form-urlencoded")] public async Task> SetSecurityInfoFromFormAsync([FromForm] SecurityInfoModel model) { return await 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 async Task> SetFolderSecurityInfoFromBodyAsync(string folderId, [FromBody] SecurityInfoModel model) { return await FilesControllerHelperString.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId}/share")] [Consumes("application/x-www-form-urlencoded")] public async Task> SetFolderSecurityInfoFromFormAsync(string folderId, [FromForm] SecurityInfoModel model) { return await FilesControllerHelperString.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId:int}/share")] public async Task> SetFolderSecurityInfoFromBodyAsync(int folderId, [FromBody] SecurityInfoModel model) { return await FilesControllerHelperInt.SetFolderSecurityInfoAsync(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public async Task> SetFolderSecurityInfoFromFormAsync(int folderId, [FromForm] SecurityInfoModel model) { return await 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 async Task SetAceLinkAsync(int fileId, [FromBody] GenerateSharedLinkModel model) { return await FilesControllerHelperInt.SetAceLinkAsync(fileId, model.Share); } [Update("{fileId}/setacelink")] public async Task SetAceLinkAsync(string fileId, [FromBody] GenerateSharedLinkModel model) { return await 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 async Task> SaveThirdPartyFromBodyAsync([FromBody] ThirdPartyModel model) { return await SaveThirdPartyAsync(model); } [Create("thirdparty")] [Consumes("application/x-www-form-urlencoded")] public async Task> SaveThirdPartyFromFormAsync([FromForm] ThirdPartyModel model) { return await 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 = FileStorageServiceInt.GetFolder(GlobalFolderHelper.FolderCommon); var thirdpartyFolders = await EntryManager.GetThirpartyFoldersAsync(parent); return thirdpartyFolders.Select(r => FolderWrapperHelper.Get(r)).ToList(); } /// /// 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 async Task DeleteThirdPartyAsync(int providerId) { return await 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 async Task AddFavoritesFromBodyAsync([FromBody] BaseBatchModel model) { return await 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 async Task ToggleFileFavoriteAsync(string fileId, bool favorite) { return await FileStorageService.ToggleFileFavoriteAsync(fileId, favorite); } [Read("favorites/{fileId:int}")] public async Task ToggleFavoriteFromFormAsync(int fileId, bool favorite) { return await FileStorageServiceInt.ToggleFileFavoriteAsync(fileId, favorite); } /// /// Removing files from favorite list /// /// Favorite delete /// Files /// /// File IDs /// [Delete("favorites")] [Consumes("application/json")] public async Task DeleteFavoritesFromBodyAsync([FromBody] BaseBatchModel model) { return await 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 bool ChangeDownloadZipFromBody([FromBody] DisplayModel model) { return FileStorageService.ChangeDownloadTarGz(model.Set); } [Update(@"settings/downloadtargz")] public bool 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 IEnumerable CheckDocServiceUrlFromBody([FromBody] CheckDocServiceUrlModel model) { return CheckDocServiceUrl(model); } [Update("docservice")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable CheckDocServiceUrlFromForm([FromForm] CheckDocServiceUrlModel model) { return CheckDocServiceUrl(model); } /// /// Create thumbnails for files with the IDs specified in the request /// /// Create thumbnails /// Files /// File IDs /// false /// [Create("thumbnails")] public async Task> CreateThumbnailsFromBodyAsync([FromBody] BaseBatchModel model) { return await 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()); } public IEnumerable CheckDocServiceUrl(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."); } DocumentServiceConnector.CheckDocServiceUrl(); return new[] { FilesLinkUtility.DocServiceUrl, FilesLinkUtility.DocServiceUrlInternal, FilesLinkUtility.DocServicePortalUrl }; } /// false [AllowAnonymous] [Read("docservice")] public object GetDocServiceUrl(bool version) { var url = CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.DocServiceApiUrl); if (!version) { return url; } var dsVersion = DocumentServiceConnector.GetVersion(); 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 == "") { 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 FileWrapper File { get; set; } /// /// Error during conversation. /// public string Error { get; set; } /// /// Is operation processed. /// public string Processed { get; set; } } } }