121 lines
No EOL
3.4 KiB
Text
121 lines
No EOL
3.4 KiB
Text
@page "/drive"
|
|
@page "/drive/{Id}"
|
|
@attribute [Authorize]
|
|
@using Iceshrimp.Frontend.Localization
|
|
@using Microsoft.AspNetCore.Components.Sections
|
|
@using Microsoft.Extensions.Localization
|
|
@using Iceshrimp.Assets.PhosphorIcons
|
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
|
@using Iceshrimp.Frontend.Core.Services
|
|
@using Iceshrimp.Shared.Schemas.Web
|
|
@using Microsoft.AspNetCore.Authorization
|
|
@inject ApiService Api;
|
|
@inject IStringLocalizer<Localization> Loc;
|
|
@inject ILogger<DrivePage> Logger;
|
|
|
|
<SectionContent SectionName="top-bar">
|
|
<Icon Name="Icons.Cloud"></Icon>
|
|
@Loc["Drive"]
|
|
</SectionContent>
|
|
|
|
@if (_state == State.Loaded && Folder != null)
|
|
{
|
|
<ol class="drive-files">
|
|
@foreach (var el in Folder.Folders)
|
|
{
|
|
<li class="drive-entry">
|
|
<Icon Name="Icons.FolderOpen" Size="5em" Pack="IconStyle.Fill"/>
|
|
<span>@el.Name</span>
|
|
</li>
|
|
}
|
|
@foreach (var el in Folder.Files)
|
|
{
|
|
<li class="drive-entry">
|
|
<div class="labels">
|
|
@if (el.Description != null)
|
|
{
|
|
<Icon Name="Icons.ClosedCaptioning" title="@Loc["Has alt text"]"/>
|
|
}
|
|
else
|
|
{
|
|
<Icon Name="Icons.Warning" title="@Loc["No alt text"]"/>
|
|
}
|
|
@if (el.Sensitive)
|
|
{
|
|
<Icon Name="Icons.EyeSlash" title="@Loc["Sensitive"]"/>
|
|
}
|
|
</div>
|
|
@if (el.ContentType.StartsWith("image"))
|
|
{
|
|
<img class="thumbnail" src="@el.ThumbnailUrl" alt="@el.Description"/>
|
|
}
|
|
else if (el.ContentType.StartsWith("audio"))
|
|
{
|
|
<Icon Name="Icons.FileAudio" Size="5em"/>
|
|
}
|
|
else if (el.ContentType.StartsWith("video"))
|
|
{
|
|
<Icon Name="Icons.FileVideo" Size="5em"/>
|
|
}
|
|
else
|
|
{
|
|
<Icon Name="Icons.File" Size="5em"/>
|
|
}
|
|
<span>@el.Filename</span>
|
|
</li>
|
|
}
|
|
</ol>
|
|
}
|
|
@if (_state == State.Loading)
|
|
{
|
|
<div>Loading</div>
|
|
}
|
|
@if (_state == State.NotFound)
|
|
{
|
|
<div>This folder does not exist</div>
|
|
}
|
|
@if (_state == State.Error)
|
|
{
|
|
<div>An error occured while loading the drive folder. Please inspect logs.</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string? Id { get; set; }
|
|
private DriveFolderResponse? Folder { get; set; } = null;
|
|
private State _state { get; set; }
|
|
|
|
private async Task Load()
|
|
{
|
|
Logger.LogTrace($"Opening drive folder: {Id ?? "root"}");
|
|
_state = State.Loading;
|
|
|
|
try
|
|
{
|
|
Folder = await Api.Drive.GetFolderAsync(Id);
|
|
}
|
|
catch (ApiException e)
|
|
{
|
|
Logger.LogWarning($"Failed to load folder '{Id ?? "root"}' due to API Exception: {e.Message}");
|
|
_state = State.Error;
|
|
return;
|
|
}
|
|
|
|
if (Folder == null)
|
|
{
|
|
_state = State.NotFound;
|
|
return;
|
|
}
|
|
|
|
_state = State.Loaded;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Load();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await Load();
|
|
}
|
|
} |