Merge branch 'release/1.0.0' of github.com:ONLYOFFICE/AppServer into release/1.0.0

This commit is contained in:
Viktor Fomin 2021-08-04 12:06:49 +03:00
commit d654a5a319
4 changed files with 113 additions and 106 deletions

View File

@ -122,10 +122,6 @@ namespace ASC.Data.Storage.DiscStorage
path += ".gz"; path += ".gz";
encoding = "gzip"; encoding = "gzip";
} }
using (var stream = storage.GetReadStream(_domain, path))
{
await stream.CopyToAsync(context.Response.Body);
}
var headersToCopy = new List<string> { "Content-Disposition", "Cache-Control", "Content-Encoding", "Content-Language", "Content-Type", "Expires" }; var headersToCopy = new List<string> { "Content-Disposition", "Cache-Control", "Content-Encoding", "Content-Language", "Content-Type", "Expires" };
foreach (var h in headers) foreach (var h in headers)
@ -147,6 +143,14 @@ namespace ASC.Data.Storage.DiscStorage
if (encoding != null) if (encoding != null)
context.Response.Headers["Content-Encoding"] = encoding; context.Response.Headers["Content-Encoding"] = encoding;
using (var stream = storage.GetReadStream(_domain, path))
{
await stream.CopyToAsync(context.Response.Body);
}
await context.Response.Body.FlushAsync();
await context.Response.CompleteAsync();
string GetRouteValue(string name) string GetRouteValue(string name)
{ {
return (context.GetRouteValue(name) ?? "").ToString(); return (context.GetRouteValue(name) ?? "").ToString();

View File

@ -52,7 +52,7 @@ namespace ASC.Web.Files.Core.Compress
/// <param name="title">File name with extension, this name will have the file in the archive</param> /// <param name="title">File name with extension, this name will have the file in the archive</param>
public void CreateEntry(string title) public void CreateEntry(string title)
{ {
zipEntry = new ZipEntry(title); zipEntry = new ZipEntry(title) { IsUnicodeText = true };
} }
/// <summary> /// <summary>

View File

@ -28,7 +28,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using ASC.Common; using ASC.Common;
@ -49,9 +48,6 @@ using ASC.Web.Studio.Core;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using SharpCompress.Common;
using SharpCompress.Writers.Zip;
namespace ASC.Web.Files.Services.WCFService.FileOperations namespace ASC.Web.Files.Services.WCFService.FileOperations
{ {
internal class FileDownloadOperationData<T> : FileOperationData<T> internal class FileDownloadOperationData<T> : FileOperationData<T>
@ -89,21 +85,23 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
using var scope = ThirdPartyOperation.CreateScope(); using var scope = ThirdPartyOperation.CreateScope();
var scopeClass = scope.ServiceProvider.GetService<FileDownloadOperationScope>(); var scopeClass = scope.ServiceProvider.GetService<FileDownloadOperationScope>();
var (zip, globalStore, filesLinkUtility, _, _, _) = scopeClass; var (globalStore, filesLinkUtility, _, _, _) = scopeClass;
using var stream = TempStream.Create(); var stream = TempStream.Create();
var writerOptions = new ZipWriterOptions(CompressionType.Deflate); (ThirdPartyOperation as FileDownloadOperation<string>).CompressToZip(stream, scope);
writerOptions.ArchiveEncoding.Default = Encoding.UTF8; (DaoOperation as FileDownloadOperation<int>).CompressToZip(stream, scope);
writerOptions.DeflateCompressionLevel = SharpCompress.Compressors.Deflate.CompressionLevel.Level3;
zip.SetStream(stream);
(ThirdPartyOperation as FileDownloadOperation<string>).CompressToZip(zip, stream, scope);
(DaoOperation as FileDownloadOperation<int>).CompressToZip(zip, stream, scope);
if (stream != null) if (stream != null)
{ {
var archiveExtension = "";
using(var zip = scope.ServiceProvider.GetService<CompressToArchive>())
{
archiveExtension = zip.ArchiveExtension;
}
stream.Position = 0; stream.Position = 0;
string fileName = FileConstant.DownloadTitle + zip.ArchiveExtension; string fileName = FileConstant.DownloadTitle + archiveExtension;
var store = globalStore.GetStore(); var store = globalStore.GetStore();
var path = string.Format(@"{0}\{1}", ((IAccount)Thread.CurrentPrincipal.Identity).ID, fileName); var path = string.Format(@"{0}\{1}", ((IAccount)Thread.CurrentPrincipal.Identity).ID, fileName);
@ -118,7 +116,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
stream, stream,
MimeMapping.GetMimeMapping(path), MimeMapping.GetMimeMapping(path),
"attachment; filename=\"" + fileName + "\""); "attachment; filename=\"" + fileName + "\"");
Result = string.Format("{0}?{1}=bulk&ext={2}", filesLinkUtility.FileHandlerPath, FilesLinkUtility.Action, zip.ArchiveExtension); Result = string.Format("{0}?{1}=bulk&ext={2}", filesLinkUtility.FileHandlerPath, FilesLinkUtility.Action, archiveExtension);
} }
FillDistributedTask(); FillDistributedTask();
@ -239,13 +237,17 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
return entriesPathId; return entriesPathId;
} }
internal void CompressToZip(ICompress compressTo, Stream stream, IServiceScope scope) internal void CompressToZip(Stream stream, IServiceScope scope)
{ {
if (entriesPathId == null) return; if (entriesPathId == null) return;
var scopeClass = scope.ServiceProvider.GetService<FileDownloadOperationScope>(); var scopeClass = scope.ServiceProvider.GetService<FileDownloadOperationScope>();
var (_, _, _, _, fileConverter, filesMessageService) = scopeClass; var (_, _, _, fileConverter, filesMessageService) = scopeClass;
var FileDao = scope.ServiceProvider.GetService<IFileDao<T>>(); var FileDao = scope.ServiceProvider.GetService<IFileDao<T>>();
using (var compressTo = scope.ServiceProvider.GetService<CompressToArchive>())
{
compressTo.SetStream(stream);
foreach (var path in entriesPathId.AllKeys) foreach (var path in entriesPathId.AllKeys)
{ {
var counter = 0; var counter = 0;
@ -349,6 +351,9 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
} }
} }
}
private void ReplaceLongPath(ItemNameValueCollection<T> entriesPathId) private void ReplaceLongPath(ItemNameValueCollection<T> entriesPathId)
{ {
foreach (var path in new List<string>(entriesPathId.AllKeys)) foreach (var path in new List<string>(entriesPathId.AllKeys))
@ -429,27 +434,23 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
private SetupInfo SetupInfo { get; } private SetupInfo SetupInfo { get; }
private FileConverter FileConverter { get; } private FileConverter FileConverter { get; }
private FilesMessageService FilesMessageService { get; } private FilesMessageService FilesMessageService { get; }
private CompressToArchive CompressToArchive { get; }
public FileDownloadOperationScope( public FileDownloadOperationScope(
GlobalStore globalStore, GlobalStore globalStore,
FilesLinkUtility filesLinkUtility, FilesLinkUtility filesLinkUtility,
SetupInfo setupInfo, SetupInfo setupInfo,
FileConverter fileConverter, FileConverter fileConverter,
FilesMessageService filesMessageService, FilesMessageService filesMessageService)
CompressToArchive compressToArchive)
{ {
GlobalStore = globalStore; GlobalStore = globalStore;
FilesLinkUtility = filesLinkUtility; FilesLinkUtility = filesLinkUtility;
SetupInfo = setupInfo; SetupInfo = setupInfo;
FileConverter = fileConverter; FileConverter = fileConverter;
FilesMessageService = filesMessageService; FilesMessageService = filesMessageService;
CompressToArchive = compressToArchive;
} }
public void Deconstruct(out CompressToArchive compressToArchive, out GlobalStore globalStore, out FilesLinkUtility filesLinkUtility, out SetupInfo setupInfo, out FileConverter fileConverter, out FilesMessageService filesMessageService) public void Deconstruct(out GlobalStore globalStore, out FilesLinkUtility filesLinkUtility, out SetupInfo setupInfo, out FileConverter fileConverter, out FilesMessageService filesMessageService)
{ {
compressToArchive = CompressToArchive;
globalStore = GlobalStore; globalStore = GlobalStore;
filesLinkUtility = FilesLinkUtility; filesLinkUtility = FilesLinkUtility;
setupInfo = SetupInfo; setupInfo = SetupInfo;

View File

@ -34,6 +34,7 @@ using ASC.Common;
using ASC.Common.Threading; using ASC.Common.Threading;
using ASC.Core.Tenants; using ASC.Core.Tenants;
using ASC.Files.Core.Resources; using ASC.Files.Core.Resources;
using ASC.Web.Files.Core.Compress;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -181,6 +182,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
services.TryAdd<FileMoveCopyOperationScope>(); services.TryAdd<FileMoveCopyOperationScope>();
services.TryAdd<FileOperationScope>(); services.TryAdd<FileOperationScope>();
services.TryAdd<FileDownloadOperationScope>(); services.TryAdd<FileDownloadOperationScope>();
services.TryAdd<CompressToArchive>();
services.AddDistributedTaskQueueService<FileOperation>(10); services.AddDistributedTaskQueueService<FileOperation>(10);
} }
} }