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";
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" };
foreach (var h in headers)
@ -147,6 +143,14 @@ namespace ASC.Data.Storage.DiscStorage
if (encoding != null)
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)
{
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>
public void CreateEntry(string title)
{
zipEntry = new ZipEntry(title);
zipEntry = new ZipEntry(title) { IsUnicodeText = true };
}
/// <summary>

View File

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

View File

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