tesses-backup/TessesDedupWeb/Pages/EditAccessKey.razor

75 lines
2.0 KiB
Plaintext

@page "/access_keys/edit"
@inject Blazored.LocalStorage.ILocalStorageService localStorage;
@inject IJSRuntime jsRt;
@inject HttpClient client;
<div class="field label border">
<input type="text" @bind-value="_AccessKey">
<label>Access Key</label>
</div>
<details>
<summary class="none">
<article class="round primary no-elevate">
<nav>
<div class="max">Mount backups (Read only, Linux)</div>
<i>expand_more</i>
</nav>
</article>
</summary>
<article class="round border">
<h2>To Install</h2>
<code>
$ sudo apt install httpdirfs
</code>
</article>
<article class="round border">
<h2>To Mount</h2>
<code>
$ mkdir "~/BackupsMount"<br>
$ httpdirfs -u "\$access_key" -p "@_AccessKey" "@WebUrl" "~/BackupsMount"
</code>
</article>
<article class="round border">
<h2>To Unmount</h2>
<code>
$ umount "~/BackupsMount"
</code>
</article>
<article class="round border">
<h2>To Unmount (if busy and you are impatient)</h2>
<code>
$ umount -l "~/BackupsMount"
</code>
</article>
</details>
<br>
<button @onclick="async()=>await SaveAsync()"><i>save</i> Save</button>
<a href="/access_keys" class="button">Done</a>
@code {
public string _AccessKey {get;set;}="";
public string WebUrl => $"{(client.BaseAddress?.ToString() ?? "").TrimEnd('/')}/data/";
public async Task SaveAsync()
{
if(string.IsNullOrWhiteSpace(_AccessKey))
{
if(await localStorage.ContainKeyAsync("token"))
await localStorage.RemoveItemAsync("token");
}
else{
await localStorage.SetItemAsStringAsync("token",_AccessKey);
}
await jsRt.InvokeVoidAsync("alert","Saved");
}
protected override async Task OnInitializedAsync()
{
_AccessKey = await localStorage.GetItemAsStringAsync("token") ?? "";
}
}