Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Manager Refactoring #437

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions BedBrigade.Client/Components/MediaManager.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,39 +367,41 @@ private async Task HandleFileUpload(InputFileChangeEventArgs e)
{
try
{
if (e != null)
if (e == null)
return;

IReadOnlyList<IBrowserFile> inputFiles = e.GetMultipleFiles();

foreach (var file in inputFiles)
{
var inputFiles = e.GetMultipleFiles();
var targetPath = Path.Combine(CurrentFolderPath, file.Name);

foreach (var file in inputFiles)
if (!AllowedExtensions.Contains(Path.GetExtension(file.Name)))
{
var targetPath = Path.Combine(CurrentFolderPath, file.Name);
await MyModal.Show(Modal.ModalType.Alert, Modal.ModalIcon.Warning, ErrorTitle,
$"File type not allowed for {file.Name}. Valid File Types are:<br />" +
String.Join("<br />", AllowedExtensions));
return;
}

if (!AllowedExtensions.Contains(Path.GetExtension(file.Name)))
{
await MyModal.Show(Modal.ModalType.Alert, Modal.ModalIcon.Warning, ErrorTitle,
$"File type not allowed for {file.Name}. Valid File Types are:<br />" + String.Join("<br />",AllowedExtensions));
return;
}
if (file.Size > MaxFileSize)
{
await MyModal.Show(Modal.ModalType.Alert, Modal.ModalIcon.Warning, ErrorTitle,
$"File size exceeds the maximum limit of {MaxFileSize / 1024.0 / 1024.0:F2} MB for for {file.Name}.");
return;
}

if (file.Size > MaxFileSize)
{
await MyModal.Show(Modal.ModalType.Alert, Modal.ModalIcon.Warning, ErrorTitle,
$"File size exceeds the maximum limit of {MaxFileSize / 1024.0 / 1024.0:F2} MB for for {file.Name}.");
return;
}
MemoryStream stream = new MemoryStream();
await file.OpenReadStream(file.Size).CopyToAsync(stream);
byte[] fileBytes = stream.ToArray();

MemoryStream stream = new MemoryStream();
await file.OpenReadStream(file.Size).CopyToAsync(stream);
byte[] fileBytes = stream.ToArray();
await File.WriteAllBytesAsync(targetPath, fileBytes);
}

await File.WriteAllBytesAsync(targetPath, fileBytes);
}
// Refresh files after upload
RefreshFiles(CurrentFolderPath);
StateHasChanged();

// Refresh files after upload
RefreshFiles(CurrentFolderPath);
StateHasChanged();
}
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions BedBrigade.Tests/QualityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public void Setup()
{
_qualityLogic = LibraryFactory.CreateQualityLogic();
_qualityLogic.Config.SetConfig("CSharpMaxNotImplementedException", -1);
_qualityLogic.Config.SetConfig("MaxFileLength", 600);

//This has duplicate strings but it is okay since roles have multiple similar permissions
_qualityLogic.Config.FilesToExclude.Add("RoleNames.cs");

//This file is large, but it does not make sense to split it up
_qualityLogic.Config.FilesToExclude.Add("MediaManager.razor.cs");

_solutionPath = TestHelper.GetSolutionPath();
}

Expand Down
Loading