/* * * (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.IO; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; 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.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Newtonsoft.Json.Linq; namespace ASC.Api.Documents { /// /// Provides access to documents /// [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 ConsumerFactory ConsumerFactory { get; } private EasyBibHelper EasyBibHelper { get; } private ProductEntryPoint ProductEntryPoint { get; } public TenantManager TenantManager { get; } public 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, ConsumerFactory consumerFactory, EasyBibHelper easyBibHelper, ProductEntryPoint productEntryPoint, TenantManager tenantManager, FileUtility fileUtility) { 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; ConsumerFactory = consumerFactory; MessageService = messageService; CommonLinkUtility = commonLinkUtility; DocumentServiceConnector = documentServiceConnector; WordpressToken = wordpressToken; WordpressHelper = wordpressHelper; EasyBibHelper = easyBibHelper; ProductEntryPoint = productEntryPoint; TenantManager = tenantManager; FileUtility = fileUtility; } [Read("info")] public Module GetModule() { ProductEntryPoint.Init(); return new Module(ProductEntryPoint, true); } [Read("@root")] public IEnumerable> GetRootFolders(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders, bool withoutTrash, bool withoutAdditionalFolder) { var IsVisitor = UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor(UserManager); var result = new SortedSet(); if (!IsVisitor) { result.Add(GlobalFolderHelper.FolderMy); } if (!CoreBaseSettings.Personal && !UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsOutsider(UserManager)) { result.Add(GlobalFolderHelper.FolderShare); } if (!IsVisitor && !withoutAdditionalFolder) { if (FilesSettingsHelper.FavoritesSection) { result.Add(GlobalFolderHelper.FolderFavorites); } if (FilesSettingsHelper.RecentSection) { result.Add(GlobalFolderHelper.FolderRecent); } if (PrivacyRoomSettings.IsAvailable(TenantManager)) { result.Add(GlobalFolderHelper.FolderPrivacy); } } if (!CoreBaseSettings.Personal) { result.Add(GlobalFolderHelper.FolderCommon); } if (!IsVisitor && !withoutAdditionalFolder && FileUtility.ExtsWebTemplate.Any() && FilesSettingsHelper.TemplatesSection) { result.Add(GlobalFolderHelper.FolderTemplates); } if (!withoutTrash) { result.Add((int)GlobalFolderHelper.FolderTrash); } return result.Select(r => FilesControllerHelperInt.GetFolder(r, userIdOrGroupId, filterType, withsubfolders)); } [Read("@privacy")] public FolderContentWrapper GetPrivacyFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { if (!IsAvailablePrivacyRoomSettings()) throw new System.Security.SecurityException(); return FilesControllerHelperInt.GetFolder(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 FolderContentWrapper GetMyFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(GlobalFolderHelper.FolderMy, userIdOrGroupId, filterType, 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 FolderContentWrapper GetProjectsFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperString.GetFolder(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 FolderContentWrapper GetCommonFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(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 FolderContentWrapper GetShareFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(GlobalFolderHelper.FolderShare, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of recent files /// /// Section Recent /// Folders /// Recent contents [Read("@recent")] public FolderContentWrapper GetRecentFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(GlobalFolderHelper.FolderRecent, userIdOrGroupId, filterType, withsubfolders); } [Create("file/{fileId}/recent", order: int.MaxValue)] public FileWrapper AddToRecent(string fileId) { return FilesControllerHelperString.AddToRecent(fileId); } [Create("file/{fileId:int}/recent", order: int.MaxValue - 1)] public FileWrapper AddToRecent(int fileId) { return FilesControllerHelperInt.AddToRecent(fileId); } /// /// Returns the detailed list of favorites files /// /// Section Favorite /// Folders /// Favorites contents [Read("@favorites")] public FolderContentWrapper GetFavoritesFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(GlobalFolderHelper.FolderFavorites, userIdOrGroupId, filterType, withsubfolders); } /// /// Returns the detailed list of templates files /// /// Section Template /// Folders /// Templates contents [Read("@templates")] public FolderContentWrapper GetTemplatesFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(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 FolderContentWrapper GetTrashFolder(Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(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 FolderContentWrapper GetFolder(string folderId, Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperString.GetFolder(folderId, userIdOrGroupId, filterType, withsubfolders).NotFoundIfNull(); } [Read("{folderId:int}", order: int.MaxValue - 1)] public FolderContentWrapper GetFolder(int folderId, Guid userIdOrGroupId, FilterType filterType, bool withsubfolders) { return FilesControllerHelperInt.GetFolder(folderId, userIdOrGroupId, filterType, withsubfolders); } [Read("{folderId}/news")] public List GetNewItems(string folderId) { return FilesControllerHelperString.GetNewItems(folderId); } [Read("{folderId:int}/news")] public List GetNewItems(int folderId) { return FilesControllerHelperInt.GetNewItems(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 List> UploadFileToMyFromBody([FromBody]UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return FilesControllerHelperInt.UploadFile(GlobalFolderHelper.FolderMy, uploadModel); } [Create("@my/upload")] [Consumes("application/x-www-form-urlencoded")] public List> UploadFileToMyFromForm([FromForm]UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return FilesControllerHelperInt.UploadFile(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 List> UploadFileToCommonFromBody([FromBody]UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return FilesControllerHelperInt.UploadFile(GlobalFolderHelper.FolderCommon, uploadModel); } [Create("@common/upload")] [Consumes("application/x-www-form-urlencoded")] public List> UploadFileToCommonFromForm([FromForm]UploadModel uploadModel) { uploadModel.CreateNewIfExist = false; return FilesControllerHelperInt.UploadFile(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", DisableFormat = true)] public List> UploadFileFromBody(string folderId, [FromBody]UploadModel uploadModel) { return FilesControllerHelperString.UploadFile(folderId, uploadModel); } [Create("{folderId}/upload", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public List> UploadFileFromForm(string folderId, [FromForm]UploadModel uploadModel) { return FilesControllerHelperString.UploadFile(folderId, uploadModel); } [Create("{folderId:int}/upload")] public List> UploadFileFromBody(int folderId, [FromBody]UploadModel uploadModel) { return FilesControllerHelperInt.UploadFile(folderId, uploadModel); } [Create("{folderId:int}/upload")] [Consumes("application/x-www-form-urlencoded")] public List> UploadFileFromForm(int folderId, [FromForm]UploadModel uploadModel) { return FilesControllerHelperInt.UploadFile(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 FileWrapper InsertFileToMyFromBody([FromBody]InsertFileModel model) { return InsertFile(GlobalFolderHelper.FolderMy, model); } [Create("@my/insert")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper InsertFileToMyFromForm([FromForm]InsertFileModel model) { return InsertFile(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 FileWrapper InsertFileToCommonFromBody([FromBody]InsertFileModel model) { return InsertFile(GlobalFolderHelper.FolderCommon, model); } [Create("@common/insert")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper InsertFileToCommonFromForm([FromForm]InsertFileModel model) { return InsertFile(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", DisableFormat = true)] public FileWrapper InsertFileFromBody(string folderId, [FromBody]InsertFileModel model) { return InsertFile(folderId, model); } [Create("{folderId}/insert", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper InsertFileFromForm(string folderId, [FromForm]InsertFileModel model) { return InsertFile(folderId, model); } private FileWrapper InsertFile(string folderId, InsertFileModel model) { return FilesControllerHelperString.InsertFile(folderId, model.File, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } [Create("{folderId:int}/insert")] public FileWrapper InsertFileFromBody(int folderId, [FromBody]InsertFileModel model) { return InsertFile(folderId, model); } [Create("{folderId:int}/insert")] public FileWrapper InsertFileFromForm(int folderId, [FromForm]InsertFileModel model) { return InsertFile(folderId, model); } private FileWrapper InsertFile(int folderId, InsertFileModel model) { return FilesControllerHelperInt.InsertFile(folderId, model.File, model.Title, model.CreateNewIfExist, model.KeepConvertStatus); } /// /// /// /// /// /// /// /// false [Update("{fileId}/update", DisableFormat = true)] public FileWrapper UpdateFileStreamFromBody(string fileId, [FromBody]FileStreamModel model) { return FilesControllerHelperString.UpdateFileStream(model.File, fileId, model.Encrypted, model.Forcesave); } [Update("{fileId}/update", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper UpdateFileStreamFromForm(string fileId, [FromForm]FileStreamModel model) { return FilesControllerHelperString.UpdateFileStream(model.File, fileId, model.Encrypted, model.Forcesave); } [Update("{fileId:int}/update")] public FileWrapper UpdateFileStreamFromBody(int fileId, [FromBody]FileStreamModel model) { return FilesControllerHelperInt.UpdateFileStream(model.File, fileId, model.Encrypted, model.Forcesave); } [Update("{fileId:int}/update")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper UpdateFileStreamFromForm(int fileId, [FromForm]FileStreamModel model) { return FilesControllerHelperInt.UpdateFileStream(model.File, fileId, model.Encrypted, model.Forcesave); } /// /// /// /// File ID /// /// /// /// /// /// Files /// [Update("file/{fileId}/saveediting", DisableFormat = true)] public FileWrapper SaveEditingFromBody(string fileId, [FromBody]SaveEditingModel model) { return FilesControllerHelperString.SaveEditing(fileId, model.FileExtension, model.DownloadUri, model.Stream, model.Doc, model.Forcesave); } [Update("file/{fileId}/saveediting", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper SaveEditingFromForm(string fileId, [FromForm]SaveEditingModel model) { return FilesControllerHelperString.SaveEditing(fileId, model.FileExtension, model.DownloadUri, model.Stream, model.Doc, model.Forcesave); } [Update("file/{fileId:int}/saveediting")] public FileWrapper SaveEditingFromBody(int fileId, [FromBody]SaveEditingModel model) { return FilesControllerHelperInt.SaveEditing(fileId, model.FileExtension, model.DownloadUri, model.Stream, model.Doc, model.Forcesave); } [Update("file/{fileId:int}/saveediting")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper SaveEditingFromForm(int fileId, [FromForm]SaveEditingModel model) { return FilesControllerHelperInt.SaveEditing(fileId, model.FileExtension, model.DownloadUri, model.Stream, model.Doc, model.Forcesave); } /// /// /// /// File ID /// /// /// Files /// [Create("file/{fileId}/startedit", DisableFormat = true)] public object StartEditFromBody(string fileId, [FromBody]StartEditModel model) { return FilesControllerHelperString.StartEdit(fileId, model.EditingAlone, model.Doc); } [Create("file/{fileId}/startedit", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public object StartEditFromForm(string fileId, [FromForm]StartEditModel model) { return FilesControllerHelperString.StartEdit(fileId, model.EditingAlone, model.Doc); } [Create("file/{fileId:int}/startedit")] public object StartEditFromBody(int fileId, [FromBody]StartEditModel model) { return FilesControllerHelperInt.StartEdit(fileId, model.EditingAlone, model.Doc); } [Create("file/{fileId:int}/startedit")] [Consumes("application/x-www-form-urlencoded")] public object StartEditFromForm(int fileId, [FromForm]StartEditModel model) { return FilesControllerHelperInt.StartEdit(fileId, model.EditingAlone, model.Doc); } /// /// /// /// File ID /// /// /// /// /// Files /// [Read("file/{fileId}/trackeditfile", DisableFormat = true)] public KeyValuePair TrackEditFile(string fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish) { return FilesControllerHelperString.TrackEditFile(fileId, tabId, docKeyForTrack, doc, isFinish); } [Read("file/{fileId:int}/trackeditfile")] public KeyValuePair TrackEditFile(int fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish) { return FilesControllerHelperInt.TrackEditFile(fileId, tabId, docKeyForTrack, doc, isFinish); } /// /// /// /// File ID /// /// /// Files /// [Read("file/{fileId}/openedit", DisableFormat = true)] public Configuration OpenEdit(string fileId, int version, string doc) { return FilesControllerHelperString.OpenEdit(fileId, version, doc); } [Read("file/{fileId:int}/openedit")] public Configuration OpenEdit(int fileId, int version, string doc) { return FilesControllerHelperInt.OpenEdit(fileId, version, doc); } /// /// 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 5 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", DisableFormat = true)] public object CreateUploadSessionFromBody(string folderId, [FromBody]SessionModel sessionModel) { return FilesControllerHelperString.CreateUploadSession(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.Encrypted); } [Create("{folderId}/upload/create_session", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public object CreateUploadSessionFromForm(string folderId, [FromForm]SessionModel sessionModel) { return FilesControllerHelperString.CreateUploadSession(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] public object CreateUploadSessionFromBody(int folderId, [FromBody]SessionModel sessionModel) { return FilesControllerHelperInt.CreateUploadSession(folderId, sessionModel.FileName, sessionModel.FileSize, sessionModel.RelativePath, sessionModel.Encrypted); } [Create("{folderId:int}/upload/create_session")] [Consumes("application/x-www-form-urlencoded")] public object CreateUploadSessionFromForm(int folderId, [FromForm]SessionModel sessionModel) { return FilesControllerHelperInt.CreateUploadSession(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 FileWrapper CreateTextFileInMyFromBody([FromBody]CreateTextOrHtmlFileModel model) { return CreateTextFile(GlobalFolderHelper.FolderMy, model); } [Create("@my/text")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateTextFileInMyFromForm([FromForm]CreateTextOrHtmlFileModel model) { return CreateTextFile(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 FileWrapper CreateTextFileInCommonFromBody([FromBody]CreateTextOrHtmlFileModel model) { return CreateTextFile(GlobalFolderHelper.FolderCommon, model); } [Create("@common/text")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateTextFileInCommonFromForm([FromForm]CreateTextOrHtmlFileModel model) { return CreateTextFile(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", DisableFormat = true)] public FileWrapper CreateTextFileFromBody(string folderId, [FromBody]CreateTextOrHtmlFileModel model) { return CreateTextFile(folderId, model); } [Create("{folderId}/text", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateTextFileFromForm(string folderId, [FromForm]CreateTextOrHtmlFileModel model) { return CreateTextFile(folderId, model); } private FileWrapper CreateTextFile(string folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperString.CreateTextFile(folderId, model.Title, model.Content); } [Create("{folderId:int}/text")] public FileWrapper CreateTextFileFromBody(int folderId, [FromBody]CreateTextOrHtmlFileModel model) { return CreateTextFile(folderId, model); } [Create("{folderId:int}/text")] public FileWrapper CreateTextFileFromForm(int folderId, [FromForm]CreateTextOrHtmlFileModel model) { return CreateTextFile(folderId, model); } private FileWrapper CreateTextFile(int folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperInt.CreateTextFile(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", DisableFormat = true)] public FileWrapper CreateHtmlFileFromBody(string folderId, [FromBody]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(folderId, model); } [Create("{folderId}/html", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateHtmlFileFromForm(string folderId, [FromForm]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(folderId, model); } private FileWrapper CreateHtmlFile(string folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperString.CreateHtmlFile(folderId, model.Title, model.Content); } [Create("{folderId:int}/html")] public FileWrapper CreateHtmlFileFromBody(int folderId, [FromBody]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(folderId, model); } [Create("{folderId:int}/html")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateHtmlFileFromForm(int folderId, [FromForm] CreateTextOrHtmlFileModel model) { return CreateHtmlFile(folderId, model); } private FileWrapper CreateHtmlFile(int folderId, CreateTextOrHtmlFileModel model) { return FilesControllerHelperInt.CreateHtmlFile(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 FileWrapper CreateHtmlFileInMyFromBody([FromBody]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(GlobalFolderHelper.FolderMy, model); } [Create("@my/html")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateHtmlFileInMyFromForm([FromForm]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(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 FileWrapper CreateHtmlFileInCommonFromBody([FromBody]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(GlobalFolderHelper.FolderCommon, model); } [Create("@common/html")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateHtmlFileInCommonFromForm([FromForm]CreateTextOrHtmlFileModel model) { return CreateHtmlFile(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}", DisableFormat = true)] public FolderWrapper CreateFolderFromBody(string folderId, [FromBody]CreateFolderModel folderModel) { return FilesControllerHelperString.CreateFolder(folderId, folderModel.Title); } [Create("folder/{folderId}", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FolderWrapper CreateFolderFromForm(string folderId, [FromForm]CreateFolderModel folderModel) { return FilesControllerHelperString.CreateFolder(folderId, folderModel.Title); } [Create("folder/{folderId:int}")] public FolderWrapper CreateFolderFromBody(int folderId, [FromBody]CreateFolderModel folderModel) { return FilesControllerHelperInt.CreateFolder(folderId, folderModel.Title); } [Create("folder/{folderId:int}")] [Consumes("application/x-www-form-urlencoded")] public FolderWrapper CreateFolderFromForm(int folderId, [FromForm]CreateFolderModel folderModel) { return FilesControllerHelperInt.CreateFolder(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 FileWrapper CreateFileFromBody([FromBody]CreateFileModel model) { return FilesControllerHelperInt.CreateFile(GlobalFolderHelper.FolderMy, model.Title, model.TemplateId); } [Create("@my/file")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateFileFromForm([FromForm]CreateFileModel model) { return FilesControllerHelperInt.CreateFile(GlobalFolderHelper.FolderMy, model.Title, model.TemplateId); } /// /// 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", DisableFormat = true)] public FileWrapper CreateFileFromBody(string folderId, [FromBody]CreateFileModel model) { return FilesControllerHelperString.CreateFile(folderId, model.Title, model.TemplateId); } [Create("{folderId}/file", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateFileFromForm(string folderId, [FromForm]CreateFileModel model) { return FilesControllerHelperString.CreateFile(folderId, model.Title, model.TemplateId); } [Create("{folderId:int}/file")] public FileWrapper CreateFileFromBody(int folderId, [FromBody]CreateFileModel model) { return FilesControllerHelperInt.CreateFile(folderId, model.Title, model.TemplateId); } [Create("{folderId:int}/file")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper CreateFileFromForm(int folderId, [FromForm]CreateFileModel model) { return FilesControllerHelperInt.CreateFile(folderId, model.Title, model.TemplateId); } /// /// Renames the selected folder to the new title specified in the request /// /// /// Rename folder /// /// Folders /// Folder ID /// New title /// Folder contents [Update("folder/{folderId}", DisableFormat = true)] public FolderWrapper RenameFolderFromBody(string folderId, [FromBody]CreateFolderModel folderModel) { return FilesControllerHelperString.RenameFolder(folderId, folderModel.Title); } [Update("folder/{folderId}", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FolderWrapper RenameFolderFromForm(string folderId, [FromForm]CreateFolderModel folderModel) { return FilesControllerHelperString.RenameFolder(folderId, folderModel.Title); } [Update("folder/{folderId:int}")] public FolderWrapper RenameFolderFromBody(int folderId, [FromBody]CreateFolderModel folderModel) { return FilesControllerHelperInt.RenameFolder(folderId, folderModel.Title); } [Update("folder/{folderId:int}")] [Consumes("application/x-www-form-urlencoded")] public FolderWrapper RenameFolderFromForm(int folderId, [FromForm]CreateFolderModel folderModel) { return FilesControllerHelperInt.RenameFolder(folderId, folderModel.Title); } /// /// Returns a detailed information about the folder with the ID specified in the request /// /// Folder information /// Folders /// Folder info [Read("folder/{folderId}", DisableFormat = true)] public FolderWrapper GetFolderInfo(string folderId) { return FilesControllerHelperString.GetFolderInfo(folderId); } [Read("folder/{folderId:int}")] public FolderWrapper GetFolderInfo(int folderId) { return FilesControllerHelperInt.GetFolderInfo(folderId); } /// /// Returns parent folders /// /// /// Folders /// Parent folders [Read("folder/{folderId}/path", DisableFormat = true)] public IEnumerable> GetFolderPath(string folderId) { return FilesControllerHelperString.GetFolderPath(folderId); } [Read("folder/{folderId:int}/path")] public IEnumerable> GetFolderPath(int folderId) { return FilesControllerHelperInt.GetFolderPath(folderId); } /// /// Returns a detailed information about the file with the ID specified in the request /// /// File information /// Files /// File info [Read("file/{fileId}", DisableFormat = true)] public FileWrapper GetFileInfo(string fileId, int version = -1) { return FilesControllerHelperString.GetFileInfo(fileId, version); } [Read("file/{fileId:int}", DisableFormat = true)] public FileWrapper GetFileInfo(int fileId, int version = -1) { return FilesControllerHelperInt.GetFileInfo(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("file/{fileId}", DisableFormat = true)] public FileWrapper UpdateFileFromBody(string fileId, [FromBody]UpdateFileModel model) { return FilesControllerHelperString.UpdateFile(fileId, model.Title, model.LastVersion); } [Update("file/{fileId}", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper UpdateFileFromForm(string fileId, [FromForm]UpdateFileModel model) { return FilesControllerHelperString.UpdateFile(fileId, model.Title, model.LastVersion); } [Update("file/{fileId:int}")] public FileWrapper UpdateFileFromBody(int fileId, [FromBody]UpdateFileModel model) { return FilesControllerHelperInt.UpdateFile(fileId, model.Title, model.LastVersion); } [Update("file/{fileId:int}")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper UpdateFileFromForm(int fileId, [FromForm]UpdateFileModel model) { return FilesControllerHelperInt.UpdateFile(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}", DisableFormat = true)] public IEnumerable DeleteFile(string fileId, bool deleteAfter, bool immediately) { return FilesControllerHelperString.DeleteFile(fileId, deleteAfter, immediately); } [Delete("file/{fileId:int}")] public IEnumerable DeleteFile(int fileId, bool deleteAfter, bool immediately) { return FilesControllerHelperInt.DeleteFile(fileId, deleteAfter, immediately); } /// /// Start conversion /// /// Convert /// File operations /// /// Operation result [Update("file/{fileId}/checkconversion", DisableFormat = true)] public IEnumerable> StartConversion(string fileId) { return FilesControllerHelperString.StartConversion(fileId); } [Update("file/{fileId:int}/checkconversion")] public IEnumerable> StartConversion(int fileId) { return FilesControllerHelperInt.StartConversion(fileId); } /// /// Check conversion status /// /// Convert /// File operations /// /// /// Operation result [Read("file/{fileId}/checkconversion", DisableFormat = true)] public IEnumerable> CheckConversion(string fileId, bool start) { return FilesControllerHelperString.CheckConversion(fileId, start); } [Read("file/{fileId:int}/checkconversion")] public IEnumerable> CheckConversion(int fileId, bool start) { return FilesControllerHelperInt.CheckConversion(fileId, 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}", 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 IEnumerable MoveOrCopyBatchCheckFromBody([FromBody]BatchModel batchModel) { return FilesControllerHelperString.MoveOrCopyBatchCheck(batchModel); } [Read("fileops/move")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable MoveOrCopyBatchCheckFromForm([FromForm]BatchModel batchModel) { return FilesControllerHelperString.MoveOrCopyBatchCheck(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 IEnumerable MoveBatchItemsFromBody([FromBody]BatchModel batchModel) { return FilesControllerHelperString.MoveBatchItems(batchModel); } [Update("fileops/move")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable MoveBatchItemsFromForm([FromForm]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]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]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]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", DisableFormat = true)] public IEnumerable> GetFileVersionInfo(string fileId) { return FilesControllerHelperString.GetFileVersionInfo(fileId); } [Read("file/{fileId:int}/history")] public IEnumerable> GetFileVersionInfo(int fileId) { return FilesControllerHelperInt.GetFileVersionInfo(fileId); } /// /// Change version history /// /// File ID /// Version of history /// Mark as version or revision /// Files /// [Update("file/{fileId}/history", DisableFormat = true)] public IEnumerable> ChangeHistoryFromBody(string fileId, [FromBody]ChangeHistoryModel model) { return FilesControllerHelperString.ChangeHistory(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId}/history", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public IEnumerable> ChangeHistoryFromForm(string fileId, [FromForm]ChangeHistoryModel model) { return FilesControllerHelperString.ChangeHistory(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId:int}/history")] public IEnumerable> ChangeHistoryFromBody(int fileId, [FromBody]ChangeHistoryModel model) { return FilesControllerHelperInt.ChangeHistory(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId:int}/history")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable> ChangeHistoryFromForm(int fileId, [FromForm]ChangeHistoryModel model) { return FilesControllerHelperInt.ChangeHistory(fileId, model.Version, model.ContinueVersion); } [Update("file/{fileId}/lock", DisableFormat = true)] public FileWrapper LockFileFromBody(string fileId, [FromBody]LockFileModel model) { return FilesControllerHelperString.LockFile(fileId, model.LockFile); } [Update("file/{fileId}/lock", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public FileWrapper LockFileFromForm(string fileId, [FromForm]LockFileModel model) { return FilesControllerHelperString.LockFile(fileId, model.LockFile); } [Update("file/{fileId:int}/lock")] public FileWrapper LockFileFromBody(int fileId, [FromBody]LockFileModel model) { return FilesControllerHelperInt.LockFile(fileId, model.LockFile); } [Update("file/{fileId:int}/lock")] [Consumes("application/x-www-form-urlencoded")] public FileWrapper LockFileFromForm(int fileId, [FromForm]LockFileModel model) { return FilesControllerHelperInt.LockFile(fileId, model.LockFile); } [Update("file/{fileId}/comment", DisableFormat = true)] public object UpdateCommentFromBody(string fileId, [FromBody]UpdateCommentModel model) { return FilesControllerHelperString.UpdateComment(fileId, model.Version, model.Comment); } [Update("file/{fileId}/comment", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public object UpdateCommentFromForm(string fileId, [FromForm]UpdateCommentModel model) { return FilesControllerHelperString.UpdateComment(fileId, model.Version, model.Comment); } [Update("file/{fileId:int}/comment")] public object UpdateCommentFromBody(int fileId, [FromBody]UpdateCommentModel model) { return FilesControllerHelperInt.UpdateComment(fileId, model.Version, model.Comment); } [Update("file/{fileId:int}/comment")] [Consumes("application/x-www-form-urlencoded")] public object UpdateCommentFromForm(int fileId, [FromForm]UpdateCommentModel model) { return FilesControllerHelperInt.UpdateComment(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", DisableFormat = true)] public IEnumerable GetFileSecurityInfo(string fileId) { return FilesControllerHelperString.GetFileSecurityInfo(fileId); } [Read("file/{fileId:int}/share")] public IEnumerable GetFileSecurityInfo(int fileId) { return FilesControllerHelperInt.GetFileSecurityInfo(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", DisableFormat = true)] public IEnumerable GetFolderSecurityInfo(string folderId) { return FilesControllerHelperString.GetFolderSecurityInfo(folderId); } [Read("folder/{folderId:int}/share")] public IEnumerable GetFolderSecurityInfo(int folderId) { return FilesControllerHelperInt.GetFolderSecurityInfo(folderId); } /// /// 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", DisableFormat = true)] public IEnumerable SetFileSecurityInfoFromBody(string fileId, [FromBody]SecurityInfoModel model) { return FilesControllerHelperString.SetFileSecurityInfo(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId}/share", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public IEnumerable SetFileSecurityInfoFromForm(string fileId, [FromForm]SecurityInfoModel model) { return FilesControllerHelperString.SetFileSecurityInfo(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId:int}/share")] public IEnumerable SetFileSecurityInfoFromBody(int fileId, [FromBody]SecurityInfoModel model) { return FilesControllerHelperInt.SetFileSecurityInfo(fileId, model.Share, model.Notify, model.SharingMessage); } [Update("file/{fileId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable SetFileSecurityInfoFromForm(int fileId, [FromForm]SecurityInfoModel model) { return FilesControllerHelperInt.SetFileSecurityInfo(fileId, model.Share, model.Notify, model.SharingMessage); } /// /// 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", DisableFormat = true)] public IEnumerable SetFolderSecurityInfoFromBody(string folderId, [FromBody]SecurityInfoModel model) { return FilesControllerHelperString.SetFolderSecurityInfo(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId}/share", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public IEnumerable SetFolderSecurityInfoFromForm(string folderId, [FromForm]SecurityInfoModel model) { return FilesControllerHelperString.SetFolderSecurityInfo(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId:int}/share")] public IEnumerable SetFolderSecurityInfoFromBody(int folderId, [FromBody]SecurityInfoModel model) { return FilesControllerHelperInt.SetFolderSecurityInfo(folderId, model.Share, model.Notify, model.SharingMessage); } [Update("folder/{folderId:int}/share")] [Consumes("application/x-www-form-urlencoded")] public IEnumerable SetFolderSecurityInfoFromForm(int folderId, [FromForm]SecurityInfoModel model) { return FilesControllerHelperInt.SetFolderSecurityInfo(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 bool RemoveSecurityInfo(BaseBatchModel model) { FileStorageService.RemoveAce(model.FileIds.OfType().ToList(), model.FolderIds.OfType().ToList()); FileStorageServiceInt.RemoveAce(model.FileIds.OfType().Select(r => Convert.ToInt32(r)).ToList(), model.FolderIds.OfType().Select(r => Convert.ToInt32(r)).ToList()); 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}/sharedlink", DisableFormat = true)] public object GenerateSharedLinkFromBody(string fileId, [FromBody]GenerateSharedLinkModel model) { return FilesControllerHelperString.GenerateSharedLink(fileId, model.Share); } [Update("{fileId}/sharedlink", DisableFormat = true)] [Consumes("application/x-www-form-urlencoded")] public object GenerateSharedLinkFromForm(string fileId, [FromForm]GenerateSharedLinkModel model) { return FilesControllerHelperString.GenerateSharedLink(fileId, model.Share); } [Update("{fileId:int}/sharedlink")] public object GenerateSharedLinkFromBody(int fileId, [FromBody]GenerateSharedLinkModel model) { return FilesControllerHelperInt.GenerateSharedLink(fileId, model.Share); } [Update("{fileId:int}/sharedlink")] [Consumes("application/x-www-form-urlencoded")] public object GenerateSharedLinkFromForm(int fileId, [FromForm] GenerateSharedLinkModel model) { return FilesControllerHelperInt.GenerateSharedLink(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; } if (ThirdpartyConfiguration.SupportBoxInclusion) { var boxLoginProvider = ConsumerFactory.Get(); result.Add(new List { "Box", boxLoginProvider.ClientID, boxLoginProvider.RedirectUri }); } if (ThirdpartyConfiguration.SupportDropboxInclusion) { var dropboxLoginProvider = ConsumerFactory.Get(); result.Add(new List { "DropboxV2", dropboxLoginProvider.ClientID, dropboxLoginProvider.RedirectUri }); } if (ThirdpartyConfiguration.SupportGoogleDriveInclusion) { var googleLoginProvider = ConsumerFactory.Get(); result.Add(new List { "GoogleDrive", googleLoginProvider.ClientID, googleLoginProvider.RedirectUri }); } if (ThirdpartyConfiguration.SupportOneDriveInclusion) { var oneDriveLoginProvider = ConsumerFactory.Get(); result.Add(new List { "OneDrive", oneDriveLoginProvider.ClientID, oneDriveLoginProvider.RedirectUri }); } if (ThirdpartyConfiguration.SupportSharePointInclusion) { result.Add(new List { "SharePoint" }); } if (ThirdpartyConfiguration.SupportkDriveInclusion) { result.Add(new List { "kDrive" }); } if (ThirdpartyConfiguration.SupportYandexInclusion) { result.Add(new List { "Yandex" }); } if (ThirdpartyConfiguration.SupportWebDavInclusion) { result.Add(new List { "WebDav" }); } //Obsolete BoxNet, DropBox, Google, SkyDrive, return result; } /// /// 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 FolderWrapper SaveThirdPartyFromBody([FromBody]ThirdPartyModel model) { return SaveThirdParty(model); } [Create("thirdparty")] [Consumes("application/x-www-form-urlencoded")] public FolderWrapper SaveThirdPartyFromForm([FromForm]ThirdPartyModel model) { return SaveThirdParty(model); } private FolderWrapper SaveThirdParty(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 = FileStorageService.SaveThirdParty(thirdPartyParams); return FolderWrapperHelper.Get(folder); } /// /// Returns the list of all connected third party services /// /// Third-Party Integration /// Get third party list /// Connected providers [Read("thirdparty")] public IEnumerable GetThirdPartyAccounts() { return FileStorageService.GetThirdParty(); } /// /// 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 IEnumerable> GetCommonThirdPartyFolders() { var parent = FileStorageServiceInt.GetFolder(GlobalFolderHelper.FolderCommon); return EntryManager.GetThirpartyFolders(parent).Select(FolderWrapperHelper.Get).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 object DeleteThirdParty(int providerId) { return FileStorageService.DeleteThirdParty(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 bool AddFavoritesFromBody([FromBody]BaseBatchModel model) { return AddFavorites(model); } [Create("favorites")] [Consumes("application/x-www-form-urlencoded")] public bool AddFavoritesFromForm([FromForm]BaseBatchModel model) { return AddFavorites(model); } private bool AddFavorites(BaseBatchModel model) { FileStorageServiceInt.AddToFavorites(model.FolderIds.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32()), model.FileIds.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32())); FileStorageService.AddToFavorites(model.FolderIds.Where(r => r.ValueKind == JsonValueKind.String).Select(r => r.GetString()), model.FileIds.Where(r => r.ValueKind == JsonValueKind.String).Select(r => r.GetString())); return true; } /// /// Removing files from favorite list /// /// Favorite delete /// Files /// /// File IDs /// [Delete("favorites")] public bool DeleteFavorites(BaseBatchModel model) { FileStorageServiceInt.DeleteFavorites(model.FolderIds.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32()), model.FileIds.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32())); FileStorageService.DeleteFavorites(model.FolderIds.Where(r => r.ValueKind == JsonValueKind.String).Select(r => r.GetString()), model.FileIds.Where(r => r.ValueKind == JsonValueKind.String).Select(r => r.GetString())); return true; } /// /// Adding files to template list /// /// Template add /// Files /// File IDs /// [Create("templates")] public bool AddTemplatesFromBody([FromBody]TemplatesModel model) { FileStorageServiceInt.AddToTemplates(model.FileIds); return true; } [Create("templates")] [Consumes("application/x-www-form-urlencoded")] public bool AddTemplatesFromForm([FromForm]TemplatesModel model) { FileStorageServiceInt.AddToTemplates(model.FileIds); return true; } /// /// Removing files from template list /// /// Template delete /// Files /// File IDs /// [Delete("templates")] public bool DeleteTemplates(IEnumerable fileIds) { FileStorageServiceInt.DeleteTemplates(fileIds); return true; } /// /// /// /// /// [Update(@"storeoriginal")] public bool StoreOriginal(SettingsModel model) { return FileStorageService.StoreOriginal(model.Set); } /// /// /// /// [Read(@"settings")] public object GetFilesSettings() { return new { FilesSettingsHelper.StoreOriginalFiles, FilesSettingsHelper.ConfirmDelete, FilesSettingsHelper.UpdateIfExist, FilesSettingsHelper.Forcesave, FilesSettingsHelper.StoreForcesave, FilesSettingsHelper.EnableThirdParty }; } /// /// /// /// /// false /// [Update(@"hideconfirmconvert")] public bool HideConfirmConvert(bool save) { return FileStorageService.HideConfirmConvert(save); } /// /// /// /// /// [Update(@"updateifexist")] public bool UpdateIfExist(SettingsModel model) { return FileStorageService.UpdateIfExist(model.Set); } /// /// /// /// /// [Update(@"changedeleteconfrim")] public bool ChangeDeleteConfrim(SettingsModel model) { return FileStorageService.ChangeDeleteConfrim(model.Set); } /// /// /// /// /// [Update(@"storeforcesave")] public bool StoreForcesave(SettingsModel model) { return FileStorageService.StoreForcesave(model.Set); } /// /// /// /// /// [Update(@"forcesave")] public bool Forcesave(SettingsModel model) { return FileStorageService.Forcesave(model.Set); } /// /// /// /// /// [Update(@"thirdparty")] public bool ChangeAccessToThirdparty(SettingsModel model) { return FileStorageService.ChangeAccessToThirdparty(model.Set); } /// /// Display recent folder /// /// /// Settings /// [Update(@"displayRecent")] public bool DisplayRecent(bool set) { return FileStorageService.DisplayRecent(set); } /// /// Display favorite folder /// /// /// Settings /// [Update(@"settings/favorites")] public bool DisplayFavorite(bool set) { return FileStorageService.DisplayFavorite(set); } /// /// Display template folder /// /// /// Settings /// [Update(@"settings/templates")] public bool DisplayTemplates(bool set) { return FileStorageService.DisplayTemplates(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); } 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 [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 = OAuth20TokenHelper.GetAccessToken(ConsumerFactory, model.Code); WordpressToken.SaveToken(token); 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; } } } public static class DocumentsControllerExtention { public static DIHelper AddDocumentsControllerService(this DIHelper services) { return services.AddFilesControllerHelperService(); } } public class BodySpecificAttribute : Attribute, IActionConstraint { public BodySpecificAttribute() { } public int Order { get { return 0; } } public bool Accept(ActionConstraintContext context) { var options = new JsonSerializerOptions { AllowTrailingCommas = true, PropertyNameCaseInsensitive = true }; try { context.RouteContext.HttpContext.Request.EnableBuffering(); _ = JsonSerializer.DeserializeAsync>(context.RouteContext.HttpContext.Request.Body, options).Result; return true; } catch { return false; } finally { context.RouteContext.HttpContext.Request.Body.Seek(0, SeekOrigin.Begin); } } } }