fix the id handling for the progressinfo and progressbar, include OnSelect events on Upload and Delete, add missing backend implementation for AddFileAsync
This commit is contained in:
@ -157,6 +157,15 @@
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<int> OnDelete { get; set; } // optional - executes a method in the calling component when a file is deleted
|
public EventCallback<int> OnDelete { get; set; } // optional - executes a method in the calling component when a file is deleted
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
// create unique id for component
|
||||||
|
_guid = Guid.NewGuid().ToString("N");
|
||||||
|
_fileinputid = "FileInput_" + _guid;
|
||||||
|
_progressinfoid = "ProgressInfo_" + _guid;
|
||||||
|
_progressbarid = "ProgressBar_" + _guid;
|
||||||
|
}
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
// packages folder is a framework folder for uploading installable nuget packages
|
// packages folder is a framework folder for uploading installable nuget packages
|
||||||
@ -223,12 +232,6 @@
|
|||||||
|
|
||||||
await GetFiles();
|
await GetFiles();
|
||||||
|
|
||||||
// create unique id for component
|
|
||||||
_guid = Guid.NewGuid().ToString("N");
|
|
||||||
_fileinputid = "FileInput_" + _guid;
|
|
||||||
_progressinfoid = "ProgressInfo_" + _guid;
|
|
||||||
_progressbarid = "ProgressBar_" + _guid;
|
|
||||||
|
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,8 +401,8 @@
|
|||||||
// reset progress indicators
|
// reset progress indicators
|
||||||
if (ShowProgress)
|
if (ShowProgress)
|
||||||
{
|
{
|
||||||
await interop.SetElementAttribute(_guid + "ProgressInfo", "style", "display: none;");
|
await interop.SetElementAttribute(_progressinfoid, "style", "display: none;");
|
||||||
await interop.SetElementAttribute(_guid + "ProgressBar", "style", "display: none;");
|
await interop.SetElementAttribute(_progressbarid, "style", "display: none;");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -435,6 +438,7 @@
|
|||||||
{
|
{
|
||||||
FileId = file.FileId;
|
FileId = file.FileId;
|
||||||
await SetImage();
|
await SetImage();
|
||||||
|
await OnSelect.InvokeAsync(FileId);
|
||||||
await OnUpload.InvokeAsync(FileId);
|
await OnUpload.InvokeAsync(FileId);
|
||||||
}
|
}
|
||||||
await GetFiles();
|
await GetFiles();
|
||||||
@ -481,7 +485,8 @@
|
|||||||
await GetFiles();
|
await GetFiles();
|
||||||
FileId = -1;
|
FileId = -1;
|
||||||
await SetImage();
|
await SetImage();
|
||||||
StateHasChanged();
|
await OnSelect.InvokeAsync(FileId);
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -159,6 +159,48 @@ namespace Oqtane.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POST api/<controller>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = RoleNames.Registered)]
|
||||||
|
public Models.File Post([FromBody] Models.File file)
|
||||||
|
{
|
||||||
|
var folder = _folders.GetFolder(file.FolderId);
|
||||||
|
if (ModelState.IsValid && folder != null && folder.SiteId == _alias.SiteId)
|
||||||
|
{
|
||||||
|
if (_userPermissions.IsAuthorized(User, folder.SiteId, EntityNames.Folder, file.FolderId, PermissionNames.Edit))
|
||||||
|
{
|
||||||
|
var filepath = _files.GetFilePath(file);
|
||||||
|
if (System.IO.File.Exists(filepath))
|
||||||
|
{
|
||||||
|
file = CreateFile(file.Name, folder.FolderId, filepath);
|
||||||
|
file = _files.AddFile(file);
|
||||||
|
_syncManager.AddSyncEvent(_alias.TenantId, EntityNames.File, file.FileId, SyncEventActions.Create);
|
||||||
|
_logger.Log(LogLevel.Information, this, LogFunction.Create, "File Added {File}", file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "File Does Not Exist At Path {FilePath}", filepath);
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||||
|
file = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized File Post Attempt {File}", file);
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
file = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized File Post Attempt {File}", file);
|
||||||
|
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
file = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
// PUT api/<controller>/5
|
// PUT api/<controller>/5
|
||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
[Authorize(Roles = RoleNames.Registered)]
|
[Authorize(Roles = RoleNames.Registered)]
|
||||||
|
Reference in New Issue
Block a user