This commit is contained in:
2026-05-17 20:54:09 -04:00
parent 6da2183583
commit 74c21ee5cc
3000 changed files with 11794 additions and 15301 deletions

View File

@@ -6,6 +6,7 @@
@using Microsoft.AspNetCore.Components.Forms
@using MudBlazor
@using OpenArchival.Blazor.Config
@using OpenArchival.DataAccess.FileAccessManager;
<style>
.file-upload-input {
@@ -99,6 +100,7 @@
@inject ISnackbar Snackbar;
@inject ILogger<UploadDropBox> _logger;
@inject IDialogService DialogService;
@inject IFileAccessManager FileAccessManager;
@code {
private const string DefaultDragClass = "relative rounded-lg border-2 border-dashed pa-4 mt-4 mud-width-full mud-height-full";
@@ -107,7 +109,7 @@
public readonly List<IBrowserFile> Files = new();
private readonly Dictionary<IBrowserFile, string> _fileToDiskFileName = new();
private readonly Dictionary<IBrowserFile, FilePathListing> _fileToDiskFileName = new();
private MudFileUpload<IReadOnlyList<IBrowserFile>>? _fileUpload;
@@ -147,12 +149,7 @@
{
try
{
FileInfo targetFile = new(pair.Value);
if (targetFile.Exists)
{
targetFile.Delete();
}
await PathProvider.DeleteFilePathListingAsync(pair.Key.Name, pair.Value);
await FileAccessManager.DeleteFileAsync(pair.Value.Id);
}
catch (Exception ex)
{
@@ -165,12 +162,7 @@
{
try
{
FileInfo targetFile = new(listing.Path);
if (targetFile.Exists)
{
targetFile.Delete();
}
await PathProvider.DeleteFilePathListingAsync(listing.OriginalName, listing.Path);
await FileAccessManager.DeleteFileAsync(listing.Id);
}
catch (Exception ex)
{
@@ -203,8 +195,8 @@
//StateHasChanged();
await InvokeAsync(StateHasChanged);
}
private async Task Upload()
{
if (!Files.Any())
@@ -221,19 +213,12 @@
if (_fileToDiskFileName.ContainsKey(file)) continue;
try
{
var diskFileName = $"{Guid.NewGuid()}{Path.GetExtension(file.Name)}";
var destinationPath = Path.Combine(_options.Value.UploadFolderPath, diskFileName);
await using var browserUploadStream = file.OpenReadStream(maxAllowedSize: _options.Value.MaxUploadSizeBytes);
await using var outFileStream = new FileStream(destinationPath, FileMode.Create);
var fileListing = await FileAccessManager.UploadFileAsync(file);
await browserUploadStream.CopyToAsync(outFileStream);
_fileToDiskFileName.Add(file, fileListing);
_fileToDiskFileName.Add(file, destinationPath);
var fileListing = new FilePathListing() { Path = destinationPath, OriginalName = Path.GetFileName(file.Name) };
fileListings.Add(fileListing);
await PathProvider.CreateFilePathListingAsync(fileListing);
Snackbar.Add($"Uploaded {file.Name}", Severity.Success);