@page "/backups/{id:long}"
@inject NavigationManager NavManager;
@inject DedupClient Client;
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
@if(IsReady)
{
if(IsDir)
{
if(ParentPath == "/backups")
{
Up @Path
}else{
Navmgr(ParentPath)">Up @Path
}
foreach(var item in Entries)
{
if(item.PointsTo.StartsWith("/api/v1/Download"))
{
@item.Type
@item.Name
}else{
Navmgr(item.PointsTo)">
@item.Type
@item.Name
}
}
}
}
@code {
[Parameter]
public long Id {get;set;}
public string Path {get;set;}="";
public bool IsReady {get;set;}=false;
public bool IsDir {get;set;}=false;
public string Url {get;set;}="";
public string ParentPath {get;set;}="";
public List Entries {get;set;}=new List();
string token="";
public void HandlePage(string path)
{
if(!string.IsNullOrWhiteSpace(path))
{
UnixPath unixPath = path;
var p=bkp.GetEntryFromPath(unixPath);
if(unixPath.Path == "/" || unixPath.Path.Length == 0)
ParentPath="/backups";
else
ParentPath = $"/backups/{Id}?path={WebUtility.UrlEncode(unixPath.Parent.Path)}";
if(p.Type == "dir")
{
IsDir=true;
foreach(var item in p.Entries)
{
FilesystemEntry ent = new FilesystemEntry();
ent.Name = item.Name;
if(item.Type == "dir")
{
ent.PointsTo = $"/backups/{Id}?path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
ent.Type = "folder";
}
else if(item.Type == "file")
{
ent.PointsTo = $"/api/v1/Download?access_key={WebUtility.UrlEncode(token)}&id={Id}&path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
ent.Type = "draft";
}
else
{
var follow = bkp.GetEntryFromPath(unixPath/item.Name);
if(follow.Type == "dir")
{
ent.PointsTo = $"/backups/{Id}?path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
}
else
{
ent.PointsTo = $"/api/v1/Download?access_key={WebUtility.UrlEncode(token)}&id={Id}&path={WebUtility.UrlEncode((unixPath/item.Name).Path)}";
}
ent.Type = "link";
}
Entries.Add(ent);
}
}
IsReady=true;
}
}
Backup bkp=new Backup();
private void Navmgr(string _url)
{
Entries.Clear();
IsReady=false;
NavManager.NavigateTo(_url);
var url=NavManager.ToAbsoluteUri(_url);
if(QueryHelpers.ParseQuery(url.Query).TryGetValue("path",out var value))
{
string? path = value;
if(!string.IsNullOrWhiteSpace(path))
{
HandlePage(path);
}
}
StateHasChanged();
}
protected override async Task OnInitializedAsync()
{
var _token = await localStorage.GetItemAsStringAsync("token");
if(!string.IsNullOrWhiteSpace(_token))
{
token = _token;
bkp = await Client.GetBackupAsync(token,Id);
Navmgr(NavManager.Uri);
}
}
}