Add ability to upload files

dhcp-server
Pat Hartl 2023-09-10 17:11:06 -05:00
parent 475a035d1c
commit 749d07a546
3 changed files with 70 additions and 1 deletions

View File

@ -40,7 +40,7 @@
</SpaceItem> </SpaceItem>
<SpaceItem> <SpaceItem>
<Tooltip Title="Upload File" MouseEnterDelay="2"> <Tooltip Title="Upload File" MouseEnterDelay="2">
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Upload" /> <Button Type="@ButtonType.Text" Icon="@IconType.Outline.Upload" OnClick="() => UploadModal.Open()" />
</Tooltip> </Tooltip>
</SpaceItem> </SpaceItem>
<SpaceItem> <SpaceItem>
@ -111,6 +111,7 @@
</div> </div>
<NewFolderModal @ref="NewFolderModal" OnFolderNameEntered="AddFolder" /> <NewFolderModal @ref="NewFolderModal" OnFolderNameEntered="AddFolder" />
<UploadModal @ref="UploadModal" Path="@Path.Path" OnUploadCompleted="() => Refresh()" />
@code { @code {
[Parameter] public Guid ArchiveId { get; set; } [Parameter] public Guid ArchiveId { get; set; }
@ -129,6 +130,7 @@
HashSet<FileManagerDirectory> Directories { get; set; } = new HashSet<FileManagerDirectory>(); HashSet<FileManagerDirectory> Directories { get; set; } = new HashSet<FileManagerDirectory>();
NewFolderModal NewFolderModal; NewFolderModal NewFolderModal;
UploadModal UploadModal;
Dictionary<string, object> OnRow(RowData<IFileManagerEntry> row) => new() Dictionary<string, object> OnRow(RowData<IFileManagerEntry> row) => new()
{ {

View File

@ -0,0 +1,42 @@
<Modal Title="Upload Files" Visible="@Visible" Draggable="true" DragInViewport="false" OnCancel="Close">
<Upload Action="/Upload/File" Name="file" Drag Multiple Data="Data" OnCompleted="OnCompleted">
<p class="ant-upload-drag-icon">
<Icon Type="@IconType.Outline.Upload" />
</p>
<p class="ant-upload-text">Click or Drag Files</p>
</Upload>
</Modal>
@code {
[Parameter] public string Path { get; set; }
[Parameter] public EventCallback OnUploadCompleted { get; set; }
bool Visible = false;
Dictionary<string, object> Data = new Dictionary<string, object>();
protected override void OnParametersSet()
{
Data["Path"] = Path;
}
public void Open()
{
Visible = true;
StateHasChanged();
}
public void Close()
{
Visible = false;
StateHasChanged();
}
async Task OnCompleted()
{
Close();
if (OnUploadCompleted.HasDelegate)
await OnUploadCompleted.InvokeAsync();
}
}

View File

@ -52,5 +52,30 @@ namespace LANCommander.Controllers
return Json("Done!"); return Json("Done!");
} }
[HttpPost]
public async Task<IActionResult> File(IFormFile file, string path)
{
try
{
if (!Directory.Exists(path))
return BadRequest("Destination path does not exist.");
path = Path.Combine(path, file.FileName);
using (var fileStream = System.IO.File.OpenWrite(path))
{
await file.CopyToAsync(fileStream);
}
return Ok();
}
catch (Exception ex)
{
Logger.Error(ex, "An error occurred while uploading the file");
return BadRequest("An error occurred while uploading the file.");
}
}
} }
} }