diff --git a/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSession.cs b/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSession.cs index bbcab626645..fd00bd4e162 100644 --- a/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSession.cs +++ b/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSession.cs @@ -27,7 +27,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.Serialization.Formatters.Binary; +using System.Linq; +using System.Text.Json; +using System.Text.Json.Serialization; namespace ASC.Core.ChunkedUploader { @@ -54,9 +56,11 @@ public class CommonChunkedUploadSession : ICloneable public string CultureName { get; set; } - public Dictionary Items = new Dictionary(); + public Dictionary Items { get; set; } = new Dictionary(); private const string TempPathKey = "TempPath"; + + [JsonIgnore] public string TempPath { get { return GetItemOrDefault(TempPathKey); } @@ -64,6 +68,8 @@ public string TempPath } private const string UploadIdKey = "UploadId"; + + [JsonIgnore] public string UploadId { get { return GetItemOrDefault(UploadIdKey); } @@ -71,6 +77,8 @@ public string UploadId } private const string ChunksBufferKey = "ChunksBuffer"; + + [JsonIgnore] public string ChunksBuffer { get { return GetItemOrDefault(ChunksBufferKey); } @@ -91,16 +99,41 @@ public T GetItemOrDefault(string key) return Items.ContainsKey(key) && Items[key] is T t ? t : default; } - public Stream Serialize() + public virtual Stream Serialize() { - var stream = new MemoryStream(); - new BinaryFormatter().Serialize(stream, this); - return stream; + return null; } - public static CommonChunkedUploadSession Deserialize(Stream stream) + public void TransformItems() { - return (CommonChunkedUploadSession)new BinaryFormatter().Deserialize(stream); + var newItems = new Dictionary(); + foreach(var item in Items) + { + if (item.Value != null) + { + if (item.Value.GetType() == typeof(JsonElement)) + { + var value = (JsonElement)item.Value; + if (value.ValueKind == JsonValueKind.String) + { + newItems.Add(item.Key, item.Value.ToString()); + } + if (value.ValueKind == JsonValueKind.Number) + { + newItems.Add(item.Key, Int32.Parse(item.Value.ToString())); + } + if (value.ValueKind == JsonValueKind.Array) + { + newItems.Add(item.Key, value.EnumerateArray().Select(o => o.ToString()).ToList()); + } + } + else + { + newItems.Add(item.Key, item.Value); + } + } + } + Items = newItems; } public virtual object Clone() diff --git a/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSessionHolder.cs b/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSessionHolder.cs index 0b51e46baaf..54fb0544aa6 100644 --- a/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSessionHolder.cs +++ b/common/ASC.Data.Storage/ChunkedUploader/CommonChunkedUploadSessionHolder.cs @@ -86,12 +86,11 @@ public void Remove(CommonChunkedUploadSession s) { DataStore.Delete(Domain, GetPathWithId(s.Id)); } - - public CommonChunkedUploadSession Get(string sessionId) - { - using var stream = DataStore.GetReadStream(Domain, GetPathWithId(sessionId)); - return CommonChunkedUploadSession.Deserialize(stream); - } + + public Stream GetStream(string sessionId) + { + return DataStore.GetReadStream(Domain, GetPathWithId(sessionId)); + } public void Init(CommonChunkedUploadSession chunkedUploadSession) { diff --git a/products/ASC.Files/Core/Core/Entries/ChunkedUploadSession.cs b/products/ASC.Files/Core/Core/Entries/ChunkedUploadSession.cs index 56306f31326..12d60adc64f 100644 --- a/products/ASC.Files/Core/Core/Entries/ChunkedUploadSession.cs +++ b/products/ASC.Files/Core/Core/Entries/ChunkedUploadSession.cs @@ -27,8 +27,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; - +using System.Text; +using System.Text.Json; + using ASC.Common; using ASC.Common.Logging; using ASC.Core.ChunkedUploader; @@ -62,6 +65,22 @@ public override object Clone() var clone = (ChunkedUploadSession)MemberwiseClone(); clone.File = (File)File.Clone(); return clone; + } + + public override Stream Serialize() + { + var str = JsonSerializer.Serialize(this); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(str)); + return stream; + } + + public static ChunkedUploadSession Deserialize(Stream stream, FileHelper fileHelper) + { + var chunkedUploadSession = JsonSerializer.DeserializeAsync>(stream).Result; + chunkedUploadSession.File.FileHelper = fileHelper; + chunkedUploadSession.TransformItems(); + return chunkedUploadSession; + } } diff --git a/products/ASC.Files/Core/Core/Entries/File.cs b/products/ASC.Files/Core/Core/Entries/File.cs index 5a22a537ccd..43320b19cc6 100644 --- a/products/ASC.Files/Core/Core/Entries/File.cs +++ b/products/ASC.Files/Core/Core/Entries/File.cs @@ -30,8 +30,6 @@ using ASC.Common; using ASC.Web.Core.Files; -using ASC.Web.Files.Classes; -using ASC.Web.Files.Utils; using ASC.Web.Studio.Core; namespace ASC.Files.Core @@ -60,28 +58,23 @@ public enum FileStatus [Serializable] [DebuggerDisplay("{Title} ({ID} v{Version})")] public class File : FileEntry - { - private FileStatus _status; - - public File(Global global, - FilesLinkUtility filesLinkUtility, - FileUtility fileUtility, - FileConverter fileConverter, - FileTrackerHelper fileTracker) - : base(global) - { - Version = 1; - VersionGroup = 1; - FileEntryType = FileEntryType.File; - FilesLinkUtility = filesLinkUtility; - FileUtility = fileUtility; - FileConverter = fileConverter; - FileTracker = fileTracker; + { + private FileStatus _status; + + public File() + { + Version = 1; + VersionGroup = 1; + FileEntryType = FileEntryType.File; + } + + public File(FileHelper fileHelper): this() + { + FileHelper = fileHelper; } public int Version { get; set; } - [JsonPropertyName("version_group")] public int VersionGroup { get; set; } public string Comment { get; set; } @@ -92,27 +85,15 @@ public string PureTitle set { base.Title = value; } } - public override string Title - { - get - { - return string.IsNullOrEmpty(ConvertedType) - ? base.Title - : FileUtility.ReplaceFileExtension(base.Title, FileUtility.GetInternalExtension(base.Title)); - } - set { base.Title = value; } - } - - [JsonPropertyName("content_length")] public long ContentLength { get; set; } - - [JsonPropertyName("content_length_string")] + + [JsonIgnore] public string ContentLengthString { get { return FileSizeComment.FilesSizeToString(ContentLength); } - set { } } - + + [JsonIgnore] public FilterType FilterType { get @@ -136,38 +117,26 @@ public FilterType FilterType return FilterType.None; } - } - - [JsonPropertyName("file_status")] + } + public FileStatus FileStatus { - get - { - if (FileTracker.IsEditing(ID)) - { - _status |= FileStatus.IsEditing; - } - - if (FileTracker.IsEditingAlone(ID)) - { - _status |= FileStatus.IsEditingAlone; - } - - if (FileConverter.IsConverting(this)) - { - _status |= FileStatus.IsConverting; - } - - return _status; - } - set { _status = value; } + get => FileHelper.GetFileStatus(this, ref _status); + set => _status = value; } + + [JsonIgnore] + public override string Title { get => FileHelper.GetTitle(this); } + + + [JsonIgnore] + public string DownloadUrl { get => FileHelper.GetDownloadUrl(this); } public bool Locked { get; set; } - [JsonPropertyName("locked_by")] public string LockedBy { get; set; } - + + [JsonIgnore] public override bool IsNew { get { return (_status & FileStatus.IsNew) == FileStatus.IsNew; } @@ -180,6 +149,7 @@ public override bool IsNew } } + [JsonIgnore] public bool IsFavorite { get { return (_status & FileStatus.IsFavorite) == FileStatus.IsFavorite; } @@ -192,6 +162,7 @@ public bool IsFavorite } } + [JsonIgnore] public bool IsTemplate { get { return (_status & FileStatus.IsTemplate) == FileStatus.IsTemplate; } @@ -206,18 +177,13 @@ public bool IsTemplate public bool Encrypted { get; set; } - [JsonPropertyName("thumbnail_status")] public Thumbnail ThumbnailStatus { get; set; } public ForcesaveType Forcesave { get; set; } - public string DownloadUrl - { - get { return FilesLinkUtility.GetFileDownloadUrl(ID); } - } - public string ConvertedType { get; set; } - + + [JsonIgnore] public string ConvertedExtension { get @@ -236,17 +202,6 @@ public string ConvertedExtension } public object NativeAccessor { get; set; } - - [NonSerialized] - private FileTrackerHelper FileTracker; - - [NonSerialized] - private readonly FilesLinkUtility FilesLinkUtility; - - [NonSerialized] - private readonly FileUtility FileUtility; - [NonSerialized] - private readonly FileConverter FileConverter; } } \ No newline at end of file diff --git a/products/ASC.Files/Core/Core/Entries/FileEntry.cs b/products/ASC.Files/Core/Core/Entries/FileEntry.cs index 920af3968bf..0606c40fc1b 100644 --- a/products/ASC.Files/Core/Core/Entries/FileEntry.cs +++ b/products/ASC.Files/Core/Core/Entries/FileEntry.cs @@ -28,52 +28,47 @@ using System.Text.Json.Serialization; using ASC.Files.Core.Security; -using ASC.Web.Files.Classes; namespace ASC.Files.Core { [Serializable] public abstract class FileEntry : ICloneable - { - public FileEntry(Global global) - { - Global = global; - } + { + [JsonIgnore] + public FileHelper FileHelper { get; set; } + + protected FileEntry() + { + + } + + public FileEntry(FileHelper fileHelper) + { + FileHelper = fileHelper; + } public virtual string Title { get; set; } - [JsonPropertyName("create_by_id")] - public Guid CreateBy { get; set; } - - [JsonPropertyName("create_by")] - public string CreateByString - { - get { return !CreateBy.Equals(Guid.Empty) ? Global.GetUserName(CreateBy) : _createByString; } - set { _createByString = value; } - } - - [JsonPropertyName("create_on")] + public Guid CreateBy { get; set; } + + [JsonIgnore] + public string CreateByString { get => FileHelper.GetCreateByString(this); } + + public Guid ModifiedBy { get; set; } + + [JsonIgnore] + public string ModifiedByString { get => FileHelper.GetModifiedByString(this); } + + [JsonIgnore] public string CreateOnString { get { return CreateOn.Equals(default) ? null : CreateOn.ToString("g"); } - set { throw new NotImplementedException(); } } - - [JsonPropertyName("modified_on")] + + [JsonIgnore] public string ModifiedOnString { get { return ModifiedOn.Equals(default) ? null : ModifiedOn.ToString("g"); } - set { throw new NotImplementedException(); } - } - - [JsonPropertyName("modified_by_id")] - public Guid ModifiedBy { get; set; } - - [JsonPropertyName("modified_by")] - public string ModifiedByString - { - get { return !ModifiedBy.Equals(Guid.Empty) ? Global.GetUserName(ModifiedBy) : _modifiedByString; } - set { _modifiedByString = value; } } public string Error { get; set; } @@ -82,11 +77,11 @@ public string ModifiedByString public bool Shared { get; set; } - [JsonPropertyName("provider_id")] public int ProviderId { get; set; } - [JsonPropertyName("provider_key")] - public string ProviderKey { get; set; } + public string ProviderKey { get; set; } + + [JsonIgnore] public bool ProviderEntry { get { return !string.IsNullOrEmpty(ProviderKey); } @@ -104,12 +99,8 @@ public bool ProviderEntry public FileEntryType FileEntryType; - [NonSerialized] - protected Global Global; - - private string _modifiedByString; - private string _createByString; - + public string _modifiedByString; + public string _createByString; public override string ToString() { @@ -125,17 +116,21 @@ public object Clone() [Serializable] public abstract class FileEntry : FileEntry, ICloneable { - public FileEntry(Global global) : base(global) - { - } - public T ID { get; set; } public T FolderID { get; set; } - private T _folderIdDisplay; - - [JsonPropertyName("folder_id")] + private T _folderIdDisplay; + + protected FileEntry() + { + + } + + protected FileEntry(FileHelper fileHelper) : base(fileHelper) + { + } + public T FolderIdDisplay { get @@ -147,7 +142,9 @@ public T FolderIdDisplay set { _folderIdDisplay = value; } } - public T RootFolderId { get; set; } + public T RootFolderId { get; set; } + + [JsonIgnore] public string UniqID { get { return string.Format("{0}_{1}", GetType().Name.ToLower(), ID); } diff --git a/products/ASC.Files/Core/Core/Entries/FileHelper.cs b/products/ASC.Files/Core/Core/Entries/FileHelper.cs new file mode 100644 index 00000000000..07700232a1e --- /dev/null +++ b/products/ASC.Files/Core/Core/Entries/FileHelper.cs @@ -0,0 +1,99 @@ +/* + * + * (c) Copyright Ascensio System Limited 2010-2021 + * + * 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 ASC.Common; +using ASC.Web.Core.Files; +using ASC.Web.Files.Classes; +using ASC.Web.Files.Utils; + +namespace ASC.Files.Core +{ + [Scope] + public class FileHelper + { + private FileTrackerHelper FileTracker { get; set; } + + private FilesLinkUtility FilesLinkUtility { get; set; } + + private FileUtility FileUtility { get; set; } + + private FileConverter FileConverter { get; set; } + + private Global Global { get; set; } + + public FileHelper(FileTrackerHelper fileTracker, FilesLinkUtility filesLinkUtility, FileUtility fileUtility, FileConverter fileConverter, Global global) + { + FileTracker = fileTracker; + FilesLinkUtility = filesLinkUtility; + FileUtility = fileUtility; + FileConverter = fileConverter; + Global = global; + } + + internal string GetCreateByString(FileEntry fileEntry) + { + return !fileEntry.CreateBy.Equals(Guid.Empty) ? Global.GetUserName(fileEntry.CreateBy) : fileEntry._createByString; + } + + internal string GetModifiedByString(FileEntry fileEntry) + { + return !fileEntry.ModifiedBy.Equals(Guid.Empty) ? Global.GetUserName(fileEntry.ModifiedBy) : fileEntry._modifiedByString; + } + + internal string GetTitle(File file) + { + return string.IsNullOrEmpty(file.ConvertedType) + ? file.PureTitle + : FileUtility.ReplaceFileExtension(file.PureTitle, FileUtility.GetInternalExtension(file.PureTitle)); + } + + internal FileStatus GetFileStatus(File file, ref FileStatus currentStatus) + { + if (FileTracker.IsEditing(file.ID)) + { + currentStatus |= FileStatus.IsEditing; + } + + if (FileTracker.IsEditingAlone(file.ID)) + { + currentStatus |= FileStatus.IsEditingAlone; + } + + if (FileConverter.IsConverting(file)) + { + currentStatus |= FileStatus.IsConverting; + } + + return currentStatus; + } + + public string GetDownloadUrl(FileEntry fileEntry) + { + return FilesLinkUtility.GetFileDownloadUrl(fileEntry.ID); + } + } +} diff --git a/products/ASC.Files/Core/Core/Entries/Folder.cs b/products/ASC.Files/Core/Core/Entries/Folder.cs index 5927a8a0d97..32c933c2a24 100644 --- a/products/ASC.Files/Core/Core/Entries/Folder.cs +++ b/products/ASC.Files/Core/Core/Entries/Folder.cs @@ -27,9 +27,8 @@ using System; using System.Diagnostics; -using ASC.Common; -using ASC.Web.Files.Classes; - +using ASC.Common; + namespace ASC.Files.Core { public enum FolderType @@ -61,9 +60,9 @@ public interface IFolder public string FolderUrl { get; set; } } - + + [DebuggerDisplay("{Title} ({ID})")] [Transient] - [DebuggerDisplay("{Title} ({ID})")] public class Folder : FileEntry, IFolder { public FolderType FolderType { get; set; } @@ -84,11 +83,15 @@ public override bool IsNew set { NewForMe = Convert.ToInt32(value); } } - public Folder(Global global) - : base(global) + public Folder() { Title = string.Empty; FileEntryType = FileEntryType.Folder; + } + + public Folder(FileHelper fileHelper) : this() + { + FileHelper = fileHelper; } } } \ No newline at end of file diff --git a/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs index d654156afc2..28aeefd2664 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs @@ -18,9 +18,9 @@ using ASC.Web.Core.Files; using ASC.Web.Files.Services.DocumentService; using ASC.Web.Studio.Core; - + using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using FileShare = ASC.Files.Core.Security.FileShare; @@ -320,7 +320,6 @@ protected File GetFile() InitFileEntry(file); file.Access = FileShare.None; - file.FileStatus = FileStatus.None; file.Shared = false; file.Version = 1; diff --git a/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderSecutiryDao.cs b/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderSecutiryDao.cs index e0ab9148713..4ba1a889dd2 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderSecutiryDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderSecutiryDao.cs @@ -34,8 +34,8 @@ using ASC.Files.Core.Data; using ASC.Files.Core.Security; using ASC.Files.Core.Thirdparty; - -using Microsoft.Extensions.DependencyInjection; + +using Microsoft.Extensions.DependencyInjection; namespace ASC.Files.Thirdparty.ProviderDao { diff --git a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointProviderInfo.cs b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointProviderInfo.cs index 0b3d6cadbce..9c57234b6c8 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointProviderInfo.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointProviderInfo.cs @@ -37,9 +37,9 @@ using ASC.Common.Logging; using ASC.Core.Tenants; using ASC.Files.Core; -using ASC.Web.Files.Classes; - -using Microsoft.Extensions.DependencyInjection; +using ASC.Web.Files.Classes; + +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.SharePoint.Client; @@ -279,8 +279,8 @@ public File CopyFile(string id, string toFolderId) public File ToFile(File file) { if (file == null) - return null; - + return null; + var result = ServiceProvider.GetService>(); if (file is SharePointFileErrorEntry errorFile) @@ -307,7 +307,6 @@ public File ToFile(File file) //ContentLength = file.Length, result.CreateBy = Owner; result.CreateOn = file.TimeCreated.Kind == DateTimeKind.Utc ? TenantUtil.DateTimeFromUtc(file.TimeCreated) : file.TimeCreated; - result.FileStatus = FileStatus.None; result.FolderID = MakeId(GetParentFolderId(file.ServerRelativeUrl)); result.ModifiedBy = Owner; result.ModifiedOn = file.TimeLastModified.Kind == DateTimeKind.Utc ? TenantUtil.DateTimeFromUtc(file.TimeLastModified) : file.TimeLastModified; diff --git a/products/ASC.Files/Core/Helpers/DocuSignHelper.cs b/products/ASC.Files/Core/Helpers/DocuSignHelper.cs index e62a185ef88..2d61d04ff92 100644 --- a/products/ASC.Files/Core/Helpers/DocuSignHelper.cs +++ b/products/ASC.Files/Core/Helpers/DocuSignHelper.cs @@ -55,9 +55,9 @@ using DocuSign.eSign.Api; using DocuSign.eSign.Client; -using DocuSign.eSign.Model; +using DocuSign.eSign.Model; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; diff --git a/products/ASC.Files/Core/Helpers/Global.cs b/products/ASC.Files/Core/Helpers/Global.cs index 088f6a3d88b..c475f4b9057 100644 --- a/products/ASC.Files/Core/Helpers/Global.cs +++ b/products/ASC.Files/Core/Helpers/Global.cs @@ -47,7 +47,7 @@ using ASC.Web.Files.Utils; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Constants = ASC.Core.Configuration.Constants; diff --git a/products/ASC.Files/Core/HttpHandlers/ChunkedUploaderHandler.cs b/products/ASC.Files/Core/HttpHandlers/ChunkedUploaderHandler.cs index ea4001d5488..7c9a616d6d6 100644 --- a/products/ASC.Files/Core/HttpHandlers/ChunkedUploaderHandler.cs +++ b/products/ASC.Files/Core/HttpHandlers/ChunkedUploaderHandler.cs @@ -112,17 +112,20 @@ public ChunkedUploaderHandlerService( Logger = optionsMonitor.CurrentValue; } - public async Task Invoke(HttpContext context) - { - var uploadSession = ChunkedUploadSessionHolder.GetSession(context.Request.Query["uid"]); - - if (uploadSession as ChunkedUploadSession != null) - { - await Invoke(context); - return; - } - - await Invoke(context); + public async Task Invoke(HttpContext context) + { + try + { + var uploadSession = ChunkedUploadSessionHolder.GetSession(context.Request.Query["uid"]); + if (uploadSession != null) + { + await Invoke(context); + } + } + catch (Exception) + { + await Invoke(context); + } } public async Task Invoke(HttpContext context) @@ -206,7 +209,7 @@ private bool TryAuthorize(ChunkedRequestHelper request) if (!string.IsNullOrEmpty(request.UploadId)) { - var uploadSession = ChunkedUploadSessionHolder.GetSession(request.UploadId); + var uploadSession = ChunkedUploadSessionHolder.GetSession(request.UploadId); if (uploadSession != null) { TenantManager.SetCurrentTenant(uploadSession.TenantId); diff --git a/products/ASC.Files/Core/HttpHandlers/SearchHandler.cs b/products/ASC.Files/Core/HttpHandlers/SearchHandler.cs index c5a59022bc5..072cb6a981a 100644 --- a/products/ASC.Files/Core/HttpHandlers/SearchHandler.cs +++ b/products/ASC.Files/Core/HttpHandlers/SearchHandler.cs @@ -130,39 +130,46 @@ public IEnumerable> SearchFolders(string text) public SearchResultItem[] Search(string text) { var folderDao = DaoFactory.GetFolderDao(); - var result = SearchFiles(text) - .Select(r => new SearchResultItem - { - Name = r.Title ?? string.Empty, - Description = string.Empty, - URL = FilesLinkUtility.GetFileWebPreviewUrl(FileUtility, r.Title, r.ID), - Date = r.ModifiedOn, - Additional = new Dictionary + var files = SearchFiles(text); + List list = new List(); + foreach (var file in files) + { + var searchResultItem = new SearchResultItem + { + Name = file.Title ?? string.Empty, + Description = string.Empty, + URL = FilesLinkUtility.GetFileWebPreviewUrl(FileUtility, file.Title, file.ID), + Date = file.ModifiedOn, + Additional = new Dictionary { - { "Author", r.CreateByString.HtmlEncode() }, - { "Path", FolderPathBuilder(EntryManager.GetBreadCrumbs(r.FolderID, folderDao)) }, - { "Size", FileSizeComment.FilesSizeToString(r.ContentLength) } + { "Author", file.CreateByString.HtmlEncode() }, + { "Path", FolderPathBuilder(EntryManager.GetBreadCrumbs(file.FolderID, folderDao)) }, + { "Size", FileSizeComment.FilesSizeToString(file.ContentLength) } } - } - ); - - var resultFolder = SearchFolders(text) - .Select(f => - new SearchResultItem - { - Name = f.Title ?? string.Empty, - Description = string.Empty, - URL = PathProvider.GetFolderUrl(f), - Date = f.ModifiedOn, - Additional = new Dictionary + }; + list.Add(searchResultItem); + } + + var folders = SearchFolders(text); + foreach (var folder in folders) + { + var searchResultItem = new SearchResultItem + { + Name = folder.Title ?? string.Empty, + Description = string.Empty, + URL = PathProvider.GetFolderUrl(folder), + Date = folder.ModifiedOn, + Additional = new Dictionary { - { "Author", f.CreateByString.HtmlEncode() }, - { "Path", FolderPathBuilder(EntryManager.GetBreadCrumbs(f.ID, folderDao)) }, + { "Author", folder.CreateByString.HtmlEncode() }, + { "Path", FolderPathBuilder(EntryManager.GetBreadCrumbs(folder.ID, folderDao)) }, { "IsFolder", true } } - }); + }; + list.Add(searchResultItem); + } - return result.Concat(resultFolder).ToArray(); + return list.ToArray(); } private static string FolderPathBuilder(IEnumerable folders) diff --git a/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs b/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs index 843c0eff200..5fd9a291f2f 100644 --- a/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs +++ b/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs @@ -33,7 +33,7 @@ using System.Text; using System.Threading; using System.Web; - + using ASC.Common.Caching; using ASC.Common.Logging; using ASC.Common.Web; @@ -59,14 +59,14 @@ using ASC.Web.Files.Services.DocumentService; using ASC.Web.Studio.Core; using ASC.Web.Studio.Utility; - + using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; - + using Newtonsoft.Json.Linq; - + using SecurityContext = ASC.Core.SecurityContext; namespace ASC.Web.Files.ThirdPartyApp @@ -218,13 +218,13 @@ public File GetFile(string fileId, out bool editable) var modifiedBy = jsonFile.Value("modified_by"); if (modifiedBy != null) { - file.ModifiedByString = modifiedBy.Value("name"); + file._modifiedByString = modifiedBy.Value("name"); } var createdBy = jsonFile.Value("created_by"); if (createdBy != null) { - file.CreateByString = createdBy.Value("name"); + file._createByString = createdBy.Value("name"); } diff --git a/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs b/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs index 99b5f2fb0d5..40bbbc57256 100644 --- a/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs +++ b/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs @@ -62,7 +62,7 @@ using ASC.Web.Studio.Utility; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -233,13 +233,13 @@ public File GetFile(string fileId, out bool editable) file.CreateOn = TenantUtil.DateTimeFromUtc(jsonFile.Value("createdTime")); file.ModifiedOn = TenantUtil.DateTimeFromUtc(jsonFile.Value("modifiedTime")); file.ContentLength = Convert.ToInt64(jsonFile.Value("size")); - file.ModifiedByString = jsonFile["lastModifyingUser"]["displayName"].Value(); + file._modifiedByString = jsonFile["lastModifyingUser"]["displayName"].Value(); file.ProviderKey = "Google"; var owners = jsonFile["owners"]; if (owners != null) { - file.CreateByString = owners[0]["displayName"].Value(); + file._createByString = owners[0]["displayName"].Value(); } editable = jsonFile["capabilities"]["canEdit"].Value(); diff --git a/products/ASC.Files/Core/Utils/ChunkedUploadSessionHolder.cs b/products/ASC.Files/Core/Utils/ChunkedUploadSessionHolder.cs index cabf4d5c99f..26be85d80bb 100644 --- a/products/ASC.Files/Core/Utils/ChunkedUploadSessionHolder.cs +++ b/products/ASC.Files/Core/Utils/ChunkedUploadSessionHolder.cs @@ -47,17 +47,20 @@ public class ChunkedUploadSessionHolder private GlobalStore GlobalStore { get; } private SetupInfo SetupInfo { get; } private TempPath TempPath { get; } + private FileHelper FileHelper { get; } public ChunkedUploadSessionHolder( IOptionsMonitor options, GlobalStore globalStore, SetupInfo setupInfo, - TempPath tempPath) + TempPath tempPath, + FileHelper fileHelper) { Options = options; GlobalStore = globalStore; SetupInfo = setupInfo; TempPath = tempPath; + FileHelper = fileHelper; // clear old sessions try @@ -78,16 +81,15 @@ public void StoreSession(ChunkedUploadSession s) public void RemoveSession(ChunkedUploadSession s) { CommonSessionHolder(false).Remove(s); - } + } + + public ChunkedUploadSession GetSession(string sessionId) + { + using var stream = CommonSessionHolder(false).GetStream(sessionId); + var chunkedUploadSession = ChunkedUploadSession.Deserialize(stream, FileHelper); + return chunkedUploadSession; + } - public ChunkedUploadSession GetSession(string sessionId) - { - return (ChunkedUploadSession)GetSession(sessionId); - } - public CommonChunkedUploadSession GetSession(string sessionId) - { - return CommonSessionHolder(false).Get(sessionId); - } public ChunkedUploadSession CreateUploadSession(File file, long contentLength) { diff --git a/products/ASC.Files/Core/Utils/EntryManager.cs b/products/ASC.Files/Core/Utils/EntryManager.cs index 7ee714a8155..1bb59280755 100644 --- a/products/ASC.Files/Core/Utils/EntryManager.cs +++ b/products/ASC.Files/Core/Utils/EntryManager.cs @@ -1104,8 +1104,8 @@ public File UpdateToVersionFile(T fileId, int version, string doc = null, try { - var currFile = fileDao.GetFile(fileId); - var newFile = ServiceProvider.GetService>(); + var currFile = fileDao.GetFile(fileId); + var newFile = ServiceProvider.GetService>(); newFile.ID = fromFile.ID; newFile.Version = currFile.Version + 1; diff --git a/products/ASC.Files/Core/Utils/FileShareLink.cs b/products/ASC.Files/Core/Utils/FileShareLink.cs index 3ac10c008d3..f47bf21d3d5 100644 --- a/products/ASC.Files/Core/Utils/FileShareLink.cs +++ b/products/ASC.Files/Core/Utils/FileShareLink.cs @@ -29,10 +29,10 @@ using ASC.Common; using ASC.Common.Utils; using ASC.Core.Common; -using ASC.Files.Core; +using ASC.Files.Core; using ASC.Files.Core.Security; using ASC.Web.Core.Files; -using ASC.Web.Files.Classes; +using ASC.Web.Files.Classes; using FileShare = ASC.Files.Core.Security.FileShare; diff --git a/products/ASC.Files/Core/Utils/FileUploader.cs b/products/ASC.Files/Core/Utils/FileUploader.cs index bc650d7e13e..dc8ed2e5c5f 100644 --- a/products/ASC.Files/Core/Utils/FileUploader.cs +++ b/products/ASC.Files/Core/Utils/FileUploader.cs @@ -45,7 +45,7 @@ using ASC.Web.Studio.UserControls.Statistics; using ASC.Web.Studio.Utility; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace ASC.Web.Files.Utils {