Merge branch 'prerel-clean-gallery-download' into 'main'
Prerel clean gallery download See merge request personal/wedding-share!96
This commit is contained in:
@@ -1132,17 +1132,17 @@ namespace WeddingShare.Controllers
|
||||
|
||||
if (options.Uploads)
|
||||
{
|
||||
listing.Add(new ZipListing(UploadsDirectory, Directory.GetFiles(UploadsDirectory, "*", SearchOption.AllDirectories), "Uploads.bak"));
|
||||
listing.Add(new ZipListing(UploadsDirectory, Directory.GetFiles(UploadsDirectory, "*", SearchOption.AllDirectories), null, "Uploads.bak"));
|
||||
}
|
||||
|
||||
if (options.Thumbnails)
|
||||
{
|
||||
listing.Add(new ZipListing(ThumbnailsDirectory, Directory.GetFiles(ThumbnailsDirectory, "*", SearchOption.AllDirectories), "Thumbnails.bak"));
|
||||
listing.Add(new ZipListing(ThumbnailsDirectory, Directory.GetFiles(ThumbnailsDirectory, "*", SearchOption.AllDirectories), null, "Thumbnails.bak"));
|
||||
}
|
||||
|
||||
if (options.CustomResources && _fileHelper.DirectoryExists(CustomResourcesDirectory))
|
||||
{
|
||||
listing.Add(new ZipListing(CustomResourcesDirectory, Directory.GetFiles(CustomResourcesDirectory, "*", SearchOption.AllDirectories), "CustomResources.bak"));
|
||||
listing.Add(new ZipListing(CustomResourcesDirectory, Directory.GetFiles(CustomResourcesDirectory, "*", SearchOption.AllDirectories), null, "CustomResources.bak"));
|
||||
}
|
||||
|
||||
var response = await ZipFileResponse($"WeddingShare-{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip", listing);
|
||||
|
||||
@@ -31,11 +31,11 @@ namespace WeddingShare.Controllers
|
||||
{
|
||||
var files = contents?.Files?.Where(x => x.StartsWith(contents.SourcePath, StringComparison.OrdinalIgnoreCase));
|
||||
if (files != null && files.Any())
|
||||
{
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(contents?.FileName))
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
{
|
||||
using (var archive = new ZipArchive(ms, ZipArchiveMode.Create, true))
|
||||
{
|
||||
foreach (var file in files)
|
||||
@@ -53,7 +53,7 @@ namespace WeddingShare.Controllers
|
||||
}
|
||||
|
||||
var relativePath = $"{contents.FileName.TrimStart('/')}";
|
||||
var zipEntry = zipArchive.CreateEntry(relativePath);
|
||||
var zipEntry = zipArchive.CreateEntry(!string.IsNullOrWhiteSpace(contents.Directory) ? Path.Combine(contents.Directory, relativePath) : relativePath);
|
||||
|
||||
using (var entryStream = zipEntry.Open())
|
||||
{
|
||||
@@ -67,7 +67,7 @@ namespace WeddingShare.Controllers
|
||||
foreach (var file in files)
|
||||
{
|
||||
var relativePath = Path.GetRelativePath(contents.SourcePath, file);
|
||||
var zipEntry = zipArchive.CreateEntry(relativePath);
|
||||
var zipEntry = zipArchive.CreateEntry(!string.IsNullOrWhiteSpace(contents.Directory) ? Path.Combine(contents.Directory, relativePath) : relativePath);
|
||||
|
||||
using (var fs = System.IO.File.OpenRead(file))
|
||||
using (var entryStream = zipEntry.Open())
|
||||
|
||||
@@ -577,14 +577,52 @@ namespace WeddingShare.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
var searchOption = (User?.Identity == null || !User.Identity.IsAuthenticated) ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories;
|
||||
var files = Directory.GetFiles(galleryDir, "*", searchOption);
|
||||
if (fileFilter != null && fileFilter.Any())
|
||||
{
|
||||
files = files.Where(x => fileFilter.Exists(y => Path.GetFileName(y).Equals(Path.GetFileName(x), StringComparison.OrdinalIgnoreCase))).ToArray();
|
||||
}
|
||||
var archieveName = $"{gallery?.Identifier ?? "WeddingShare"}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip";
|
||||
|
||||
return await ZipFileResponse($"{gallery?.Identifier ?? "WeddingShare"}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip", new ZipListing(galleryDir, files));
|
||||
var listing = new List<ZipListing>();
|
||||
|
||||
if (User?.Identity == null || !User.Identity.IsAuthenticated)
|
||||
{
|
||||
var files = Directory.GetFiles(galleryDir, "*", SearchOption.TopDirectoryOnly);
|
||||
if (fileFilter != null && fileFilter.Any())
|
||||
{
|
||||
files = files.Where(x => fileFilter.Exists(y => Path.GetFileName(y).Equals(Path.GetFileName(x), StringComparison.OrdinalIgnoreCase))).ToArray();
|
||||
}
|
||||
|
||||
if (files != null && files.Any())
|
||||
{
|
||||
listing.Add(new ZipListing(galleryDir, files));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var scanners = new List<ZipListingScanner>()
|
||||
{
|
||||
new ZipListingScanner("Approved", galleryDir, SearchOption.TopDirectoryOnly),
|
||||
new ZipListingScanner("Pending", Path.Combine(galleryDir, "Pending"), SearchOption.AllDirectories),
|
||||
new ZipListingScanner("Rejected", Path.Combine(galleryDir, "Rejected"), SearchOption.AllDirectories),
|
||||
};
|
||||
|
||||
foreach (var scanner in scanners)
|
||||
{
|
||||
try
|
||||
{
|
||||
var files = Directory.GetFiles(scanner.Path, "*", scanner.SearchOption);
|
||||
if (fileFilter != null && fileFilter.Any())
|
||||
{
|
||||
files = files.Where(x => fileFilter.Exists(y => Path.GetFileName(y).Equals(Path.GetFileName(x), StringComparison.OrdinalIgnoreCase))).ToArray();
|
||||
}
|
||||
|
||||
if (files != null && files.Any())
|
||||
{
|
||||
listing.Add(new ZipListing(scanner.Path, files, scanner.Name));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
return await ZipFileResponse(archieveName, listing);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -2,15 +2,31 @@ namespace WeddingShare.Models
|
||||
{
|
||||
public class ZipListing
|
||||
{
|
||||
public ZipListing(string sourcePath, IEnumerable<string> files, string? filename = null)
|
||||
public ZipListing(string sourcePath, IEnumerable<string> files, string? directory = null, string? filename = null)
|
||||
{
|
||||
this.SourcePath = sourcePath;
|
||||
this.Directory = directory;
|
||||
this.FileName = filename;
|
||||
this.Files = files;
|
||||
}
|
||||
|
||||
public string SourcePath { get; }
|
||||
public string? FileName { get; }
|
||||
public string? Directory { get; }
|
||||
public IEnumerable<string>? Files { get; }
|
||||
}
|
||||
|
||||
public class ZipListingScanner
|
||||
{
|
||||
public ZipListingScanner(string name, string path, SearchOption searchOption = SearchOption.TopDirectoryOnly)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Path = path;
|
||||
this.SearchOption = searchOption;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string Path { get; }
|
||||
public SearchOption SearchOption { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user