111 lines
4.2 KiB
Plaintext
111 lines
4.2 KiB
Plaintext
@page "/admin/api"
|
|
|
|
@using MoonCore.Blazor.Tailwind.Attributes
|
|
@using MoonCore.Helpers
|
|
@using MoonCore.Models
|
|
@using Moonlight.Shared.Http.Requests.Admin.ApiKeys
|
|
@using Moonlight.Shared.Http.Responses.Admin.ApiKeys
|
|
|
|
@attribute [RequirePermission("admin.apikeys.read")]
|
|
|
|
@inject HttpApiClient HttpApiClient
|
|
@inject AlertService AlertService
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-3 mb-8 gap-x-3">
|
|
<div class="col-span-1 card card-body border-l-4 border-primary-500">
|
|
<p class="font-medium tracking-wide text-slate-100">
|
|
API Documentation
|
|
</p>
|
|
<a href="/api/swagger" target="_blank" class="mt-2 flex items-center justify-between text-primary-500">
|
|
<div class="font-medium">Open</div>
|
|
<div>
|
|
<i class="bi bi-box-arrow-up-right text-lg text-primary-500"></i>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="col-span-1 card card-body border-l-4 border-tertiary-500">
|
|
<p class="font-medium tracking-wide text-slate-100">
|
|
Learn about the api usage
|
|
</p>
|
|
<a href="https://help.moonlightpanel.xyz" target="_blank" class="mt-2 flex items-center justify-between text-primary-500">
|
|
<div class="font-medium">Open</div>
|
|
<div>
|
|
<i class="bi bi-box-arrow-up-right text-lg text-tertiary-500"></i>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="col-span-1 card card-body border-l-4 border-success-500">
|
|
<p class="font-medium tracking-wide text-slate-100">
|
|
Open API Specification
|
|
</p>
|
|
<a href="/api/swagger/main" target="_blank" class="mt-2 flex items-center justify-between text-primary-500">
|
|
<div class="font-medium">Open</div>
|
|
<div>
|
|
<i class="bi bi-box-arrow-up-right text-lg text-success-500"></i>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<Crud TItem="ApiKeyDetailResponse"
|
|
TCreateForm="CreateApiKeyRequest"
|
|
TUpdateForm="UpdateApiKeyRequest"
|
|
OnConfigure="OnConfigure">
|
|
<View>
|
|
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.Id)" Title="Id"/>
|
|
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.Description)" Title="Description"/>
|
|
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.ExpiresAt)" Title="Expires at">
|
|
<Template>
|
|
@Formatter.FormatDate(context.ExpiresAt)
|
|
</Template>
|
|
</Column>
|
|
</View>
|
|
</Crud>
|
|
|
|
@code
|
|
{
|
|
private void OnConfigure(CrudOptions<ApiKeyDetailResponse, CreateApiKeyRequest, UpdateApiKeyRequest> crudOptions)
|
|
{
|
|
crudOptions.ItemName = "API Key";
|
|
|
|
crudOptions.ItemLoader = async (page, pageSize)
|
|
=> await HttpApiClient.GetJson<PagedData<ApiKeyDetailResponse>>($"api/admin/apikeys?page={page}&pageSize={pageSize}");
|
|
|
|
crudOptions.SingleItemLoader = async id
|
|
=> await HttpApiClient.GetJson<ApiKeyDetailResponse>($"api/admin/apikeys/{id}");
|
|
|
|
crudOptions.QueryIdentifier = response => response.Id.ToString();
|
|
|
|
crudOptions.OnCreate = async request =>
|
|
{
|
|
var response = await HttpApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", request);
|
|
|
|
await AlertService.Success(
|
|
"API Key successfully created",
|
|
$"Copy the following secret. It wont be shown again. '{response.Secret}'"
|
|
);
|
|
};
|
|
|
|
crudOptions.OnUpdate = async (item, request)
|
|
=> await HttpApiClient.Patch($"api/admin/apikeys/{item.Id}", request);
|
|
|
|
crudOptions.OnDelete = async item
|
|
=> await HttpApiClient.Delete($"api/admin/apikeys/{item.Id}");
|
|
|
|
crudOptions.OnConfigureCreate = configuration =>
|
|
{
|
|
configuration.WithField(x => x.Description);
|
|
configuration.WithField(x => x.PermissionsJson);
|
|
configuration.WithField(x => x.ExpiresAt, fieldConfiguration => { fieldConfiguration.DefaultValue = DateTime.UtcNow.AddMonths(1); });
|
|
};
|
|
|
|
crudOptions.OnConfigureUpdate = (_, configuration) =>
|
|
{
|
|
configuration.WithField(x => x.Description);
|
|
configuration.WithField(x => x.PermissionsJson);
|
|
configuration.WithField(x => x.ExpiresAt);
|
|
};
|
|
}
|
|
} |