Удалено лишнее
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
<CascadingAuthenticationState>
|
|
||||||
<Router AppAssembly="@typeof(App).Assembly" NotFoundPage="typeof(Pages.NotFound)" >
|
|
||||||
<Found Context="routeData">
|
|
||||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
|
|
||||||
<NotAuthorized>
|
|
||||||
@if (context.User.Identity?.IsAuthenticated != true)
|
|
||||||
{
|
|
||||||
<RedirectToLogin />
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<p role="alert">You are not authorized to access this resource.</p>
|
|
||||||
}
|
|
||||||
</NotAuthorized>
|
|
||||||
</AuthorizeRouteView>
|
|
||||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
|
||||||
</Found>
|
|
||||||
</Router>
|
|
||||||
</CascadingAuthenticationState>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
|
||||||
@inject NavigationManager Navigation
|
|
||||||
|
|
||||||
<AuthorizeView>
|
|
||||||
<Authorized>
|
|
||||||
<MudText Typo="Typo.body2" Class="d-inline mr-2">Hello, @context.User.Identity?.Name!</MudText>
|
|
||||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="BeginLogOut">Log out</MudButton>
|
|
||||||
</Authorized>
|
|
||||||
<NotAuthorized>
|
|
||||||
<MudLink Href="authentication/login" Color="Color.Inherit" Underline="Underline.Hover" Typo="Typo.body2">Log in</MudLink>
|
|
||||||
</NotAuthorized>
|
|
||||||
</AuthorizeView>
|
|
||||||
|
|
||||||
@code{
|
|
||||||
public void BeginLogOut()
|
|
||||||
{
|
|
||||||
Navigation.NavigateToLogout("authentication/logout");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
@inherits LayoutComponentBase
|
|
||||||
|
|
||||||
<MudThemeProvider Theme="@_theme" IsDarkMode="_isDarkMode" />
|
|
||||||
<MudPopoverProvider />
|
|
||||||
<MudDialogProvider />
|
|
||||||
<MudSnackbarProvider />
|
|
||||||
|
|
||||||
<MudLayout>
|
|
||||||
<MudAppBar Elevation="1">
|
|
||||||
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@DrawerToggle" />
|
|
||||||
<MudText Typo="Typo.h6" Class="ml-2">Application</MudText>
|
|
||||||
<MudSpacer />
|
|
||||||
<LoginDisplay />
|
|
||||||
<MudIconButton Icon="@(DarkLightModeButtonIcon)" Color="Color.Inherit" OnClick="@DarkModeToggle" Class="ml-2" />
|
|
||||||
<MudLink Href="https://learn.microsoft.com/aspnet/core/" Target="_blank" Color="Color.Inherit" Underline="Underline.None" Class="ml-4">
|
|
||||||
About
|
|
||||||
</MudLink>
|
|
||||||
</MudAppBar>
|
|
||||||
|
|
||||||
<MudDrawer @bind-Open="_drawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
|
|
||||||
<NavMenu />
|
|
||||||
</MudDrawer>
|
|
||||||
|
|
||||||
<MudMainContent Class="pt-16 pa-4">
|
|
||||||
@Body
|
|
||||||
</MudMainContent>
|
|
||||||
</MudLayout>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private bool _drawerOpen = true;
|
|
||||||
private bool _isDarkMode = true;
|
|
||||||
private MudTheme? _theme;
|
|
||||||
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
base.OnInitialized();
|
|
||||||
|
|
||||||
_theme = new()
|
|
||||||
{
|
|
||||||
PaletteLight = _lightPalette,
|
|
||||||
PaletteDark = _darkPalette,
|
|
||||||
LayoutProperties = new LayoutProperties()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawerToggle()
|
|
||||||
{
|
|
||||||
_drawerOpen = !_drawerOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DarkModeToggle()
|
|
||||||
{
|
|
||||||
_isDarkMode = !_isDarkMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly PaletteLight _lightPalette = new()
|
|
||||||
{
|
|
||||||
Black = "#110e2d",
|
|
||||||
AppbarText = "#424242",
|
|
||||||
AppbarBackground = "rgba(255,255,255,0.8)",
|
|
||||||
DrawerBackground = "#ffffff",
|
|
||||||
GrayLight = "#e8e8e8",
|
|
||||||
GrayLighter = "#f9f9f9",
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly PaletteDark _darkPalette = new()
|
|
||||||
{
|
|
||||||
Primary = "#7e6fff",
|
|
||||||
Surface = "#1e1e2d",
|
|
||||||
Background = "#1a1a27",
|
|
||||||
BackgroundGray = "#151521",
|
|
||||||
AppbarText = "#92929f",
|
|
||||||
AppbarBackground = "rgba(26,26,39,0.8)",
|
|
||||||
DrawerBackground = "#1a1a27",
|
|
||||||
ActionDefault = "#74718e",
|
|
||||||
ActionDisabled = "#9999994d",
|
|
||||||
ActionDisabledBackground = "#605f6d4d",
|
|
||||||
TextPrimary = "#b2b0bf",
|
|
||||||
TextSecondary = "#92929f",
|
|
||||||
TextDisabled = "#ffffff33",
|
|
||||||
DrawerIcon = "#92929f",
|
|
||||||
DrawerText = "#92929f",
|
|
||||||
GrayLight = "#2a2833",
|
|
||||||
GrayLighter = "#1e1e2d",
|
|
||||||
Info = "#4a86ff",
|
|
||||||
Success = "#3dcb6c",
|
|
||||||
Warning = "#ffb545",
|
|
||||||
Error = "#ff3f5f",
|
|
||||||
LinesDefault = "#33323e",
|
|
||||||
TableLines = "#33323e",
|
|
||||||
Divider = "#292838",
|
|
||||||
OverlayLight = "#1e1e2d80",
|
|
||||||
};
|
|
||||||
|
|
||||||
public string DarkLightModeButtonIcon => _isDarkMode switch
|
|
||||||
{
|
|
||||||
true => Icons.Material.Rounded.AutoMode,
|
|
||||||
false => Icons.Material.Outlined.DarkMode,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
.page {
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar {
|
|
||||||
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row {
|
|
||||||
background-color: #f7f7f7;
|
|
||||||
border-bottom: 1px solid #d6d5d5;
|
|
||||||
justify-content: flex-end;
|
|
||||||
height: 3.5rem;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row ::deep a, .top-row ::deep .btn-link {
|
|
||||||
white-space: nowrap;
|
|
||||||
margin-left: 1.5rem;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row ::deep a:first-child {
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 640.98px) {
|
|
||||||
.top-row {
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row ::deep a, .top-row ::deep .btn-link {
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 641px) {
|
|
||||||
.page {
|
|
||||||
flex-direction: row;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar {
|
|
||||||
width: 250px;
|
|
||||||
height: 100vh;
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row {
|
|
||||||
position: sticky;
|
|
||||||
top: 0;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row.auth ::deep a:first-child {
|
|
||||||
flex: 1;
|
|
||||||
text-align: right;
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.top-row, article {
|
|
||||||
padding-left: 2rem !important;
|
|
||||||
padding-right: 1.5rem !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<MudNavMenu>
|
|
||||||
<MudNavLink Href="/" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
|
|
||||||
<AuthorizeView>
|
|
||||||
<Authorized>
|
|
||||||
<MudNavLink Href="/create" Icon="@Icons.Material.Filled.Add">Создать плейлист</MudNavLink>
|
|
||||||
<MudNavLink Href="/my" Icon="@Icons.Material.Filled.List">Мои ссылки</MudNavLink>
|
|
||||||
</Authorized>
|
|
||||||
</AuthorizeView>
|
|
||||||
</MudNavMenu>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
|
||||||
@inject NavigationManager Navigation
|
|
||||||
|
|
||||||
@code {
|
|
||||||
protected override void OnInitialized()
|
|
||||||
{
|
|
||||||
Navigation.NavigateToLogin("authentication/login");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
@page "/auth-callback"
|
|
||||||
@using PlaylistShared.PWA.Services
|
|
||||||
@inject NavigationManager Navigation
|
|
||||||
@inject AuthStateProvider AuthProvider
|
|
||||||
@inject ISnackbar Snackbar
|
|
||||||
|
|
||||||
@code {
|
|
||||||
[Parameter] public string? Token { get; set; }
|
|
||||||
[Parameter] public string? RefreshToken { get; set; }
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(Token) && !string.IsNullOrEmpty(RefreshToken))
|
|
||||||
{
|
|
||||||
await AuthProvider.MarkUserAsAuthenticated(Token, RefreshToken);
|
|
||||||
Navigation.NavigateTo("/");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Snackbar.Add("Ошибка аутентификации через Яндекс", Severity.Error);
|
|
||||||
Navigation.NavigateTo("/login");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
@page "/authentication/{action}"
|
|
||||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
|
||||||
<RemoteAuthenticatorView Action="@Action" />
|
|
||||||
|
|
||||||
@code{
|
|
||||||
[Parameter] public string? Action { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
@page "/counter"
|
|
||||||
|
|
||||||
<PageTitle>Counter</PageTitle>
|
|
||||||
|
|
||||||
<MudText Typo="Typo.h3" GutterBottom="true">Counter</MudText>
|
|
||||||
|
|
||||||
<MudText Class="mb-4">Current count: @currentCount</MudText>
|
|
||||||
|
|
||||||
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private int currentCount = 0;
|
|
||||||
|
|
||||||
private void IncrementCount()
|
|
||||||
{
|
|
||||||
currentCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
@page "/"
|
|
||||||
|
|
||||||
<PageTitle>Home</PageTitle>
|
|
||||||
|
|
||||||
<MudText Typo="Typo.h3" GutterBottom="true">Hello, world!</MudText>
|
|
||||||
<MudText Class="mb-8">Welcome to your new app, powered by MudBlazor and the .NET 10 Template!</MudText>
|
|
||||||
|
|
||||||
<MudAlert Severity="Severity.Warning" Variant="Variant.Outlined" Dense="true" Class="mb-6">
|
|
||||||
Before authentication will function correctly, you must configure your provider details in <code>Program.cs</code>.
|
|
||||||
</MudAlert>
|
|
||||||
|
|
||||||
|
|
||||||
<MudAlert Severity="Severity.Normal" ContentAlignment="HorizontalAlignment.Start">
|
|
||||||
You can find documentation and examples on our website here:
|
|
||||||
<MudLink Href="https://mudblazor.com" Target="_blank" Typo="Typo.body2" Color="Color.Primary">
|
|
||||||
<b>www.mudblazor.com</b>
|
|
||||||
</MudLink>
|
|
||||||
</MudAlert>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
@page "/login"
|
|
||||||
@using PlaylistShared.PWA.Services
|
|
||||||
@inject NavigationManager Navigation
|
|
||||||
@inject AuthStateProvider AuthProvider
|
|
||||||
@inject ApiClient ApiClient
|
|
||||||
@inject ISnackbar Snackbar
|
|
||||||
|
|
||||||
<MudContainer MaxWidth="MaxWidth.Small" Class="mt-16">
|
|
||||||
<MudCard>
|
|
||||||
<MudCardContent Class="text-center">
|
|
||||||
<MudText Typo="Typo.h5" Class="mb-4">Вход в PlaylistShared</MudText>
|
|
||||||
|
|
||||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="LoginWithYandex" StartIcon="@Icons.Custom.Brands.Yandex" FullWidth="true">
|
|
||||||
Войти через Яндекс
|
|
||||||
</MudButton>
|
|
||||||
|
|
||||||
<MudDivider Class="my-4">или</MudDivider>
|
|
||||||
|
|
||||||
<MudTextField Label="Логин" @bind-Value="_username" Variant="Variant.Outlined" FullWidth="true" />
|
|
||||||
<MudTextField Label="Пароль" @bind-Value="_password" InputType="InputType.Password" Variant="Variant.Outlined" FullWidth="true" />
|
|
||||||
<MudButton Variant="Variant.Filled" Color="Color.Secondary" OnClick="LoginWithPassword" FullWidth="true">Войти по паролю</MudButton>
|
|
||||||
|
|
||||||
<MudText Class="mt-4">
|
|
||||||
Нет аккаунта? <MudLink Href="/register">Зарегистрироваться</MudLink>
|
|
||||||
</MudText>
|
|
||||||
</MudCardContent>
|
|
||||||
</MudCard>
|
|
||||||
</MudContainer>
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private string _username = "";
|
|
||||||
private string _password = "";
|
|
||||||
|
|
||||||
private void LoginWithYandex()
|
|
||||||
{
|
|
||||||
Navigation.NavigateTo("https://localhost:5001/api/externalauth/login-yandex", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task LoginWithPassword()
|
|
||||||
{
|
|
||||||
var result = await ApiClient.LoginAsync(_username, _password);
|
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
await AuthProvider.MarkUserAsAuthenticated(result.Token, result.RefreshToken);
|
|
||||||
Navigation.NavigateTo("/");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Snackbar.Add("Неверный логин или пароль", Severity.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
@inject NavigationManager Navigation
|
|
||||||
|
|
||||||
<AuthorizeView>
|
|
||||||
<Authorized>
|
|
||||||
<MudText Typo="Typo.body2" Class="d-inline mr-2">Hello, @context.User.Identity?.Name!</MudText>
|
|
||||||
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="() => Navigation.NavigateTo("/logout")">Log out</MudButton>
|
|
||||||
</Authorized>
|
|
||||||
<NotAuthorized>
|
|
||||||
<MudLink Href="/login" Color="Color.Inherit" Underline="Underline.Hover" Typo="Typo.body2">Log in</MudLink>
|
|
||||||
</NotAuthorized>
|
|
||||||
</AuthorizeView>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
@page "/logout"
|
|
||||||
@using PlaylistShared.PWA.Services
|
|
||||||
@inject AuthStateProvider AuthProvider
|
|
||||||
@inject NavigationManager Navigation
|
|
||||||
|
|
||||||
@code {
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
await AuthProvider.MarkUserAsLoggedOut();
|
|
||||||
Navigation.NavigateTo("/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
@page "/not-found"
|
|
||||||
@layout MainLayout
|
|
||||||
|
|
||||||
<PageTitle>Not Found</PageTitle>
|
|
||||||
|
|
||||||
<MudText Typo="Typo.h3" GutterBottom="true">404 - Page Not Found</MudText>
|
|
||||||
<MudText Class="mb-8">Sorry, the content you are looking for does not exist.</MudText>
|
|
||||||
|
|
||||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" Href="/">Go to Home</MudButton>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
@page "/weather"
|
|
||||||
@inject HttpClient Http
|
|
||||||
|
|
||||||
<PageTitle>Weather</PageTitle>
|
|
||||||
|
|
||||||
<MudText Typo="Typo.h3" GutterBottom="true">Weather forecast</MudText>
|
|
||||||
<MudText Typo="Typo.body1" Class="mb-8">This component demonstrates fetching data from the server.</MudText>
|
|
||||||
|
|
||||||
@if (forecasts == null)
|
|
||||||
{
|
|
||||||
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<MudTable Items="forecasts" Hover="true" SortLabel="Sort By" Elevation="0" AllowUnsorted="false">
|
|
||||||
<HeaderContent>
|
|
||||||
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<WeatherForecast, object>(x => x.Date)">Date</MudTableSortLabel></MudTh>
|
|
||||||
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureC)">Temp. (C)</MudTableSortLabel></MudTh>
|
|
||||||
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureF)">Temp. (F)</MudTableSortLabel></MudTh>
|
|
||||||
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.Summary!)">Summary</MudTableSortLabel></MudTh>
|
|
||||||
</HeaderContent>
|
|
||||||
<RowTemplate>
|
|
||||||
<MudTd DataLabel="Date">@context.Date</MudTd>
|
|
||||||
<MudTd DataLabel="Temp. (C)">@context.TemperatureC</MudTd>
|
|
||||||
<MudTd DataLabel="Temp. (F)">@context.TemperatureF</MudTd>
|
|
||||||
<MudTd DataLabel="Summary">@context.Summary</MudTd>
|
|
||||||
</RowTemplate>
|
|
||||||
<PagerContent>
|
|
||||||
<MudTablePager PageSizeOptions="new int[] { 50, 100 }" />
|
|
||||||
</PagerContent>
|
|
||||||
</MudTable>
|
|
||||||
}
|
|
||||||
|
|
||||||
@code {
|
|
||||||
private WeatherForecast[]? forecasts;
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
|
||||||
{
|
|
||||||
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateOnly Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public string? Summary { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
|
|
||||||
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="AspNet.Security.OAuth.Yandex" Version="10.0.0" />
|
|
||||||
<PackageReference Include="MudBlazor" Version="9.3.0" />
|
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.17.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\PlaylistShared.Shared\PlaylistShared.Shared.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ServiceWorker Include="wwwroot\\service-worker.js" PublishedContent="wwwroot\\service-worker.published.js" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Components.Web;
|
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
||||||
using MudBlazor.Services;
|
|
||||||
using PlaylistShared.PWA;
|
|
||||||
using PlaylistShared.PWA.Services;
|
|
||||||
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
private static async global::System.Threading.Tasks.Task Main(string[] args)
|
|
||||||
{
|
|
||||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
||||||
builder.RootComponents.Add<App>("#app");
|
|
||||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
|
||||||
|
|
||||||
builder.Services.AddMudServices();
|
|
||||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
|
||||||
|
|
||||||
builder.Services.AddScoped<TokenStorage>();
|
|
||||||
builder.Services.AddScoped<AuthStateProvider>();
|
|
||||||
builder.Services.AddScoped<ApiClient>();
|
|
||||||
|
|
||||||
builder.Services.AddAuthorizationCore();
|
|
||||||
builder.Services.AddCascadingAuthenticationState();
|
|
||||||
|
|
||||||
/*
|
|
||||||
builder.Services.AddOidcAuthentication(options =>
|
|
||||||
{
|
|
||||||
// Configure your authentication provider options here.
|
|
||||||
// For more information, see https://aka.ms/blazor-standalone-auth
|
|
||||||
builder.Configuration.Bind("Local", options.ProviderOptions);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
await builder.Build().RunAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
|
||||||
"profiles": {
|
|
||||||
"https": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
|
||||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
|
||||||
"applicationUrl": "https://localhost:7244;http://localhost:5143",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
using PlaylistShared.Shared.DTO;
|
|
||||||
using PlaylistShared.Shared.Models;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
|
|
||||||
namespace PlaylistShared.PWA.Services;
|
|
||||||
|
|
||||||
public class ApiClient
|
|
||||||
{
|
|
||||||
private readonly HttpClient _http;
|
|
||||||
private readonly TokenStorage _tokenStorage;
|
|
||||||
|
|
||||||
public ApiClient(HttpClient http, TokenStorage tokenStorage)
|
|
||||||
{
|
|
||||||
_http = http;
|
|
||||||
_tokenStorage = tokenStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<LoginResponse?> RefreshTokenAsync(string? refreshToken)
|
|
||||||
{
|
|
||||||
var response = await _http.PostAsJsonAsync("/api/account/refresh-token", new RefreshTokenRequest { RefreshToken = refreshToken });
|
|
||||||
if (!response.IsSuccessStatusCode) return null;
|
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<LoginResponse>>();
|
|
||||||
return apiResponse?.Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<LoginResponse?> LoginAsync(string username, string password)
|
|
||||||
{
|
|
||||||
var response = await _http.PostAsJsonAsync("/api/account/login", new LoginRequest { Username = username, Password = password });
|
|
||||||
if (!response.IsSuccessStatusCode) return null;
|
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<LoginResponse>>();
|
|
||||||
return apiResponse?.Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<LoginResponse?> RegisterAsync(string username, string email, string password)
|
|
||||||
{
|
|
||||||
var response = await _http.PostAsJsonAsync("/api/account/register", new RegisterRequest { Username = username, Email = email, Password = password });
|
|
||||||
if (!response.IsSuccessStatusCode) return null;
|
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<LoginResponse>>();
|
|
||||||
return apiResponse?.Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<SharedPlaylistDto?> CreateSharedPlaylistAsync(SharePlaylistDto dto)
|
|
||||||
{
|
|
||||||
var response = await _http.PostAsJsonAsync("/api/sharedplaylist", dto);
|
|
||||||
if (!response.IsSuccessStatusCode) return null;
|
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<SharedPlaylistDto>>();
|
|
||||||
return apiResponse?.Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<SharedPlaylistDto?> GetSharedPlaylistAsync(string token)
|
|
||||||
{
|
|
||||||
var response = await _http.GetAsync($"/api/sharedplaylist/{token}");
|
|
||||||
if (!response.IsSuccessStatusCode) return null;
|
|
||||||
var apiResponse = await response.Content.ReadFromJsonAsync<ApiResponse<SharedPlaylistDto>>();
|
|
||||||
return apiResponse?.Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> AddTracksAsync(string sharedPlaylistToken, List<string> trackIds)
|
|
||||||
{
|
|
||||||
var response = await _http.PostAsJsonAsync("/api/playlist/add-tracks", new AddTrackRequest
|
|
||||||
{
|
|
||||||
SharedPlaylistToken = sharedPlaylistToken,
|
|
||||||
TrackIds = trackIds
|
|
||||||
});
|
|
||||||
return response.IsSuccessStatusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> RemoveTracksAsync(string sharedPlaylistToken, List<string> trackIds)
|
|
||||||
{
|
|
||||||
var response = await _http.PostAsJsonAsync("/api/playlist/remove-tracks", new AddTrackRequest
|
|
||||||
{
|
|
||||||
SharedPlaylistToken = sharedPlaylistToken,
|
|
||||||
TrackIds = trackIds
|
|
||||||
});
|
|
||||||
return response.IsSuccessStatusCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Security.Claims;
|
|
||||||
|
|
||||||
namespace PlaylistShared.PWA.Services;
|
|
||||||
|
|
||||||
public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
|
||||||
{
|
|
||||||
private readonly TokenStorage _tokenStorage;
|
|
||||||
private readonly ApiClient _apiClient;
|
|
||||||
private readonly HttpClient _http;
|
|
||||||
private Timer? _refreshTimer;
|
|
||||||
private ClaimsPrincipal _currentUser = new(new ClaimsIdentity());
|
|
||||||
|
|
||||||
public AuthStateProvider(TokenStorage tokenStorage, ApiClient apiClient, HttpClient http)
|
|
||||||
{
|
|
||||||
_tokenStorage = tokenStorage;
|
|
||||||
_apiClient = apiClient;
|
|
||||||
_http = http;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
|
||||||
{
|
|
||||||
var (token, refreshToken) = await _tokenStorage.GetTokensAsync();
|
|
||||||
if (string.IsNullOrEmpty(token))
|
|
||||||
return new AuthenticationState(_currentUser);
|
|
||||||
|
|
||||||
var principal = ParseToken(token);
|
|
||||||
if (principal == null)
|
|
||||||
return new AuthenticationState(_currentUser);
|
|
||||||
|
|
||||||
_currentUser = principal;
|
|
||||||
_http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
||||||
ScheduleTokenRefresh(token, refreshToken);
|
|
||||||
return new AuthenticationState(principal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task MarkUserAsAuthenticated(string token, string refreshToken)
|
|
||||||
{
|
|
||||||
await _tokenStorage.SetTokensAsync(token, refreshToken);
|
|
||||||
var principal = ParseToken(token);
|
|
||||||
_currentUser = principal ?? new ClaimsPrincipal(new ClaimsIdentity());
|
|
||||||
_http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
||||||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task MarkUserAsLoggedOut()
|
|
||||||
{
|
|
||||||
await _tokenStorage.ClearTokensAsync();
|
|
||||||
_currentUser = new ClaimsPrincipal(new ClaimsIdentity());
|
|
||||||
_http.DefaultRequestHeaders.Authorization = null;
|
|
||||||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClaimsPrincipal? ParseToken(string token)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var handler = new JwtSecurityTokenHandler();
|
|
||||||
var jwt = handler.ReadJwtToken(token);
|
|
||||||
var identity = new ClaimsIdentity(jwt.Claims, "jwt");
|
|
||||||
return new ClaimsPrincipal(identity);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ScheduleTokenRefresh(string token, string? refreshToken)
|
|
||||||
{
|
|
||||||
var handler = new JwtSecurityTokenHandler();
|
|
||||||
var jwt = handler.ReadJwtToken(token);
|
|
||||||
var expiresAt = jwt.ValidTo;
|
|
||||||
var timeToExpiry = expiresAt - DateTime.UtcNow;
|
|
||||||
var refreshTime = timeToExpiry - TimeSpan.FromMinutes(5);
|
|
||||||
|
|
||||||
if (refreshTime > TimeSpan.Zero && !string.IsNullOrEmpty(refreshToken))
|
|
||||||
{
|
|
||||||
_refreshTimer?.Dispose();
|
|
||||||
_refreshTimer = new Timer(async _ =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var newToken = await _apiClient.RefreshTokenAsync(refreshToken);
|
|
||||||
if (newToken != null)
|
|
||||||
await MarkUserAsAuthenticated(newToken.Token, newToken.RefreshToken);
|
|
||||||
else
|
|
||||||
await MarkUserAsLoggedOut();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
await MarkUserAsLoggedOut();
|
|
||||||
}
|
|
||||||
}, null, (int)refreshTime.TotalMilliseconds, Timeout.Infinite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() => _refreshTimer?.Dispose();
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
using Microsoft.JSInterop;
|
|
||||||
|
|
||||||
namespace PlaylistShared.PWA.Services;
|
|
||||||
|
|
||||||
public class TokenStorage
|
|
||||||
{
|
|
||||||
private readonly IJSRuntime _js;
|
|
||||||
private const string TokenKey = "jwt_token";
|
|
||||||
private const string RefreshTokenKey = "refresh_token";
|
|
||||||
|
|
||||||
public TokenStorage(IJSRuntime js) => _js = js;
|
|
||||||
|
|
||||||
public async Task SetTokensAsync(string token, string refreshToken)
|
|
||||||
{
|
|
||||||
await _js.InvokeVoidAsync("localStorage.setItem", TokenKey, token);
|
|
||||||
await _js.InvokeVoidAsync("localStorage.setItem", RefreshTokenKey, refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<(string? token, string? refreshToken)> GetTokensAsync()
|
|
||||||
{
|
|
||||||
var token = await _js.InvokeAsync<string>("localStorage.getItem", TokenKey);
|
|
||||||
var refreshToken = await _js.InvokeAsync<string>("localStorage.getItem", RefreshTokenKey);
|
|
||||||
return (token, refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ClearTokensAsync()
|
|
||||||
{
|
|
||||||
await _js.InvokeVoidAsync("localStorage.removeItem", TokenKey);
|
|
||||||
await _js.InvokeVoidAsync("localStorage.removeItem", RefreshTokenKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
@using System.Net.Http
|
|
||||||
@using System.Net.Http.Json
|
|
||||||
@using Microsoft.AspNetCore.Components.Authorization
|
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
|
||||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
|
||||||
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
|
||||||
@using Microsoft.JSInterop
|
|
||||||
@using PlaylistShared.PWA
|
|
||||||
@using PlaylistShared.PWA.Layout
|
|
||||||
@using PlaylistShared.PWA.Services
|
|
||||||
@using MudBlazor
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"Local": {
|
|
||||||
"Authority": "https://login.microsoftonline.com/",
|
|
||||||
"ClientId": "33333333-3333-3333-33333333333333333"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"Local": {
|
|
||||||
"Authority": "https://login.microsoftonline.com/",
|
|
||||||
"ClientId": "33333333-3333-3333-33333333333333333"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
html, body {
|
|
||||||
font-family: 'Roboto', Helvetica, Arial, sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
#blazor-error-ui {
|
|
||||||
color-scheme: light;
|
|
||||||
background: rgba(30, 30, 45, 0.95);
|
|
||||||
color: #f5f5f7;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
||||||
border-radius: 12px;
|
|
||||||
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
|
|
||||||
backdrop-filter: blur(6px);
|
|
||||||
box-sizing: border-box;
|
|
||||||
display: none;
|
|
||||||
left: 50%;
|
|
||||||
right: auto;
|
|
||||||
bottom: 1rem;
|
|
||||||
width: min(52rem, calc(100vw - 2rem));
|
|
||||||
transform: translateX(-50%);
|
|
||||||
padding: 0.85rem 4rem 0.85rem 1rem;
|
|
||||||
position: fixed;
|
|
||||||
z-index: 2000;
|
|
||||||
}
|
|
||||||
|
|
||||||
#blazor-error-ui .reload {
|
|
||||||
color: #594AE2;
|
|
||||||
font-weight: 600;
|
|
||||||
margin-left: 0.5rem;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#blazor-error-ui .reload:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
#blazor-error-ui .dismiss {
|
|
||||||
cursor: pointer;
|
|
||||||
position: absolute;
|
|
||||||
right: 1rem;
|
|
||||||
top: 0.55rem;
|
|
||||||
width: 1.75rem;
|
|
||||||
height: 1.75rem;
|
|
||||||
line-height: 1.65rem;
|
|
||||||
text-align: center;
|
|
||||||
border-radius: 999px;
|
|
||||||
color: #d7d7df;
|
|
||||||
background: rgba(255, 255, 255, 0.06);
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
#blazor-error-ui .dismiss:hover {
|
|
||||||
background: rgba(255, 255, 255, 0.12);
|
|
||||||
}
|
|
||||||
|
|
||||||
.blazor-error-boundary {
|
|
||||||
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
|
|
||||||
padding: 1rem 1rem 1rem 3.7rem;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.blazor-error-boundary::after {
|
|
||||||
content: "An error has occurred."
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-progress {
|
|
||||||
position: absolute;
|
|
||||||
display: block;
|
|
||||||
width: 8rem;
|
|
||||||
height: 8rem;
|
|
||||||
inset: 20vh 0 auto 0;
|
|
||||||
margin: 0 auto 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-progress circle {
|
|
||||||
fill: none;
|
|
||||||
stroke: #e0e0e0;
|
|
||||||
stroke-width: 0.6rem;
|
|
||||||
transform-origin: 50% 50%;
|
|
||||||
transform: rotate(-90deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-progress circle:last-child {
|
|
||||||
stroke: #594AE2;
|
|
||||||
stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
|
|
||||||
transition: stroke-dasharray 0.05s ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-progress-text {
|
|
||||||
position: absolute;
|
|
||||||
text-align: center;
|
|
||||||
font-weight: bold;
|
|
||||||
inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.loading-progress-text:after {
|
|
||||||
content: var(--blazor-load-percentage-text, "Loading");
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
color: #c02d76;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
|
|
||||||
color: var(--bs-secondary-color);
|
|
||||||
text-align: end;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
|
|
||||||
text-align: start;
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 23 KiB |
@@ -1,41 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>PlaylistShared.PWA</title>
|
|
||||||
<base href="/" />
|
|
||||||
<link rel="preload" id="webassembly" />
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet" />
|
|
||||||
<link rel="stylesheet" href="_content/MudBlazor/MudBlazor.min.css" />
|
|
||||||
<link rel="stylesheet" href="css/app.css" />
|
|
||||||
<link rel="icon" type="image/png" href="favicon.png" />
|
|
||||||
<link href="PlaylistShared.PWA.styles.css" rel="stylesheet" />
|
|
||||||
<link href="manifest.webmanifest" rel="manifest" />
|
|
||||||
<link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
|
|
||||||
<link rel="apple-touch-icon" sizes="192x192" href="icon-192.png" />
|
|
||||||
<script type="importmap"></script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="app">
|
|
||||||
<svg class="loading-progress">
|
|
||||||
<circle r="40%" cx="50%" cy="50%" />
|
|
||||||
<circle r="40%" cx="50%" cy="50%" />
|
|
||||||
</svg>
|
|
||||||
<div class="loading-progress-text"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="blazor-error-ui">
|
|
||||||
An unhandled error has occurred.
|
|
||||||
<a href="." class="reload">Reload</a>
|
|
||||||
<span class="dismiss">🗙</span>
|
|
||||||
</div>
|
|
||||||
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
|
|
||||||
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
|
||||||
<script src="_framework/blazor.webassembly#[.{fingerprint}].js"></script>
|
|
||||||
<script>navigator.serviceWorker.register('service-worker.js', { updateViaCache: 'none' });</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "PlaylistShared.PWA",
|
|
||||||
"short_name": "PlaylistShared.PWA",
|
|
||||||
"id": "./",
|
|
||||||
"start_url": "./",
|
|
||||||
"display": "standalone",
|
|
||||||
"background_color": "#ffffff",
|
|
||||||
"theme_color": "#03173d",
|
|
||||||
"prefer_related_applications": false,
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "icon-512.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "512x512"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "icon-192.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "192x192"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"date": "2022-01-06",
|
|
||||||
"temperatureC": 1,
|
|
||||||
"summary": "Freezing"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"date": "2022-01-07",
|
|
||||||
"temperatureC": 14,
|
|
||||||
"summary": "Bracing"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"date": "2022-01-08",
|
|
||||||
"temperatureC": -13,
|
|
||||||
"summary": "Freezing"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"date": "2022-01-09",
|
|
||||||
"temperatureC": -16,
|
|
||||||
"summary": "Balmy"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"date": "2022-01-10",
|
|
||||||
"temperatureC": -2,
|
|
||||||
"summary": "Chilly"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// In development, always fetch from the network and do not enable offline support.
|
|
||||||
// This is because caching would make development more difficult (changes would not
|
|
||||||
// be reflected on the first load after each change).
|
|
||||||
self.addEventListener('fetch', () => { });
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
// Caution! Be sure you understand the caveats before publishing an application with
|
|
||||||
// offline support. See https://aka.ms/blazor-offline-considerations
|
|
||||||
|
|
||||||
self.importScripts('./service-worker-assets.js');
|
|
||||||
self.addEventListener('install', event => event.waitUntil(onInstall(event)));
|
|
||||||
self.addEventListener('activate', event => event.waitUntil(onActivate(event)));
|
|
||||||
self.addEventListener('fetch', event => event.respondWith(onFetch(event)));
|
|
||||||
|
|
||||||
const cacheNamePrefix = 'offline-cache-';
|
|
||||||
const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`;
|
|
||||||
const offlineAssetsInclude = [ /\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/, /\.webmanifest$/ ];
|
|
||||||
const offlineAssetsExclude = [ /^service-worker\.js$/ ];
|
|
||||||
|
|
||||||
// Replace with your base path if you are hosting on a subfolder. Ensure there is a trailing '/'.
|
|
||||||
const base = "/";
|
|
||||||
const baseUrl = new URL(base, self.origin);
|
|
||||||
const manifestUrlList = self.assetsManifest.assets.map(asset => new URL(asset.url, baseUrl).href);
|
|
||||||
|
|
||||||
async function onInstall(event) {
|
|
||||||
console.info('Service worker: Install');
|
|
||||||
|
|
||||||
// Fetch and cache all matching items from the assets manifest
|
|
||||||
const assetsRequests = self.assetsManifest.assets
|
|
||||||
.filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url)))
|
|
||||||
.filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url)))
|
|
||||||
.map(asset => new Request(asset.url, { integrity: asset.hash, cache: 'no-cache' }));
|
|
||||||
await caches.open(cacheName).then(cache => cache.addAll(assetsRequests));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onActivate(event) {
|
|
||||||
console.info('Service worker: Activate');
|
|
||||||
|
|
||||||
// Delete unused caches
|
|
||||||
const cacheKeys = await caches.keys();
|
|
||||||
await Promise.all(cacheKeys
|
|
||||||
.filter(key => key.startsWith(cacheNamePrefix) && key !== cacheName)
|
|
||||||
.map(key => caches.delete(key)));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onFetch(event) {
|
|
||||||
let cachedResponse = null;
|
|
||||||
if (event.request.method === 'GET') {
|
|
||||||
// For all navigation requests, try to serve index.html from cache,
|
|
||||||
// unless that request is for an offline resource.
|
|
||||||
// If you need some URLs to be server-rendered, edit the following check to exclude those URLs
|
|
||||||
const shouldServeIndexHtml = event.request.mode === 'navigate'
|
|
||||||
&& !manifestUrlList.some(url => url === event.request.url);
|
|
||||||
|
|
||||||
const request = shouldServeIndexHtml ? 'index.html' : event.request;
|
|
||||||
const cache = await caches.open(cacheName);
|
|
||||||
cachedResponse = await cache.match(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachedResponse || fetch(event.request);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user