Compare commits
43 Commits
3e18537a0e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38af6174fa | ||
|
|
2fe20c804a | ||
|
|
3c83a83396 | ||
|
|
14fcd7dff9 | ||
|
|
ecb12a7d4a | ||
|
|
2cd80c8082 | ||
|
|
78808ea525 | ||
|
|
d6da8460cc | ||
|
|
362762a813 | ||
|
|
7c05940dbf | ||
|
|
b3f19045fa | ||
|
|
b1febfc9dc | ||
|
|
0f2755281e | ||
|
|
d17ed30175 | ||
|
|
0f9dd1a8d8 | ||
|
|
45b8a168a1 | ||
|
|
c32eee0954 | ||
|
|
e2e117a539 | ||
|
|
64cc0e68a1 | ||
|
|
d2df57ca6e | ||
|
|
832363df57 | ||
|
|
d1e3e23e93 | ||
|
|
1c32b2e997 | ||
|
|
f9bbd895c4 | ||
|
|
8a809c9e7d | ||
|
|
e0c6b4119c | ||
|
|
eb323e874f | ||
| 58f21da19c | |||
|
|
9c95e6b189 | ||
|
|
12241639dc | ||
|
|
4324b86512 | ||
|
|
6b399f7fb7 | ||
|
|
ab56c34646 | ||
|
|
07a52b12d6 | ||
|
|
bb50bcbf22 | ||
|
|
dec6bc4dd1 | ||
|
|
280c164626 | ||
|
|
5a8ae3d680 | ||
|
|
68d7c7fc12 | ||
|
|
974fb0f538 | ||
|
|
a634986ac0 | ||
|
|
41a9d27005 | ||
|
|
35140b71b7 |
@@ -2,9 +2,10 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Api.Services;
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.DTO;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace PlaylistShared.Api.Controllers;
|
||||
@@ -41,7 +42,7 @@ public class AudioController : ControllerBase
|
||||
public async Task<IActionResult> StreamTrack(string trackId, [FromQuery] string? access_token = null, [FromQuery] string? shared_id = null)
|
||||
{
|
||||
var user = await GetUserFromToken(access_token);
|
||||
if (user == null) user = await GetUserFromSharedPlaylistId(shared_id);
|
||||
if (user == null || user.YandexAccessToken is null) user = await GetUserFromSharedPlaylistId(shared_id);
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
var streamUrl = await _yandexService.GetTrackFileUrlAsync(user, trackId);
|
||||
@@ -77,7 +78,7 @@ public class AudioController : ControllerBase
|
||||
public async Task<ActionResult<ApiResponse<YandexTrack>>> GetTrackInfo(string trackId, [FromQuery] string? access_token = null, [FromQuery] string? shared_id = null)
|
||||
{
|
||||
var user = await GetUserFromToken(access_token);
|
||||
if (user == null) user = await GetUserFromSharedPlaylistId(shared_id);
|
||||
if (user == null || user.YandexAccessToken is null) user = await GetUserFromSharedPlaylistId(shared_id);
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
var track = await _yandexService.GetYTrackAsync(user, trackId);
|
||||
@@ -87,7 +88,13 @@ public class AudioController : ControllerBase
|
||||
{
|
||||
Title = track.Title,
|
||||
CoverUri = track.CoverUri,
|
||||
Artists = track.Artists.Select(t => t.Name).ToList(),
|
||||
Artists = track.Artists.Select(a => new YandexArtist
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
CoverUrl = a.Cover.GetUrl(),
|
||||
Description = a.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
DurationMs = track.DurationMs,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@ using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Api.Services;
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using PlaylistShared.Shared.Playlist;
|
||||
using PlaylistShared.Shared.SharedPlaylist;
|
||||
using YandexMusic;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
|
||||
namespace PlaylistShared.Api.Controllers;
|
||||
|
||||
@@ -20,39 +19,41 @@ public class PlaylistsController : ControllerBase
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly SharedPlaylistService _sharedService;
|
||||
private readonly YandexMusicService _yandexService;
|
||||
private readonly YandexApiService _yandexApiService;
|
||||
|
||||
public PlaylistsController(
|
||||
UserManager<ApplicationUser> userManager,
|
||||
SharedPlaylistService sharedService,
|
||||
YandexMusicService yandexService)
|
||||
YandexMusicService yandexService,
|
||||
YandexApiService yandexApiService)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_sharedService = sharedService;
|
||||
_yandexService = yandexService;
|
||||
_yandexApiService = yandexApiService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<ApiResponse<List<YandexPlaylistInfo>>>> GetMyPlaylists()
|
||||
public async Task<ActionResult<ApiResponse<List<YandexPlaylistShare>>>> GetMyPlaylists()
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
var decryptedToken = _yandexService.DecryptToken(user.YandexAccessToken);
|
||||
var decryptedToken = _yandexApiService.DecryptToken(user.YandexAccessToken);
|
||||
if (string.IsNullOrEmpty(decryptedToken))
|
||||
return BadRequest(ApiResponse<object>.Fail(new ErrorResponse { StatusCode = 400, Message = "Токен Яндекс.Музыки не установлен или недействителен" }));
|
||||
|
||||
var yandexClient = new YandexMusicClient();
|
||||
var authSuccess = await yandexClient.Authorize(decryptedToken);
|
||||
var authSuccess = await _yandexApiService.AuthAsync(decryptedToken);
|
||||
if (!authSuccess)
|
||||
return BadRequest(ApiResponse<object>.Fail(new ErrorResponse { StatusCode = 400, Message = "Не удалось авторизоваться в Яндекс.Музыке. Проверьте токен." }));
|
||||
|
||||
var favorites = await yandexClient.GetFavoritesAsync();
|
||||
var ownPlaylists = favorites.Where(p => p.Owner.Uid == yandexClient.Account.Uid).ToList();
|
||||
var favorites = await _yandexApiService.Client.Api.Playlist.FavoritesAsync();
|
||||
var ownPlaylists = favorites.Where(p => p.Owner.Uid == _yandexApiService.Client.Account.Uid).ToList();
|
||||
|
||||
var sharedPlaylists = await _sharedService.GetAllByUserAsync(userId);
|
||||
|
||||
var result = ownPlaylists.Select(p => new YandexPlaylistInfo
|
||||
var result = ownPlaylists.Select(p => new YandexPlaylistShare
|
||||
{
|
||||
Kind = p.Kind,
|
||||
OwnerUid = p.Owner.Uid,
|
||||
@@ -63,7 +64,7 @@ public class PlaylistsController : ControllerBase
|
||||
ShareToken = sharedPlaylists.FirstOrDefault(s => s.YandexPlaylistKind == p.Kind && s.YandexPlaylistOwnerUid == p.Owner.Uid)?.ShareToken,
|
||||
}).ToList();
|
||||
|
||||
return Ok(ApiResponse<List<YandexPlaylistInfo>>.Ok(result));
|
||||
return Ok(ApiResponse<List<YandexPlaylistShare>>.Ok(result));
|
||||
}
|
||||
|
||||
[HttpPost("share")]
|
||||
@@ -74,11 +75,9 @@ public class PlaylistsController : ControllerBase
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
// Проверяем, что плейлист действительно принадлежит пользователю
|
||||
var yandexClient = new YandexMusicClient();
|
||||
await yandexClient.Authorize(_yandexService.DecryptToken(user.YandexAccessToken));
|
||||
var playlist = await yandexClient.GetPlaylistAsync(request.OwnerUid, request.Kind);
|
||||
if (playlist == null || playlist.Owner.Uid != yandexClient.Account.Uid)
|
||||
return BadRequest(ApiResponse<object>.Fail(new ErrorResponse { StatusCode = 400, Message = "Плейлист не принадлежит вам" }));
|
||||
var playlist = await _yandexService.GetPlaylistAsync(user, request.OwnerUid, request.Kind);
|
||||
if (playlist == null)
|
||||
return BadRequest(ApiResponse<object>.Fail(new ErrorResponse { StatusCode = 404, Message = "Плейлист не найден" }));
|
||||
|
||||
var dto = new SharePlaylistDto
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Api.Services;
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.DTO;
|
||||
using PlaylistShared.Shared.SharedPlaylist;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using YandexMusic.API.Models.Playlist;
|
||||
|
||||
[ApiController]
|
||||
@@ -168,13 +168,19 @@ public class SharedPlaylistController : ControllerBase
|
||||
{
|
||||
return new YandexPlaylistData
|
||||
{
|
||||
Title = playlist.Title ?? "",
|
||||
Description = playlist.Description ?? "",
|
||||
Tracks = playlist.Tracks?.Select(t => new YandexTrack
|
||||
Title = playlist.Title,
|
||||
Description = playlist.Description,
|
||||
Tracks = playlist.Tracks.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Track?.Id ?? "",
|
||||
Title = t.Track?.Title ?? "",
|
||||
Artists = t.Track?.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
TrackId = t.Track.Id,
|
||||
Title = t.Track.Title,
|
||||
Artists = t.Track.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
DurationMs = (int)(t.Track?.DurationMs ?? 0),
|
||||
CoverUri = t.Track?.CoverUri ?? ""
|
||||
}).ToList() ?? new List<YandexTrack>()
|
||||
|
||||
@@ -6,31 +6,32 @@ using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Api.Services;
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.Profile;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
|
||||
namespace PlaylistShared.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
[Authorize]
|
||||
public class YandexTokenController : ControllerBase
|
||||
public class YandexAccountController : ControllerBase
|
||||
{
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly YandexMusicService _yandexService;
|
||||
private readonly YandexAuthService _yandexService;
|
||||
|
||||
public YandexTokenController(UserManager<ApplicationUser> userManager, YandexMusicService yandexService)
|
||||
public YandexAccountController(UserManager<ApplicationUser> userManager, YandexAuthService yandexService)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_yandexService = yandexService;
|
||||
}
|
||||
|
||||
[HttpPost("set")]
|
||||
[HttpPost("token")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> SetToken([FromBody] SetYandexTokenRequest request)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
user.YandexAccessToken = _yandexService.EncryptToken(request.Token);
|
||||
user.YandexAccessToken = _yandexService.Service.EncryptToken(request.Token);
|
||||
// Не храним refresh-токен, так как пользователь вводит только access-токен
|
||||
user.YandexTokenExpiryUtc = DateTime.UtcNow.AddMonths(1); // условно, т.к. срок жизни токена неизвестен
|
||||
await _userManager.UpdateAsync(user);
|
||||
@@ -55,4 +56,35 @@ public class YandexTokenController : ControllerBase
|
||||
ExpiryUtc = user.YandexTokenExpiryUtc
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpGet("qr")]
|
||||
public async Task<ActionResult<ApiResponse<YandexAuthQr>>> GetQr()
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
var qr = await _yandexService.GetQrOrGenerate(user);
|
||||
|
||||
return Ok(ApiResponse<YandexAuthQr>.Ok(qr));
|
||||
}
|
||||
|
||||
[HttpGet("qr/{sessionId}")]
|
||||
public async Task<IActionResult> CheckQr(int sessionId)
|
||||
{
|
||||
var userId = User.GetUserId();
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null) return Unauthorized();
|
||||
|
||||
var checkResult = await _yandexService.CheckQrAsync(sessionId);
|
||||
if (checkResult == null) return NotFound();
|
||||
|
||||
if (checkResult.Status == Shared.Enums.YandexAuthQrStatus.Authorized)
|
||||
{
|
||||
await SetToken(new() { Token = _yandexService.Service.Client.AuthStorage.Token });
|
||||
|
||||
}
|
||||
|
||||
return Ok(ApiResponse<YandexAuthQrCheck>.Ok(checkResult));
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Api.Services;
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.DTO;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
|
||||
namespace PlaylistShared.Api.Controllers;
|
||||
|
||||
@@ -26,16 +26,16 @@ public class YandexSearchController : ControllerBase
|
||||
_sharedPlaylistService = sharedPlaylistService;
|
||||
}
|
||||
|
||||
[HttpGet("tracks")]
|
||||
public async Task<ActionResult<ApiResponse<List<YandexTrack>>>> SearchQuery(
|
||||
[FromQuery] string query,
|
||||
[FromQuery] int limit = 20,
|
||||
[FromQuery] TrackSearchType? searchType = TrackSearchType.All,
|
||||
[HttpGet("search")]
|
||||
public async Task<ActionResult<ApiResponse<YandexSearchResult>>> SearchQuery(
|
||||
[FromQuery] string query = "",
|
||||
[FromQuery] int limit = 40,
|
||||
[FromQuery] TrackSearchType searchType = TrackSearchType.All,
|
||||
[FromQuery] bool byId = false,
|
||||
[FromQuery] string? shared_id = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
return BadRequest(ApiResponse<List<YandexTrack>>.Fail(new ErrorResponse
|
||||
if (string.IsNullOrWhiteSpace(query) && searchType != TrackSearchType.MyPlaylists)
|
||||
return BadRequest(ApiResponse<YandexSearchResult>.Fail(new ErrorResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = "Поисковый запрос не может быть пустым."
|
||||
@@ -46,8 +46,10 @@ public class YandexSearchController : ControllerBase
|
||||
if (userId.HasValue)
|
||||
user = await _userManager.FindByIdAsync(userId.Value.ToString());
|
||||
|
||||
var byShareId = false;
|
||||
|
||||
// Если нет пользователя или у него нет токена, пробуем через shared_id
|
||||
if (user == null || string.IsNullOrEmpty(_yandexService.DecryptToken(user.YandexAccessToken)))
|
||||
if (user == null || string.IsNullOrEmpty(user.YandexAccessToken))
|
||||
{
|
||||
if (string.IsNullOrEmpty(shared_id))
|
||||
return Unauthorized("Не установлен яндекс токен.");
|
||||
@@ -61,27 +63,37 @@ public class YandexSearchController : ControllerBase
|
||||
var owner = await _userManager.FindByIdAsync(playlist.CreatorUserId.ToString());
|
||||
if (owner == null) return StatusCode(500, "Не удалось найти владельца плейлиста.");
|
||||
user = owner;
|
||||
|
||||
byShareId = true;
|
||||
}
|
||||
|
||||
var decryptedToken = _yandexService.DecryptToken(user.YandexAccessToken);
|
||||
if (string.IsNullOrEmpty(decryptedToken))
|
||||
return BadRequest(ApiResponse<List<YandexTrack>>.Fail(new ErrorResponse
|
||||
if (string.IsNullOrEmpty(user.YandexAccessToken))
|
||||
return BadRequest(ApiResponse<YandexSearchResult>.Fail(new ErrorResponse
|
||||
{
|
||||
StatusCode = 400,
|
||||
Message = "Токен Яндекс.Музыки не установлен или недействителен."
|
||||
}));
|
||||
|
||||
List<YandexTrack>? results = null;
|
||||
YandexSearchResult? results = null;
|
||||
|
||||
if (byId)
|
||||
{
|
||||
results = await _yandexService.SearchTracksByIdAsync(user, query, searchType.Value, limit);
|
||||
results = await _yandexService.SearchTracksByIdAsync(user, query, searchType);
|
||||
}
|
||||
else if (searchType == TrackSearchType.MyPlaylists)
|
||||
{
|
||||
if (byShareId)
|
||||
{
|
||||
return Unauthorized("Необходимо подключение профиля к яндекс музыке.");
|
||||
}
|
||||
|
||||
results = await _yandexService.SearchMyPlaylists(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
results = await _yandexService.SearchTracksAsync(user, query, searchType, limit);
|
||||
results = await _yandexService.SearchAsync(user, query, searchType, limit);
|
||||
}
|
||||
|
||||
return Ok(ApiResponse<List<YandexTrack>>.Ok(results));
|
||||
return Ok(ApiResponse<YandexSearchResult>.Ok(results));
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityR
|
||||
public DbSet<TrackAdditionLog> TrackAdditionLogs => Set<TrackAdditionLog>();
|
||||
public DbSet<TrackRemovalLog> TrackRemovalLogs => Set<TrackRemovalLog>();
|
||||
public DbSet<UserSession> UserSessions => Set<UserSession>();
|
||||
public DbSet<YandexAuthSession> YandexAuthSessions => Set<YandexAuthSession>();
|
||||
public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
@@ -102,5 +103,42 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityR
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
entity.Property(e => e.AddedAtUtc).IsRequired();
|
||||
});
|
||||
|
||||
|
||||
builder.Entity<YandexAuthSession>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id);
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
entity.HasOne(e => e.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(e => e.UserId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
entity.Property(e => e.QrCodeUrl)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
entity.Property(e => e.SerializedCookies)
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
entity.Property(e => e.ConfirmedAt)
|
||||
.IsRequired(false);
|
||||
entity.Property(e => e.IsConfirmed)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
entity.Property(e => e.TrackId)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired(false);
|
||||
entity.Property(e => e.CsfrToken)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired(false);
|
||||
entity.Property(e => e.HeaderCsfrToken)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired(false);
|
||||
entity.Property(e => e.HeaderProcessId)
|
||||
.HasMaxLength(200)
|
||||
.IsRequired(false);
|
||||
entity.HasIndex(e => e.UserId)
|
||||
.HasDatabaseName("IX_YandexAuthSessions_UserId");
|
||||
});
|
||||
}
|
||||
}
|
||||
668
PlaylistShared.Api/Data/Migrations/20260419180136_AddYandexAuthSessions.Designer.cs
generated
Normal file
668
PlaylistShared.Api/Data/Migrations/20260419180136_AddYandexAuthSessions.Designer.cs
generated
Normal file
@@ -0,0 +1,668 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using PlaylistShared.Api.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlaylistShared.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20260419180136_AddYandexAuthSessions")]
|
||||
partial class AddYandexAuthSessions
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FriendlyName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Xml")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("DataProtectionKeys");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("RoleNameIndex")
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetRoleClaims", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserClaims", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderKey")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderDisplayName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserLogins", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("AspNetUserTokens", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.ApplicationUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpiryUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("YandexAccessToken")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("YandexId")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("YandexRefreshToken")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("YandexTokenExpiryUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasDatabaseName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("UserNameIndex")
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.FavoritePlaylist", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("SharedPlaylistId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("AddedAtUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("UserId", "SharedPlaylistId");
|
||||
|
||||
b.HasIndex("SharedPlaylistId");
|
||||
|
||||
b.ToTable("FavoritePlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.SharedPlaylist", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int>("AddPermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("CoverUrl")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid>("CreatorUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PlayPermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RemovePermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShareToken")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("nvarchar(255)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ViewPermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("YandexPlaylistKind")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("YandexPlaylistOwnerUid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("YandexPlaylistUuid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatorUserId");
|
||||
|
||||
b.HasIndex("ShareToken")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("SharedPlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.TrackAdditionLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("AddedAtUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("AddedByUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("SessionId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(449)");
|
||||
|
||||
b.Property<Guid>("SharedPlaylistId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AddedByUserId");
|
||||
|
||||
b.HasIndex("SessionId");
|
||||
|
||||
b.HasIndex("SharedPlaylistId", "TrackId");
|
||||
|
||||
b.ToTable("TrackAdditionLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.UserSession", b =>
|
||||
{
|
||||
b.Property<string>("SessionId")
|
||||
.HasMaxLength(449)
|
||||
.HasColumnType("nvarchar(449)");
|
||||
|
||||
b.Property<Guid?>("AssociatedUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("ClientIpAddress")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("FirstSeenUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("LastSeenUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("UserAgent")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("SessionId");
|
||||
|
||||
b.HasIndex("AssociatedUserId");
|
||||
|
||||
b.ToTable("UserSessions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.YandexAuthSession", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("ConfirmedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("CsfrToken")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<bool>("IsConfirmed")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bit")
|
||||
.HasDefaultValue(false);
|
||||
|
||||
b.Property<string>("QrCodeUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("SerializedCookies")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<Guid?>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("IX_YandexAuthSessions_UserId");
|
||||
|
||||
b.ToTable("YandexAuthSessions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TrackRemovalLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("RemovedAtUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("RemovedByUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("SessionId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(449)");
|
||||
|
||||
b.Property<Guid>("SharedPlaylistId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RemovedByUserId");
|
||||
|
||||
b.HasIndex("SessionId");
|
||||
|
||||
b.HasIndex("SharedPlaylistId", "TrackId");
|
||||
|
||||
b.ToTable("TrackRemovalLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.FavoritePlaylist", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.SharedPlaylist", "SharedPlaylist")
|
||||
.WithMany()
|
||||
.HasForeignKey("SharedPlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany("FavoritePlaylists")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("SharedPlaylist");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.SharedPlaylist", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "Creator")
|
||||
.WithMany("OwnedPlaylists")
|
||||
.HasForeignKey("CreatorUserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Creator");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.TrackAdditionLog", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "AddedByUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("AddedByUserId")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.UserSession", "Session")
|
||||
.WithMany("TrackAdditionLogs")
|
||||
.HasForeignKey("SessionId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.SharedPlaylist", "SharedPlaylist")
|
||||
.WithMany("TrackAdditionLogs")
|
||||
.HasForeignKey("SharedPlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AddedByUser");
|
||||
|
||||
b.Navigation("Session");
|
||||
|
||||
b.Navigation("SharedPlaylist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.UserSession", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("AssociatedUserId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.YandexAuthSession", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TrackRemovalLog", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "RemovedByUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("RemovedByUserId")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.UserSession", "Session")
|
||||
.WithMany("TrackRemovalLogs")
|
||||
.HasForeignKey("SessionId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.SharedPlaylist", "SharedPlaylist")
|
||||
.WithMany()
|
||||
.HasForeignKey("SharedPlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("RemovedByUser");
|
||||
|
||||
b.Navigation("Session");
|
||||
|
||||
b.Navigation("SharedPlaylist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.ApplicationUser", b =>
|
||||
{
|
||||
b.Navigation("FavoritePlaylists");
|
||||
|
||||
b.Navigation("OwnedPlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.SharedPlaylist", b =>
|
||||
{
|
||||
b.Navigation("TrackAdditionLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.UserSession", b =>
|
||||
{
|
||||
b.Navigation("TrackAdditionLogs");
|
||||
|
||||
b.Navigation("TrackRemovalLogs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlaylistShared.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddYandexAuthSessions : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "YandexAuthSessions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
QrCodeUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
SerializedCookies = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ConfirmedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
IsConfirmed = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
|
||||
TrackId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||
CsfrToken = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_YandexAuthSessions", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_YandexAuthSessions_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_YandexAuthSessions_UserId",
|
||||
table: "YandexAuthSessions",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "YandexAuthSessions");
|
||||
}
|
||||
}
|
||||
}
|
||||
676
PlaylistShared.Api/Data/Migrations/20260420123450_AddYandexAuthSessions_Header.Designer.cs
generated
Normal file
676
PlaylistShared.Api/Data/Migrations/20260420123450_AddYandexAuthSessions_Header.Designer.cs
generated
Normal file
@@ -0,0 +1,676 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using PlaylistShared.Api.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlaylistShared.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20260420123450_AddYandexAuthSessions_Header")]
|
||||
partial class AddYandexAuthSessions_Header
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FriendlyName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Xml")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("DataProtectionKeys");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("RoleNameIndex")
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetRoleClaims", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserClaims", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderKey")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderDisplayName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserLogins", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("AspNetUserTokens", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.ApplicationUser", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("RefreshTokenExpiryUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("YandexAccessToken")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("YandexId")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("YandexRefreshToken")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("YandexTokenExpiryUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasDatabaseName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("UserNameIndex")
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.FavoritePlaylist", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("SharedPlaylistId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("AddedAtUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("UserId", "SharedPlaylistId");
|
||||
|
||||
b.HasIndex("SharedPlaylistId");
|
||||
|
||||
b.ToTable("FavoritePlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.SharedPlaylist", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int>("AddPermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("CoverUrl")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid>("CreatorUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("PlayPermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("RemovePermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShareToken")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("nvarchar(255)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ViewPermission")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("YandexPlaylistKind")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("YandexPlaylistOwnerUid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("YandexPlaylistUuid")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreatorUserId");
|
||||
|
||||
b.HasIndex("ShareToken")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("SharedPlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.TrackAdditionLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("AddedAtUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("AddedByUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("SessionId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(449)");
|
||||
|
||||
b.Property<Guid>("SharedPlaylistId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AddedByUserId");
|
||||
|
||||
b.HasIndex("SessionId");
|
||||
|
||||
b.HasIndex("SharedPlaylistId", "TrackId");
|
||||
|
||||
b.ToTable("TrackAdditionLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.UserSession", b =>
|
||||
{
|
||||
b.Property<string>("SessionId")
|
||||
.HasMaxLength(449)
|
||||
.HasColumnType("nvarchar(449)");
|
||||
|
||||
b.Property<Guid?>("AssociatedUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("ClientIpAddress")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("FirstSeenUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("LastSeenUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("UserAgent")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("SessionId");
|
||||
|
||||
b.HasIndex("AssociatedUserId");
|
||||
|
||||
b.ToTable("UserSessions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.YandexAuthSession", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("ConfirmedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("CsfrToken")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("HeaderCsfrToken")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("HeaderProcessId")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<bool>("IsConfirmed")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bit")
|
||||
.HasDefaultValue(false);
|
||||
|
||||
b.Property<string>("QrCodeUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("SerializedCookies")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<Guid?>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("IX_YandexAuthSessions_UserId");
|
||||
|
||||
b.ToTable("YandexAuthSessions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TrackRemovalLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("RemovedAtUtc")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("RemovedByUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("SessionId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(449)");
|
||||
|
||||
b.Property<Guid>("SharedPlaylistId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RemovedByUserId");
|
||||
|
||||
b.HasIndex("SessionId");
|
||||
|
||||
b.HasIndex("SharedPlaylistId", "TrackId");
|
||||
|
||||
b.ToTable("TrackRemovalLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<System.Guid>", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.FavoritePlaylist", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.SharedPlaylist", "SharedPlaylist")
|
||||
.WithMany()
|
||||
.HasForeignKey("SharedPlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany("FavoritePlaylists")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("SharedPlaylist");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.SharedPlaylist", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "Creator")
|
||||
.WithMany("OwnedPlaylists")
|
||||
.HasForeignKey("CreatorUserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Creator");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.TrackAdditionLog", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "AddedByUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("AddedByUserId")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.UserSession", "Session")
|
||||
.WithMany("TrackAdditionLogs")
|
||||
.HasForeignKey("SessionId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.SharedPlaylist", "SharedPlaylist")
|
||||
.WithMany("TrackAdditionLogs")
|
||||
.HasForeignKey("SharedPlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("AddedByUser");
|
||||
|
||||
b.Navigation("Session");
|
||||
|
||||
b.Navigation("SharedPlaylist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.UserSession", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("AssociatedUserId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.YandexAuthSession", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TrackRemovalLog", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "RemovedByUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("RemovedByUserId")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.UserSession", "Session")
|
||||
.WithMany("TrackRemovalLogs")
|
||||
.HasForeignKey("SessionId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlaylistShared.Api.Entities.SharedPlaylist", "SharedPlaylist")
|
||||
.WithMany()
|
||||
.HasForeignKey("SharedPlaylistId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("RemovedByUser");
|
||||
|
||||
b.Navigation("Session");
|
||||
|
||||
b.Navigation("SharedPlaylist");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.ApplicationUser", b =>
|
||||
{
|
||||
b.Navigation("FavoritePlaylists");
|
||||
|
||||
b.Navigation("OwnedPlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.SharedPlaylist", b =>
|
||||
{
|
||||
b.Navigation("TrackAdditionLogs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.UserSession", b =>
|
||||
{
|
||||
b.Navigation("TrackAdditionLogs");
|
||||
|
||||
b.Navigation("TrackRemovalLogs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlaylistShared.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddYandexAuthSessions_Header : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "HeaderCsfrToken",
|
||||
table: "YandexAuthSessions",
|
||||
type: "nvarchar(200)",
|
||||
maxLength: 200,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "HeaderProcessId",
|
||||
table: "YandexAuthSessions",
|
||||
type: "nvarchar(200)",
|
||||
maxLength: 200,
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HeaderCsfrToken",
|
||||
table: "YandexAuthSessions");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HeaderProcessId",
|
||||
table: "YandexAuthSessions");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace PlaylistShared.Api.Data.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.5")
|
||||
.HasAnnotation("ProductVersion", "10.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
@@ -407,6 +407,61 @@ namespace PlaylistShared.Api.Data.Migrations
|
||||
b.ToTable("UserSessions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.YandexAuthSession", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("ConfirmedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("CsfrToken")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("HeaderCsfrToken")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("HeaderProcessId")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<bool>("IsConfirmed")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bit")
|
||||
.HasDefaultValue(false);
|
||||
|
||||
b.Property<string>("QrCodeUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("SerializedCookies")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("TrackId")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<Guid?>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("IX_YandexAuthSessions_UserId");
|
||||
|
||||
b.ToTable("YandexAuthSessions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TrackRemovalLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -558,6 +613,16 @@ namespace PlaylistShared.Api.Data.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlaylistShared.Api.Entities.YandexAuthSession", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TrackRemovalLog", b =>
|
||||
{
|
||||
b.HasOne("PlaylistShared.Api.Entities.ApplicationUser", "RemovedByUser")
|
||||
|
||||
@@ -12,4 +12,4 @@ public class UserSession
|
||||
public ApplicationUser? User { get; set; }
|
||||
public ICollection<TrackAdditionLog> TrackAdditionLogs { get; set; } = new List<TrackAdditionLog>();
|
||||
public ICollection<TrackRemovalLog> TrackRemovalLogs { get; set; } = new List<TrackRemovalLog>();
|
||||
}
|
||||
}
|
||||
|
||||
18
PlaylistShared.Api/Entities/YandexAuthSession.cs
Normal file
18
PlaylistShared.Api/Entities/YandexAuthSession.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace PlaylistShared.Api.Entities;
|
||||
|
||||
public class YandexAuthSession
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public string QrCodeUrl { get; set; }
|
||||
public string SerializedCookies { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime? ConfirmedAt { get; set; }
|
||||
public bool IsConfirmed { get; set; }
|
||||
public string? TrackId { get; set; }
|
||||
public string? CsfrToken { get; set; }
|
||||
public string? HeaderProcessId { get; set; }
|
||||
public string? HeaderCsfrToken { get; set; }
|
||||
|
||||
public ApplicationUser? User { get; set; }
|
||||
}
|
||||
@@ -4,14 +4,16 @@ namespace PlaylistShared.Api.Extensions;
|
||||
|
||||
public static class YCoverExtensions
|
||||
{
|
||||
public static string GetUrl(this YCover cover, string size = "200x200")
|
||||
public static string GetUrl(this YCover cover)
|
||||
{
|
||||
switch (cover)
|
||||
{
|
||||
case YCoverImage img when !string.IsNullOrEmpty(img.Uri):
|
||||
return $"https://{img.Uri.Replace("%%", size)}";
|
||||
return img.Uri;
|
||||
case YCoverPic pic when !string.IsNullOrEmpty(pic.Uri):
|
||||
return $"https://{pic.Uri.Replace("%%", size)}";
|
||||
return pic.Uri;
|
||||
case YCoverMosaic mosaic when mosaic.ItemsUri.Any():
|
||||
return mosaic.ItemsUri.First();
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
@@ -10,24 +10,24 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.7" />
|
||||
<PackageReference Include="AspNet.Security.OAuth.Yandex" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.6">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.7">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="10.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="10.1.7" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.7" />
|
||||
<PackageReference Include="YandexMusic" Version="0.0.7" />
|
||||
<PackageReference Include="YandexMusic" Version="0.0.16" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -92,14 +92,18 @@ public class Program
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddScoped<JwtService>();
|
||||
builder.Services.AddScoped<UserSessionService>();
|
||||
|
||||
builder.Services.AddDataProtection()
|
||||
.PersistKeysToDbContext<ApplicationDbContext>()
|
||||
.SetApplicationName("PlaylistShared.Api");
|
||||
|
||||
builder.Services.AddScoped<YandexApiService>();
|
||||
builder.Services.AddScoped<YandexMusicService>();
|
||||
builder.Services.AddScoped<YandexAuthService>();
|
||||
builder.Services.AddScoped<SharedPlaylistService>();
|
||||
builder.Services.AddScoped<TrackAdditionLogService>();
|
||||
builder.Services.AddScoped<TrackRemovalLogService>();
|
||||
builder.Services.AddScoped<FavoritesService>();
|
||||
builder.Services.AddDataProtection()
|
||||
.PersistKeysToDbContext<ApplicationDbContext>()
|
||||
.SetApplicationName("PlaylistShared.Api");
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using PlaylistShared.Api.Data;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Shared.Auth;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using PlaylistShared.Shared.Playlist;
|
||||
using PlaylistShared.Shared.SharedPlaylist;
|
||||
|
||||
namespace PlaylistShared.Api.Services;
|
||||
|
||||
128
PlaylistShared.Api/Services/Yandex/YandexApiService.cs
Normal file
128
PlaylistShared.Api/Services/Yandex/YandexApiService.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using System.Net;
|
||||
using YandexMusic;
|
||||
|
||||
namespace PlaylistShared.Api.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Сервис для работы с API Яндекс Музыки в ASP.NET Core.
|
||||
/// </summary>
|
||||
public class YandexApiService : IDisposable
|
||||
{
|
||||
private readonly IDataProtector _dataProtector;
|
||||
private readonly YandexMusicClient _client;
|
||||
private readonly CookieContainer _cookieContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Экземпляр клиента Яндекс Музыки.
|
||||
/// </summary>
|
||||
public YandexMusicClient Client => _client;
|
||||
|
||||
/// <summary>
|
||||
/// Контейнер кук, используемый клиентом.
|
||||
/// </summary>
|
||||
public CookieContainer CookieContainer => _cookieContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Создаёт сервис с автоматическим созданием HttpClient (рекомендуется).
|
||||
/// </summary>
|
||||
public YandexApiService(IDataProtectionProvider provider, IWebProxy? proxy = null, TimeSpan? timeout = null)
|
||||
{
|
||||
_dataProtector = provider.CreateProtector("YandexTokens");
|
||||
_cookieContainer = new();
|
||||
_client = new YandexMusicClient(_cookieContainer, proxy, timeout);
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool?> AuthAsync(ApplicationUser user)
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.YandexAccessToken))
|
||||
return null;
|
||||
|
||||
var decryptedToken = DecryptToken(user.YandexAccessToken);
|
||||
if (decryptedToken == null)
|
||||
return null;
|
||||
|
||||
return await AuthorizeAsync(decryptedToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Авторизуется с помощью OAuth-токена.
|
||||
/// </summary>
|
||||
public async Task<bool> AuthAsync(string token)
|
||||
{
|
||||
return await AuthorizeAsync(token);
|
||||
}
|
||||
|
||||
private async Task<bool> AuthorizeAsync(string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _client.Api.Auth.AuthorizeAsync(token);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Засшифровывает и возвращает токен для хранения в базе данных.
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
public string EncryptToken(string token) => _dataProtector.Protect(token);
|
||||
|
||||
/// <summary>
|
||||
/// Расшифровывает ключ из базы данных. Если токен повреждён или недействителен, возвращает null.
|
||||
/// </summary>
|
||||
/// <param name="encryptedToken"></param>
|
||||
/// <returns></returns>
|
||||
public string DecryptToken(string encryptedToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _dataProtector.Unprotect(encryptedToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Устанавливает куки из строки для указанного домена.
|
||||
/// </summary>
|
||||
public void SetCookies(string cookieString, string domain)
|
||||
{
|
||||
var uri = new Uri(domain.StartsWith("http") ? domain : $"https://{domain}");
|
||||
_cookieContainer.SetCookies(uri, cookieString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получает все куки для указанного домена в виде строки.
|
||||
/// </summary>
|
||||
public string GetCookies(string domain)
|
||||
{
|
||||
var uri = new Uri(domain.StartsWith("http") ? domain : $"https://{domain}");
|
||||
var cookies = _cookieContainer.GetCookies(uri);
|
||||
return string.Join("; ", cookies.Cast<Cookie>().Select(c => $"{c.Name}={c.Value}"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получает значение конкретной куки.
|
||||
/// </summary>
|
||||
public string? GetCookie(string domain, string cookieName)
|
||||
{
|
||||
var uri = new Uri(domain.StartsWith("http") ? domain : $"https://{domain}");
|
||||
var cookie = _cookieContainer.GetCookies(uri)[cookieName];
|
||||
return cookie?.Value;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_client.Dispose();
|
||||
}
|
||||
}
|
||||
152
PlaylistShared.Api/Services/Yandex/YandexAuthService.cs
Normal file
152
PlaylistShared.Api/Services/Yandex/YandexAuthService.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PlaylistShared.Api.Data;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using YandexMusic.API;
|
||||
|
||||
namespace PlaylistShared.Api.Services;
|
||||
|
||||
public class YandexAuthService
|
||||
{
|
||||
private readonly YandexApiService _apiService;
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
|
||||
public YandexApiService Service => _apiService;
|
||||
public YandexMusicApi Api => _apiService.Client.Api;
|
||||
|
||||
public YandexAuthService(YandexApiService apiService, ApplicationDbContext dbContext)
|
||||
{
|
||||
_apiService = apiService;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
internal async Task<YandexAuthQr> GetQrOrGenerate(ApplicationUser user)
|
||||
{
|
||||
var existingSession = _dbContext.YandexAuthSessions
|
||||
.Where(s => s.UserId == user.Id && !s.IsConfirmed && s.CreatedAt > DateTime.UtcNow.AddMinutes(-5))
|
||||
.OrderByDescending(s => s.CreatedAt)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (existingSession != null)
|
||||
{
|
||||
return new YandexAuthQr
|
||||
{
|
||||
QrLink = existingSession.QrCodeUrl,
|
||||
SessionId = existingSession.Id.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
return await GenerateQrAsync(user);
|
||||
}
|
||||
|
||||
internal async Task<YandexAuthQr> GenerateQrAsync(ApplicationUser user)
|
||||
{
|
||||
var qr = await Api.Passport.GetAuthQRLinkAsync();
|
||||
var trackId = Service.Client.AuthStorage.AuthToken.TrackId;
|
||||
var csfrToken = Service.Client.AuthStorage.AuthToken.CsfrToken;
|
||||
var headerProcessUuid = Service.Client.AuthStorage.HeaderToken.ProcessUuid;
|
||||
var headerCsfrToken = Service.Client.AuthStorage.HeaderToken.CsfrToken;
|
||||
|
||||
if (string.IsNullOrEmpty(qr))
|
||||
throw new Exception("Не удалось получить QR-ссылку");
|
||||
|
||||
var cookiesJson = SerializeCookies(_apiService.CookieContainer);
|
||||
|
||||
var session = new YandexAuthSession
|
||||
{
|
||||
UserId = user.Id,
|
||||
QrCodeUrl = qr,
|
||||
SerializedCookies = cookiesJson,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
IsConfirmed = false,
|
||||
TrackId = trackId,
|
||||
CsfrToken = csfrToken,
|
||||
HeaderCsfrToken = headerCsfrToken,
|
||||
HeaderProcessId = headerProcessUuid,
|
||||
|
||||
};
|
||||
|
||||
_dbContext.YandexAuthSessions.Add(session);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
return new YandexAuthQr
|
||||
{
|
||||
QrLink = qr,
|
||||
SessionId = session.Id.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
internal async Task<YandexAuthQrCheck?> CheckQrAsync(int sessionId)
|
||||
{
|
||||
var session = await _dbContext.YandexAuthSessions.FindAsync(sessionId);
|
||||
if (session == null) return null;
|
||||
|
||||
RestoreCookies(Service.CookieContainer, session.SerializedCookies);
|
||||
if (Service.Client.AuthStorage.AuthToken is null)
|
||||
{
|
||||
Service.Client.AuthStorage.AuthToken = new();
|
||||
}
|
||||
|
||||
Service.Client.AuthStorage.AuthToken.CsfrToken = session?.CsfrToken ?? "";
|
||||
Service.Client.AuthStorage.AuthToken.TrackId = session?.TrackId ?? "";
|
||||
Service.Client.AuthStorage.HeaderToken.CsfrToken = session?.HeaderCsfrToken ?? "";
|
||||
Service.Client.AuthStorage.HeaderToken.ProcessUuid = session?.HeaderProcessId ?? "";
|
||||
|
||||
var status = await Api.Passport.CheckQRStatusAsync();
|
||||
|
||||
if (status?.State == "otp_auth_finished")
|
||||
{
|
||||
try
|
||||
{
|
||||
var auth = await Api.Passport.AuthorizeByQRAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new() { Status = Shared.Enums.YandexAuthQrStatus.Error, };
|
||||
}
|
||||
|
||||
_dbContext.YandexAuthSessions.Where(t => t.UserId == session.UserId).ExecuteDelete();
|
||||
_dbContext.SaveChanges();
|
||||
|
||||
return new() { Status = Shared.Enums.YandexAuthQrStatus.Authorized, };
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Status = Shared.Enums.YandexAuthQrStatus.Pending,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private string SerializeCookies(CookieContainer container)
|
||||
{
|
||||
var allCookies = new List<object>();
|
||||
|
||||
var cookies = container.GetAllCookies();
|
||||
foreach (Cookie cookie in cookies)
|
||||
{
|
||||
allCookies.Add(new { cookie.Name, cookie.Value, cookie.Domain, cookie.Path });
|
||||
}
|
||||
|
||||
return JsonSerializer.Serialize(allCookies);
|
||||
}
|
||||
|
||||
private void RestoreCookies(CookieContainer container, string serializedCookies)
|
||||
{
|
||||
var cookies = JsonSerializer.Deserialize<List<CookieData>>(serializedCookies);
|
||||
foreach (var c in cookies)
|
||||
{
|
||||
container.Add(new Cookie(c.Name, c.Value, c.Path, c.Domain));
|
||||
}
|
||||
}
|
||||
|
||||
private class CookieData
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Domain { get; set; }
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
||||
342
PlaylistShared.Api/Services/Yandex/YandexMusicService.cs
Normal file
342
PlaylistShared.Api/Services/Yandex/YandexMusicService.cs
Normal file
@@ -0,0 +1,342 @@
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Api.Extensions;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using YandexMusic.API;
|
||||
using YandexMusic.API.Models.Playlist;
|
||||
using YandexMusic.API.Models.Track;
|
||||
|
||||
namespace PlaylistShared.Api.Services;
|
||||
|
||||
public class YandexMusicService
|
||||
{
|
||||
private readonly YandexApiService _yandexApiService;
|
||||
private YandexMusicApi Api => _yandexApiService.Client.Api;
|
||||
private bool IsAuthorized => _yandexApiService.Client.IsAuthorized;
|
||||
|
||||
public YandexMusicService(YandexApiService yandexApiService)
|
||||
{
|
||||
_yandexApiService = yandexApiService;
|
||||
}
|
||||
|
||||
private async Task AuthorizeIfNot(ApplicationUser user)
|
||||
{
|
||||
if (!IsAuthorized)
|
||||
{
|
||||
var authResult = await _yandexApiService.AuthAsync(user);
|
||||
if (authResult == null || authResult == false)
|
||||
throw new Exception("Не удалось авторизоваться в Яндекс.Музыке. Проверьте токен.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> GetPlaylistAsync(ApplicationUser user, string ownerUid, string kind)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
return await Api.Playlist.GetAsync(ownerUid, kind);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> CreatePlaylistAsync(ApplicationUser user, string title)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
return await Api.Playlist.CreateAsync(title);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> AddTracksAsync(ApplicationUser user, string ownerUid, string kind, IEnumerable<string> trackIds)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
var playlist = await Api.Playlist.GetAsync(ownerUid, kind);
|
||||
if (playlist == null) return null;
|
||||
|
||||
var tracks = await Api.Track.GetAsync(trackIds);
|
||||
if (tracks == null || !tracks.Any()) return null;
|
||||
|
||||
var insertedTracks = tracks.Where(t => !playlist.Tracks.Any(p => p.Track.Id == t.Id)).ToArray();
|
||||
|
||||
return await playlist.InsertTracksAsync(insertedTracks);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> RemoveTracksAsync(ApplicationUser user, string ownerUid, string kind, IEnumerable<string> trackIds)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
var tracks = await Api.Track.GetAsync(trackIds);
|
||||
if (tracks == null || !tracks.Any()) return null;
|
||||
|
||||
var playlist = await Api.Playlist.GetAsync(ownerUid, kind);
|
||||
if (playlist == null) return null;
|
||||
|
||||
return await playlist.RemoveTracksAsync(tracks.ToArray());
|
||||
}
|
||||
|
||||
public async Task<string?> GetTrackFileUrlAsync(ApplicationUser user, string trackId)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
var track = await GetYTrackAsync(user, trackId);
|
||||
if (track == null) return null;
|
||||
|
||||
return await track.GetLinkAsync();
|
||||
}
|
||||
|
||||
public async Task<YTrack?> GetYTrackAsync(ApplicationUser user, string trackId)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
var track = await Api.Track.GetAsync(trackId);
|
||||
return track;
|
||||
}
|
||||
|
||||
public async Task<YandexSearchResult> SearchAsync(
|
||||
ApplicationUser user,
|
||||
string query,
|
||||
TrackSearchType? searchType = TrackSearchType.All,
|
||||
int limit = 20
|
||||
)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
var ySerchType = searchType switch
|
||||
{
|
||||
TrackSearchType.Artist => YandexMusic.API.Models.Common.YSearchType.Artist,
|
||||
TrackSearchType.Album => YandexMusic.API.Models.Common.YSearchType.Album,
|
||||
TrackSearchType.Playlist => YandexMusic.API.Models.Common.YSearchType.Playlist,
|
||||
TrackSearchType.Track => YandexMusic.API.Models.Common.YSearchType.Track,
|
||||
_ => YandexMusic.API.Models.Common.YSearchType.All
|
||||
};
|
||||
|
||||
var searchResult = await Api.Search.SearchAsync(query, ySerchType, page: 0, pageSize: limit);
|
||||
if (searchResult == null) return new YandexSearchResult();
|
||||
|
||||
return new YandexSearchResult
|
||||
{
|
||||
Tracks = searchResult.Tracks?.Results.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
CoverUri = t.CoverUri,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList(),
|
||||
|
||||
Playlists = searchResult.Playlists?.Results.Select(p => new YandexPlaylist
|
||||
{
|
||||
Uuid = p.PlaylistUuid,
|
||||
Kind = p.Kind,
|
||||
OwnerUid = p.Owner?.Uid ?? string.Empty,
|
||||
Title = p.Title,
|
||||
Description = p.Description,
|
||||
CoverUrl = string.IsNullOrEmpty(p.CoverUri) ? p.Cover.GetUrl() : p.CoverUri,
|
||||
TrackCount = p.TrackCount,
|
||||
}).ToList(),
|
||||
|
||||
Artists = searchResult.Artists?.Results.Select(a => new YandexArtist
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
CoverUrl = a.Cover.GetUrl(),
|
||||
Description = a.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
|
||||
Albums = searchResult.Albums?.Results.Select(a => new YandexAlbum
|
||||
{
|
||||
Id = a.Id,
|
||||
Title = a.Title,
|
||||
Artists = a.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
CoverUrl = string.IsNullOrEmpty(a.CoverUri) ? a.Cover.GetUrl() : a.CoverUri,
|
||||
Description = a.Description,
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<YandexSearchResult> SearchMyPlaylists(ApplicationUser user)
|
||||
{
|
||||
YandexSearchResult result = new();
|
||||
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
|
||||
var favoritesPlaylist = await Api.Playlist.FavoritesAsync();
|
||||
result.Playlists = favoritesPlaylist?.Select(t => new YandexPlaylist
|
||||
{
|
||||
Uuid = t.PlaylistUuid,
|
||||
Kind = t.Kind,
|
||||
OwnerUid = t.Owner?.Uid ?? string.Empty,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
TrackCount = t.TrackCount,
|
||||
}).ToList();
|
||||
|
||||
var personalPlaylists = await Api.Playlist.GetPersonalPlaylistsAsync();
|
||||
result.PersonalPlaylists = personalPlaylists?.Select(t => new YandexPlaylist
|
||||
{
|
||||
Uuid = t.PlaylistUuid,
|
||||
Kind = t.Kind,
|
||||
OwnerUid = t.Owner?.Uid ?? string.Empty,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
TrackCount = t.TrackCount,
|
||||
}).ToList();
|
||||
|
||||
var likedPlaylists = (await Api.Library.GetLikedPlaylistsAsync())?.Select(t => t.Playlist).ToList();
|
||||
result.LikedPlaylists = likedPlaylists?.Select(t => new YandexPlaylist
|
||||
{
|
||||
Uuid = t.PlaylistUuid,
|
||||
Kind = t.Kind,
|
||||
OwnerUid = t.Owner?.Uid ?? string.Empty,
|
||||
Title = t.Title,
|
||||
Description = t.Description,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
TrackCount = t.TrackCount,
|
||||
}).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<YandexSearchResult> SearchTracksByIdAsync(
|
||||
ApplicationUser user,
|
||||
string id,
|
||||
TrackSearchType searchType
|
||||
)
|
||||
{
|
||||
YandexSearchResult result = new();
|
||||
|
||||
await AuthorizeIfNot(user);
|
||||
|
||||
if (searchType == TrackSearchType.All)
|
||||
{
|
||||
throw new Exception("Для поиска по ID необходимо указать конкретный тип (трек, альбом, исполнитель или плейлист).");
|
||||
}
|
||||
|
||||
else if (searchType == TrackSearchType.Track)
|
||||
{
|
||||
var track = await Api.Track.GetAsync(id);
|
||||
|
||||
if (track != null)
|
||||
{
|
||||
result.Tracks = new List<YandexTrack>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
TrackId = track.Id,
|
||||
Title = track.Title,
|
||||
Artists = track.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
CoverUri = track.CoverUri ?? string.Empty,
|
||||
DurationMs = track.DurationMs,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
else if (searchType == TrackSearchType.Album)
|
||||
{
|
||||
var album = await Api.Album.GetAsync(id);
|
||||
|
||||
result.Tracks = album?.Volumes.SelectMany(v => v).Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
else if (searchType == TrackSearchType.Artist)
|
||||
{
|
||||
var artist = await Api.Artist.GetAsync(id);
|
||||
if (artist != null)
|
||||
{
|
||||
result.Albums = artist.Albums.Select(a => new YandexAlbum()
|
||||
{
|
||||
Id = a.Id,
|
||||
Title = a.Title,
|
||||
Artists = a.Artists.Select(t => new YandexArtist()
|
||||
{
|
||||
Id = t.Id,
|
||||
Name = t.Name,
|
||||
CoverUrl = t.Cover.GetUrl(),
|
||||
Description = t.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
CoverUrl = string.IsNullOrEmpty(a.CoverUri) ? a.Cover.GetUrl() : a.CoverUri,
|
||||
Description = a.Description,
|
||||
}).ToList();
|
||||
|
||||
result.Playlists = artist.Playlists.Select(p => new YandexPlaylist
|
||||
{
|
||||
Uuid = p.PlaylistUuid,
|
||||
Kind = p.Kind,
|
||||
OwnerUid = p.Owner?.Uid ?? string.Empty,
|
||||
Title = p.Title,
|
||||
Description = p.Description,
|
||||
CoverUrl = p.Cover.GetUrl(),
|
||||
TrackCount = p.TrackCount,
|
||||
}).ToList();
|
||||
|
||||
var allTraks = await artist.Artist.GetAllTracksAsync();
|
||||
result.Tracks = allTraks?.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists.Select(a => new YandexArtist()
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
CoverUrl = a.Cover.GetUrl(),
|
||||
Description = a.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
else if (searchType == TrackSearchType.Playlist)
|
||||
{
|
||||
var playlist = await Api.Playlist.GetAsync(id);
|
||||
|
||||
result.Tracks = playlist?.Tracks.Select(p => new YandexTrack
|
||||
{
|
||||
TrackId = p.Track.Id,
|
||||
CoverUri = p.Track.CoverUri,
|
||||
Artists = p.Track.Artists.Select(a => new YandexArtist
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
CoverUrl = a.Cover.GetUrl(),
|
||||
Description = a.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
Title = p.Track.Title,
|
||||
DurationMs = p.Track.DurationMs,
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using PlaylistShared.Api.Entities;
|
||||
using PlaylistShared.Shared.DTO;
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using YandexMusic;
|
||||
using YandexMusic.API.Extensions.API;
|
||||
using YandexMusic.API.Models.Playlist;
|
||||
using YandexMusic.API.Models.Track;
|
||||
|
||||
namespace PlaylistShared.Api.Services;
|
||||
|
||||
public class YandexMusicService
|
||||
{
|
||||
private readonly IDataProtector _dataProtector;
|
||||
|
||||
public YandexMusicService(IDataProtectionProvider provider)
|
||||
{
|
||||
_dataProtector = provider.CreateProtector("YandexTokens");
|
||||
}
|
||||
|
||||
private async Task<YandexMusicClient?> CreateClientAsync(ApplicationUser user)
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.YandexAccessToken))
|
||||
return null;
|
||||
|
||||
string decryptedToken;
|
||||
try
|
||||
{
|
||||
decryptedToken = _dataProtector.Unprotect(user.YandexAccessToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var client = new YandexMusicClient();
|
||||
var success = await client.Authorize(decryptedToken);
|
||||
return success ? client : null;
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> GetPlaylistAsync(ApplicationUser user, string ownerUid, string kind)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return null;
|
||||
return await client.GetPlaylistAsync(ownerUid, kind);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> CreatePlaylistAsync(ApplicationUser user, string title)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return null;
|
||||
return await client.CreatePlaylistAsync(title);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> AddTracksAsync(ApplicationUser user, string ownerUid, string kind, IEnumerable<string> trackIds)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return null;
|
||||
|
||||
var playlist = await client.GetPlaylistAsync(ownerUid, kind);
|
||||
if (playlist == null) return null;
|
||||
|
||||
var tracks = await client.GetTracksAsync(trackIds);
|
||||
if (tracks == null || !tracks.Any()) return null;
|
||||
|
||||
var insertedTracks = tracks.Where(t => !playlist.Tracks.Any(p => p.Track.Id == t.Id)).ToArray();
|
||||
|
||||
return await playlist.InsertTracksAsync(insertedTracks);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> RemoveTracksAsync(ApplicationUser user, string ownerUid, string kind, IEnumerable<string> trackIds)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return null;
|
||||
var tracks = await client.GetTracksAsync(trackIds);
|
||||
if (tracks == null || !tracks.Any()) return null;
|
||||
var playlist = await client.GetPlaylistAsync(ownerUid, kind);
|
||||
if (playlist == null) return null;
|
||||
return await playlist.RemoveTracksAsync(tracks.ToArray());
|
||||
}
|
||||
|
||||
public async Task<string?> GetTrackFileUrlAsync(ApplicationUser user, string trackId)
|
||||
{
|
||||
var track = await GetYTrackAsync(user, trackId);
|
||||
if (track == null) return null;
|
||||
return await track.GetLinkAsync();
|
||||
}
|
||||
|
||||
public async Task<YTrack?> GetYTrackAsync(ApplicationUser user, string trackId)
|
||||
{
|
||||
using var client = await CreateClientAsync(user);
|
||||
if (client == null) return null;
|
||||
var track = await client.GetTrackAsync(trackId);
|
||||
return track;
|
||||
}
|
||||
|
||||
public string EncryptToken(string token) => _dataProtector.Protect(token);
|
||||
|
||||
public string DecryptToken(string encryptedToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _dataProtector.Unprotect(encryptedToken);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<YandexTrack>> SearchTracksAsync(
|
||||
ApplicationUser user,
|
||||
string query,
|
||||
TrackSearchType? searchType = TrackSearchType.All,
|
||||
int limit = 20
|
||||
)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return new List<YandexTrack>();
|
||||
|
||||
var ySerchType = searchType switch
|
||||
{
|
||||
TrackSearchType.Artist => YandexMusic.API.Models.Common.YSearchType.Artist,
|
||||
TrackSearchType.Album => YandexMusic.API.Models.Common.YSearchType.Album,
|
||||
TrackSearchType.Playlist => YandexMusic.API.Models.Common.YSearchType.Playlist,
|
||||
TrackSearchType.Track => YandexMusic.API.Models.Common.YSearchType.Track,
|
||||
_ => YandexMusic.API.Models.Common.YSearchType.All
|
||||
};
|
||||
|
||||
var searchResult = await client.SearchAsync(query, ySerchType, page: 0, pageSize: limit);
|
||||
if (searchResult?.Tracks?.Results == null) return new List<YandexTrack>();
|
||||
|
||||
return searchResult.Tracks.Results.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<YandexTrack>> SearchTracksByIdAsync(
|
||||
ApplicationUser user,
|
||||
string id,
|
||||
TrackSearchType searchType,
|
||||
int limit = 20
|
||||
)
|
||||
{
|
||||
var client = await CreateClientAsync(user);
|
||||
if (client == null) return new List<YandexTrack>();
|
||||
|
||||
var ySerchType = searchType switch
|
||||
{
|
||||
TrackSearchType.Artist => YandexMusic.API.Models.Common.YSearchType.Artist,
|
||||
TrackSearchType.Album => YandexMusic.API.Models.Common.YSearchType.Album,
|
||||
TrackSearchType.Playlist => YandexMusic.API.Models.Common.YSearchType.Playlist,
|
||||
TrackSearchType.Track => YandexMusic.API.Models.Common.YSearchType.Track,
|
||||
_ => YandexMusic.API.Models.Common.YSearchType.All
|
||||
};
|
||||
|
||||
IEnumerable<YTrack> searchResult = searchType switch
|
||||
{
|
||||
TrackSearchType.Playlist => (await client.GetPlaylistAsync(id)).Tracks.Select(t => t.Track),
|
||||
TrackSearchType.Track => (await client.GetTracksAsync([id])),
|
||||
TrackSearchType.Album => (await client.GetAlbumAsync(id)).Volumes.SelectMany(t => t),
|
||||
TrackSearchType.Artist => (await client.GetArtistAsync(id)).Albums.SelectMany(t => t.Volumes.SelectMany(v => v)),
|
||||
_ => new List<YTrack>()
|
||||
};
|
||||
|
||||
if (searchType != TrackSearchType.Track)
|
||||
{
|
||||
searchResult = searchResult.Distinct();
|
||||
if (limit > 0) searchResult = searchResult.Take(limit);
|
||||
}
|
||||
|
||||
return searchResult.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Id,
|
||||
Title = t.Title,
|
||||
Artists = t.Artists?.Select(a => a.Name).ToList() ?? new List<string>(),
|
||||
CoverUri = t.CoverUri ?? string.Empty,
|
||||
DurationMs = t.DurationMs,
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<p role="alert">You are not authorized to access this resource.</p>
|
||||
<p role="alert">У вас нет прав доступа к этому ресурсу.</p>
|
||||
}
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Share"
|
||||
Color="Color.Default"
|
||||
OnClick="@TogglePopover"
|
||||
Title="Поделиться"
|
||||
Size="Size.Medium" />
|
||||
|
||||
<MudPopover Open="@_popoverOpen"
|
||||
|
||||
45
PlaylistShared.Pwa/Components/Common/ShareDialog.razor
Normal file
45
PlaylistShared.Pwa/Components/Common/ShareDialog.razor
Normal file
@@ -0,0 +1,45 @@
|
||||
@inject IJSRuntime JS
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Поделиться плейлистом</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudStack Spacing="2">
|
||||
<MudText>Скопируйте ссылку и отправьте её друзьям:</MudText>
|
||||
<MudTextField @bind-Value="ShareUrl"
|
||||
Variant="Variant.Outlined"
|
||||
ReadOnly="true"
|
||||
Margin="Margin.Dense"
|
||||
Class="mt-2" />
|
||||
</MudStack>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
OnClick="CopyToClipboard">
|
||||
Скопировать ссылку
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Text" Color="Color.Default"
|
||||
OnClick="Close">
|
||||
Закрыть
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = default!;
|
||||
|
||||
[Parameter]
|
||||
public string ShareUrl { get; set; } = string.Empty;
|
||||
|
||||
private async Task CopyToClipboard()
|
||||
{
|
||||
await JS.InvokeVoidAsync("navigator.clipboard.writeText", ShareUrl);
|
||||
Snackbar.Add("Ссылка скопирована в буфер обмена!", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
|
||||
private void Close() => MudDialog.Cancel();
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
@inject IAudioPlayerService AudioPlayerService
|
||||
|
||||
<MudItem @onmouseenter="HandleMouseEnter"
|
||||
@onmouseleave="HandleMouseLeave"
|
||||
style="position: relative; display: inline-block; cursor: pointer; border-radius: 4px; overflow: hidden;">
|
||||
|
||||
<MudImage Src="@CoverUrl.FormatCoverUrl(Width, Height)" Height="@Height" Width="@Width" Class="rounded" Style="display: block;" />
|
||||
<MudImage Src="@Track?.CoverUri.FormatCoverUrl(Width, Height)" Height="@Height" Width="@Width" Class="rounded" Style="display: block;" />
|
||||
|
||||
@if (CanPlay && (_isHovered || IsCurrentTrackPlaying))
|
||||
{
|
||||
<MudItem class="play-overlay"
|
||||
style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; border-radius: 4px;">
|
||||
style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; border-radius: 4px; transition: opacity 0.2s ease; cursor: pointer;">
|
||||
<MudIconButton Icon="@(IsCurrentTrackPlaying? Icons.Material.Filled.Pause : Icons.Material.Filled.PlayArrow)"
|
||||
Color="Color.Inherit"
|
||||
Size="Size.Large"
|
||||
@@ -20,8 +22,7 @@
|
||||
</MudItem>
|
||||
|
||||
@code {
|
||||
[Parameter] public string CoverUrl { get; set; } = string.Empty;
|
||||
[Parameter] public string TrackTitle { get; set; } = string.Empty;
|
||||
[Parameter] public YandexTrack? Track { get; set; } = null;
|
||||
[Parameter] public string TrackId { get; set; } = string.Empty;
|
||||
[Parameter] public int Height { get; set; } = 50;
|
||||
[Parameter] public int Width { get; set; } = 50;
|
||||
@@ -53,8 +54,7 @@
|
||||
await AudioPlayerService.LoadAndPlayAsync(
|
||||
trackId: TrackId,
|
||||
playlistShareToken: playlistShareToken,
|
||||
title: TrackTitle,
|
||||
coverUrl: CoverUrl);
|
||||
track: Track);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@using PlaylistShared.Pwa.Components.Common
|
||||
@using PlaylistShared.Pwa.Extensions
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
<!-- Обложка с фиксированной шириной -->
|
||||
<MudItem>
|
||||
<TrackCoverWithPlay CoverUrl="@Track.CoverUri"
|
||||
TrackId="@Track.TrackId"
|
||||
TrackTitle="@Track.Title"
|
||||
<TrackCoverWithPlay TrackId="@Track.TrackId"
|
||||
Track="@Track"
|
||||
PlaylistShareToken="@PlaylistShareToken"
|
||||
CanPlay="@CanPlay"
|
||||
Width="40" Height="40" />
|
||||
@@ -17,7 +17,7 @@
|
||||
<MudItem>
|
||||
<MudStack Spacing="0">
|
||||
<MudText Typo="Typo.body1" Color="Color.Secondary">@Track.Title</MudText>
|
||||
<MudText Typo="Typo.body2" >@string.Join(", ", Track.Artists)</MudText>
|
||||
<MudText Typo="Typo.body2" >@string.Join(", ", Track.Artists.Select(a => a.Name))</MudText>
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
|
||||
|
||||
23
PlaylistShared.Pwa/Components/Common/TrackItemSkeleton.razor
Normal file
23
PlaylistShared.Pwa/Components/Common/TrackItemSkeleton.razor
Normal file
@@ -0,0 +1,23 @@
|
||||
@using PlaylistShared.Pwa.Components.Common
|
||||
|
||||
<MudStack Class="py-2 px-0" Row AlignItems="AlignItems.Center">
|
||||
<!-- Обложка-скелет -->
|
||||
<MudItem>
|
||||
<MudSkeleton SkeletonType="SkeletonType.Rectangle" Width="40px" Height="40px" />
|
||||
</MudItem>
|
||||
|
||||
<!-- Информация о треке (две строки текста) -->
|
||||
<MudItem>
|
||||
<MudStack Spacing="0">
|
||||
<MudSkeleton SkeletonType="SkeletonType.Text" Width="180px" Class="my-0" />
|
||||
<MudSkeleton SkeletonType="SkeletonType.Text" Width="120px" Class="my-0" />
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
|
||||
<MudSpacer />
|
||||
|
||||
<!-- Длительность-скелет -->
|
||||
<MudItem>
|
||||
<MudSkeleton SkeletonType="SkeletonType.Text" Width="30px" />
|
||||
</MudItem>
|
||||
</MudStack>
|
||||
@@ -6,72 +6,128 @@
|
||||
@inject AuthenticationStateProvider AuthProvider
|
||||
@inject ISnackbar Snackbar
|
||||
@inject HttpClient Http
|
||||
@implements IDisposable
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<MudPaper Class="pa-4" Elevation="0" Width="100%" Style="background-color: rgba(0,0,0,0.05); border-radius: 8px;">
|
||||
<MudStack Row Gap="2" AlignItems="AlignItems.Center" Wrap="Wrap.Wrap">
|
||||
<!-- Информация о треке -->
|
||||
<MudStack Row Gap="2" AlignItems="AlignItems.Center">
|
||||
@if (!string.IsNullOrEmpty(_currentTrackCoverUrl))
|
||||
{
|
||||
<MudImage Src="@_currentTrackCoverUrl" Height="40" Width="40" Class="rounded" />
|
||||
}
|
||||
<MudText Typo="Typo.body1" Style="font-weight: 500;">@_currentTrackTitle</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudStack Spacing="1" Row AlignItems="AlignItems.Center" Wrap="Wrap.NoWrap">
|
||||
<!-- Кнопки управления -->
|
||||
<MudStack Row Gap="1">
|
||||
<MudIconButton Icon="@(_isPlaying? Icons.Material.Filled.Pause : Icons.Material.Filled.PlayArrow)" Size="Size.Medium" Color="Color.Primary" OnClick="TogglePlayPause" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Stop" Size="Size.Medium" Color="Color.Default" OnClick="Stop" />
|
||||
</MudStack>
|
||||
|
||||
<!-- Ползунок прогресса -->
|
||||
<MudItem Style="flex-grow: 1; min-width: 150px;">
|
||||
<MudSlider @bind-Value="_currentProgress" @bind-Value:event="oninput" Min="0" Max="100" Size="Size.Small" ValueChanged="@((double newValue) => SeekTo(newValue))" />
|
||||
<MudItem @onmouseenter="() => { _isPlayHovered = true; }"
|
||||
@onmouseleave="() => { _isPlayHovered = false; }"
|
||||
Class="relative d-inline-block rounded overflow-hidden cursor-pointer"
|
||||
Style="width: 50px; height: 50px;">
|
||||
|
||||
@if (!string.IsNullOrEmpty(AudioPlayerService.CurrentTrack?.CoverUri))
|
||||
{
|
||||
<MudImage Src="@AudioPlayerService.CurrentTrack.CoverUri.FormatCoverUrl(50, 50)" Height="50" Width="50" Class="rounded d-block" />
|
||||
}
|
||||
|
||||
<MudItem Class="absolute d-flex align-center justify-center rounded"
|
||||
Style="top: 0; left: 0; right: 0; bottom: 0; background: transparent;">
|
||||
<MudToggleIconButton Toggled="@AudioPlayerService.IsPlaying"
|
||||
Icon="@Icons.Material.Filled.PlayArrow"
|
||||
Color="@Color.Primary"
|
||||
Size="Size.Large"
|
||||
ToggledIcon="@Icons.Material.Filled.Pause"
|
||||
ToggledColor="@Color.Primary"
|
||||
ToggledChanged="OnPlayClick" />
|
||||
</MudItem>
|
||||
</MudItem>
|
||||
|
||||
<!-- Название и прогресс -->
|
||||
@if (AudioPlayerService.CurrentTrack != null)
|
||||
{
|
||||
<MudStack Spacing="0" AlignItems="AlignItems.Stretch" Class="d-flex flex-grow-1 relative overflow-hidden align-center rounded" Style="height: 50px;">
|
||||
<MudItem Class="absolute" style="top: 0; left: 0; right: 0; bottom: 0; z-index: 1;">
|
||||
<TrackProgress Value="@AudioPlayerService.CurrentTime"
|
||||
Min="0" Max="@AudioPlayerService.TotalTime"
|
||||
Height="50"
|
||||
BufferValue="@_bufferSecond"
|
||||
Color="Color.Primary"
|
||||
Icon=""
|
||||
Step="0.1"
|
||||
Opacity="0.3"
|
||||
Buffer
|
||||
ValueChanged="SeekTo" />
|
||||
</MudItem>
|
||||
<MudStack Spacing="0" Row AlignItems="AlignItems.Center" Class="px-3 relative pointer-events-none" Style="z-index: 2; width: 100%; height: 100%;">
|
||||
<MudStack AlignItems="AlignItems.Start" Spacing="0" Style="min-width: 0; width: 100%;">
|
||||
<MudText Typo="Typo.body2" Inline Color="Color.Default" Style="font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;">
|
||||
@AudioPlayerService.CurrentTrack.Title
|
||||
</MudText>
|
||||
|
||||
<MudText Typo="Typo.body2" Inline Color="Color.Default" Style="font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;">
|
||||
@string.Join(", ", AudioPlayerService.CurrentTrack.Artists.Select(a => a.Name))
|
||||
</MudText>
|
||||
</MudStack>
|
||||
|
||||
<!-- Время и громкость -->
|
||||
<MudStack Row Gap="2" AlignItems="AlignItems.Center">
|
||||
<MudText Typo="Typo.body2">@_currentTime / @_totalTime</MudText>
|
||||
<MudStack Row Gap="1" AlignItems="AlignItems.Center" Style="width: 120px;">
|
||||
<MudIconButton Icon="@(_currentVolume == 0 ? Icons.Material.Filled.VolumeOff : Icons.Material.Filled.VolumeUp)" Size="Size.Small" Color="Color.Default" OnClick="ToggleMute" />
|
||||
<MudSlider @bind-Value="_currentVolume" @bind-Value:event="oninput" Min="0" Max="100" Size="Size.Small" ValueChanged="@((double newValue) => ChangeVolume(newValue))" />
|
||||
<MudSpacer />
|
||||
|
||||
<MudText Typo="Typo.body2">
|
||||
@AudioPlayerService.CurrentTimeString
|
||||
</MudText>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSpacer />
|
||||
}
|
||||
|
||||
<MudHidden Breakpoint="Breakpoint.SmAndDown">
|
||||
<!-- Громкость -->
|
||||
<MudItem @onmouseenter="() => _volumeIsOpen = true"
|
||||
@onmouseleave="() => _volumeIsOpen = false"
|
||||
@onwheel="OnVolumeHandleWheel"
|
||||
Style="position: relative; display: flex; align-items: center;">
|
||||
|
||||
<MudIconButton Icon="@(AudioPlayerService.CurrentVolume == 0 ? Icons.Material.Filled.VolumeOff : Icons.Material.Filled.VolumeUp)"
|
||||
Size="Size.Small"
|
||||
Color="Color.Default"
|
||||
OnClick="ToggleMute" />
|
||||
|
||||
<MudPopover Open="@_volumeIsOpen"
|
||||
AnchorOrigin="Origin.TopCenter"
|
||||
TransformOrigin="Origin.BottomCenter"
|
||||
Fixed
|
||||
Class="pa-0 mt-n5"
|
||||
Style="height:120px; width: 10px; background-color: transparent !important; overflow: visible !important;">
|
||||
<MudProgressLinear Vertical Color="Color.Primary" Size="Size.Medium" Value="@AudioPlayerService.CurrentVolume" />
|
||||
|
||||
</MudPopover>
|
||||
</MudItem>
|
||||
</MudHidden>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
<audio id="@_audioId" style="display: none;"></audio>
|
||||
|
||||
@code {
|
||||
private const double _defaultVolume = 50;
|
||||
private const double _volumeDefault = 50;
|
||||
|
||||
// Генерируем уникальный ID для аудиоэлемента, чтобы избежать конфликтов при множественных экземплярах
|
||||
private string _audioId = $"audio_{Guid.NewGuid():N}";
|
||||
private IJSObjectReference? _audioModule;
|
||||
private IJSObjectReference? _audioElement;
|
||||
private double _currentProgress;
|
||||
private double _currentVolume = _defaultVolume;
|
||||
private string _currentTime = "0:00";
|
||||
private string _totalTime = "0:00";
|
||||
private bool _isPlaying;
|
||||
private Timer? _progressTimer;
|
||||
private bool _isMuted;
|
||||
private string? _currentAccessToken;
|
||||
private string? _currentSharedPlaylistId;
|
||||
private string? _currentTrackCoverUrl;
|
||||
private string? _currentTrackTitle;
|
||||
|
||||
// Громкость
|
||||
private bool _volumeIsOpen;
|
||||
private double _volumeBeforeMute;
|
||||
private double _bufferSecond;
|
||||
|
||||
private bool _isPlayHovered;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
AudioPlayerService.OnLoadAndPlayRequested += OnLoadAndPlay;
|
||||
AudioPlayerService.OnPlayRequested += OnPlay;
|
||||
AudioPlayerService.OnPauseRequested += OnPause;
|
||||
AudioPlayerService.OnStopRequested += OnStop;
|
||||
AudioPlayerService.OnSeekRequested += OnSeek;
|
||||
AudioPlayerService.OnVolumeChangeRequested += OnVolumeChange;
|
||||
AudioPlayerService.OnStateChanged += OnStateChanged;
|
||||
|
||||
await LoadSavedVolume();
|
||||
await AudioPlayerService.SetVolumeAsync(_currentVolume); // синхронизация
|
||||
AudioPlayerService.OnLoadAndPlayRequested += OnServiceLoadAndPlay;
|
||||
AudioPlayerService.OnPlayRequested += OnServicePlay;
|
||||
AudioPlayerService.OnPauseRequested += OnServicePause;
|
||||
AudioPlayerService.OnSeekRequested += OnServiceSeek;
|
||||
AudioPlayerService.OnVolumeChangeRequested += OnServiceVolumeChange;
|
||||
AudioPlayerService.OnStateChanged += OnServiceStateChanged;
|
||||
}
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
@@ -81,20 +137,6 @@
|
||||
await EnsureAudioModuleAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStateChanged()
|
||||
{
|
||||
_currentTrackTitle = AudioPlayerService.CurrentTrackTitle;
|
||||
_currentTrackCoverUrl = AudioPlayerService.CurrentTrackCoverUrl?.FormatCoverUrl(40, 40);
|
||||
InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task LoadSavedVolume()
|
||||
{
|
||||
var savedVolume = await PlayerStorage.GetVolumeAsync() ?? _defaultVolume;
|
||||
_currentVolume = savedVolume;
|
||||
await AudioPlayerService.SetVolumeAsync(savedVolume);
|
||||
}
|
||||
|
||||
private async Task EnsureAudioModuleAsync()
|
||||
{
|
||||
@@ -104,37 +146,94 @@
|
||||
_audioElement = await _audioModule.InvokeAsync<IJSObjectReference>("init", _audioId, DotNetObjectReference.Create(this));
|
||||
}
|
||||
|
||||
#region Обработка JS
|
||||
[JSInvokable]
|
||||
public async Task OnAudioEnded()
|
||||
{
|
||||
AudioPlayerService.NotifyTrackEnded();
|
||||
_isPlaying = false;
|
||||
_currentProgress = 0;
|
||||
StopProgressTimer();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnTimeUpdate(double currentTime, double duration)
|
||||
{
|
||||
if (double.IsNaN(currentTime) || double.IsNaN(duration) || duration <= 0) return;
|
||||
var progress = (currentTime / duration) * 100;
|
||||
var currentTimeStr = FormatTime(currentTime);
|
||||
var totalTimeStr = FormatTime(duration);
|
||||
AudioPlayerService.UpdateProgress(progress, currentTimeStr, totalTimeStr);
|
||||
_currentProgress = progress;
|
||||
_currentTime = currentTimeStr;
|
||||
_totalTime = totalTimeStr;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
if (!double.IsNaN(duration) && !double.IsNaN(currentTime) && duration > 0)
|
||||
{
|
||||
AudioPlayerService.UpdateProgress(currentTime, duration);
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnDurationReady(double duration)
|
||||
public async Task OnDownloadProgress(double second)
|
||||
{
|
||||
if (duration <= 0) return;
|
||||
_totalTime = FormatTime(duration);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
_bufferSecond = second;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Обработка сервиса
|
||||
private async Task OnServiceLoadAndPlay(string trackId, string? accessToken, string? sharedPlaylistId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
var tokens = await TokenStorage.GetTokensAsync();
|
||||
accessToken = tokens.token;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(accessToken) && string.IsNullOrWhiteSpace(sharedPlaylistId))
|
||||
{
|
||||
Snackbar.Add("Токен авторизации не найден. Пожалуйста, войдите заново.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var streamUrl = new Uri(Http.BaseAddress!, $"/api/audio/track/{trackId}").ToString();
|
||||
await EnsureAudioModuleAsync();
|
||||
await _audioElement!.InvokeVoidAsync("loadAndPlay", streamUrl, accessToken, sharedPlaylistId);
|
||||
}
|
||||
|
||||
private async Task OnServicePlay()
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
await _audioElement.InvokeVoidAsync("play");
|
||||
}
|
||||
|
||||
private async Task OnServicePause()
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
await _audioElement.InvokeVoidAsync("pause");
|
||||
}
|
||||
|
||||
private async Task OnServiceSeek(double time)
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
try
|
||||
{
|
||||
await _audioElement.InvokeVoidAsync("setCurrentTime", time);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Seek error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnServiceVolumeChange(double volume)
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
await _audioElement.InvokeVoidAsync("setVolume", volume / 100);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Volume change error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnServiceStateChanged()
|
||||
{
|
||||
InvokeAsync(StateHasChanged);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private async Task<bool> CheckAuthAsync()
|
||||
{
|
||||
@@ -147,102 +246,15 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task OnLoadAndPlay(string trackId, string? accessToken, string? sharedPlaylistId)
|
||||
private async Task OnVolumeHandleWheel(WheelEventArgs e)
|
||||
{
|
||||
//if (!await CheckAuthAsync()) return;
|
||||
|
||||
var tokens = await TokenStorage.GetTokensAsync();
|
||||
_currentAccessToken = accessToken ?? tokens.token;
|
||||
_currentSharedPlaylistId = sharedPlaylistId;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_currentAccessToken) && string.IsNullOrWhiteSpace(_currentSharedPlaylistId))
|
||||
{
|
||||
Snackbar.Add("Токен авторизации не найден. Пожалуйста, войдите заново.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var streamUrl = new Uri(Http.BaseAddress!, $"/api/audio/track/{trackId}").ToString();
|
||||
await EnsureAudioModuleAsync();
|
||||
await _audioElement!.InvokeVoidAsync("loadAndPlay", streamUrl, _currentAccessToken, _currentSharedPlaylistId);
|
||||
_isPlaying = true;
|
||||
StartProgressTimer();
|
||||
StateHasChanged();
|
||||
}
|
||||
// Изменяем громкость на 5 единиц за один тик колесика
|
||||
double step = 5;
|
||||
double newVolume = e.DeltaY < 0
|
||||
? Math.Min(AudioPlayerService.CurrentVolume + step, 100)
|
||||
: Math.Max(AudioPlayerService.CurrentVolume - step, 0);
|
||||
|
||||
private async Task OnPlay()
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
await _audioElement.InvokeVoidAsync("play");
|
||||
_isPlaying = true;
|
||||
StartProgressTimer();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnPause()
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
await _audioElement.InvokeVoidAsync("pause");
|
||||
_isPlaying = false;
|
||||
StopProgressTimer();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnStop()
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
await _audioElement.InvokeVoidAsync("stop");
|
||||
_isPlaying = false;
|
||||
_currentProgress = 0;
|
||||
StopProgressTimer();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnSeek(double percent)
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
try
|
||||
{
|
||||
var duration = await _audioElement.InvokeAsync<double>("getDuration");
|
||||
if (duration > 0 && !double.IsNaN(duration))
|
||||
{
|
||||
var newTime = (percent / 100) * duration;
|
||||
await _audioElement.InvokeVoidAsync("setCurrentTime", newTime);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Seek error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnVolumeChange(double volume)
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
try
|
||||
{
|
||||
await _audioElement.InvokeVoidAsync("setVolume", volume / 100);
|
||||
_isMuted = false;
|
||||
_currentVolume = volume;
|
||||
await PlayerStorage.SetVolumeAsync(volume);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Volume change error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task TogglePlayPause()
|
||||
{
|
||||
if (_isPlaying)
|
||||
await AudioPlayerService.PauseAsync();
|
||||
else
|
||||
await AudioPlayerService.PlayAsync();
|
||||
}
|
||||
|
||||
private async Task Stop()
|
||||
{
|
||||
await AudioPlayerService.StopAsync();
|
||||
await ChangeVolume(newVolume);
|
||||
}
|
||||
|
||||
private async Task SeekTo(double value)
|
||||
@@ -257,57 +269,37 @@
|
||||
|
||||
private async Task ToggleMute()
|
||||
{
|
||||
_isMuted = !_isMuted;
|
||||
var newVolume = _isMuted ? 0 : _currentVolume;
|
||||
await AudioPlayerService.SetVolumeAsync(newVolume);
|
||||
}
|
||||
|
||||
private void StartProgressTimer()
|
||||
{
|
||||
StopProgressTimer();
|
||||
_progressTimer = new Timer(async _ => await UpdateProgress(), null, 0, 500);
|
||||
}
|
||||
|
||||
private void StopProgressTimer() => _progressTimer?.Dispose();
|
||||
|
||||
private async Task UpdateProgress()
|
||||
{
|
||||
if (_audioElement == null) return;
|
||||
try
|
||||
if (AudioPlayerService.CurrentVolume > 0)
|
||||
{
|
||||
var current = await _audioElement.InvokeAsync<double>("getCurrentTime");
|
||||
var duration = await _audioElement.InvokeAsync<double>("getDuration");
|
||||
if (duration > 0 && !double.IsNaN(duration) && !double.IsNaN(current))
|
||||
{
|
||||
var progress = (current / duration) * 100;
|
||||
var currentTime = FormatTime(current);
|
||||
var totalTime = FormatTime(duration);
|
||||
AudioPlayerService.UpdateProgress(progress, currentTime, totalTime);
|
||||
_currentProgress = progress;
|
||||
_currentTime = currentTime;
|
||||
_totalTime = totalTime;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
_volumeBeforeMute = AudioPlayerService.CurrentVolume;
|
||||
await AudioPlayerService.SetVolumeAsync(0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"UpdateProgress error: {ex.Message}");
|
||||
await AudioPlayerService.SetVolumeAsync(_volumeBeforeMute);
|
||||
_volumeBeforeMute = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private string FormatTime(double seconds)
|
||||
private async Task OnPlayClick()
|
||||
{
|
||||
var total = (int)seconds;
|
||||
var mins = total / 60;
|
||||
var secs = total % 60;
|
||||
return $"{mins}:{secs:D2}";
|
||||
if (AudioPlayerService.IsPlaying)
|
||||
await AudioPlayerService.PauseAsync();
|
||||
else
|
||||
await AudioPlayerService.PlayAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
StopProgressTimer();
|
||||
AudioPlayerService.OnLoadAndPlayRequested -= OnServiceLoadAndPlay;
|
||||
AudioPlayerService.OnPlayRequested -= OnServicePlay;
|
||||
AudioPlayerService.OnPauseRequested -= OnServicePause;
|
||||
AudioPlayerService.OnSeekRequested -= OnServiceSeek;
|
||||
AudioPlayerService.OnVolumeChangeRequested -= OnServiceVolumeChange;
|
||||
AudioPlayerService.OnStateChanged -= OnServiceStateChanged;
|
||||
|
||||
if (_audioElement != null)
|
||||
await _audioElement.DisposeAsync();
|
||||
if (_audioModule != null)
|
||||
@@ -315,4 +307,9 @@
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeAsync().AsTask().Wait();
|
||||
}
|
||||
}
|
||||
30
PlaylistShared.Pwa/Components/Global/ContextualBarContent.cs
Normal file
30
PlaylistShared.Pwa/Components/Global/ContextualBarContent.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using PlaylistShared.Pwa.Services;
|
||||
|
||||
namespace PlaylistShared.Pwa.Components.Global;
|
||||
|
||||
public class ContextualBarContent : ComponentBase, IDisposable
|
||||
{
|
||||
[Inject]
|
||||
public ContextualActionBarService ContextualActionBarService { get; set; } = default!;
|
||||
|
||||
[Parameter]
|
||||
public ContextualActionBarPosition Position { get; set; } = ContextualActionBarPosition.Default;
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
ContextualActionBarService.Content = ChildContent;
|
||||
ContextualActionBarService.Position = Position;
|
||||
ContextualActionBarService.ChangeParameters();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ContextualActionBarService.Content = null;
|
||||
ContextualActionBarService.Position = ContextualActionBarPosition.Default;
|
||||
ContextualActionBarService.ChangeParameters();
|
||||
}
|
||||
}
|
||||
127
PlaylistShared.Pwa/Components/Global/TrackProgress.razor
Normal file
127
PlaylistShared.Pwa/Components/Global/TrackProgress.razor
Normal file
@@ -0,0 +1,127 @@
|
||||
@using MudBlazor
|
||||
|
||||
<div class="track-progress-container @ColorClass"
|
||||
@onwheel="HandleWheel"
|
||||
style="--track-height: @(Height)px; height: @(Height)px; --track-opacity: @(Opacity.ToString(System.Globalization.CultureInfo.InvariantCulture));">
|
||||
|
||||
<div class="progress-base-track">
|
||||
@if (Buffer)
|
||||
{
|
||||
<div class="progress-buffer-bar" style="width:@(CalculatePercentage(BufferValue).ToString("0.##", System.Globalization.CultureInfo.InvariantCulture))%;"></div>
|
||||
}
|
||||
<div class="progress-active-bar" style="width:@(CalculatePercentage(Value).ToString("0.##", System.Globalization.CultureInfo.InvariantCulture))%;"></div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Icon))
|
||||
{
|
||||
<div class="track-icon-thumb" style="left: @(CalculatePercentage(Value).ToString("0.##", System.Globalization.CultureInfo.InvariantCulture))%;">
|
||||
<MudIcon Icon="@Icon" Size="Size.Small" />
|
||||
</div>
|
||||
}
|
||||
|
||||
<input type="range"
|
||||
min="@Min.ToString(System.Globalization.CultureInfo.InvariantCulture)"
|
||||
max="@Max.ToString(System.Globalization.CultureInfo.InvariantCulture)"
|
||||
step="@Step.ToString(System.Globalization.CultureInfo.InvariantCulture)"
|
||||
value="@Value.ToString(System.Globalization.CultureInfo.InvariantCulture)"
|
||||
height="@Height"
|
||||
@oninput="OnInput"
|
||||
class="progress-input" />
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public double Value { get; set; }
|
||||
[Parameter] public double BufferValue { get; set; }
|
||||
[Parameter] public bool Buffer { get; set; } = true;
|
||||
[Parameter] public double Min { get; set; } = 0;
|
||||
[Parameter] public double Max { get; set; } = 100;
|
||||
[Parameter] public double Step { get; set; } = 1;
|
||||
[Parameter] public double Opacity { get; set; } = 1.0;
|
||||
[Parameter] public int Height { get; set; } = 4;
|
||||
[Parameter] public Color Color { get; set; } = Color.Primary;
|
||||
[Parameter] public string Icon { get; set; } = "";
|
||||
[Parameter] public EventCallback<double> ValueChanged { get; set; }
|
||||
|
||||
private string ColorClass => $"track-color-{Color.ToString().ToLower()}";
|
||||
|
||||
private double CalculatePercentage(double val) => Max <= Min ? 0 : ((Math.Clamp(val, Min, Max) - Min) / (Max - Min)) * 100;
|
||||
|
||||
private async Task OnInput(ChangeEventArgs e)
|
||||
{
|
||||
if (double.TryParse(e.Value?.ToString(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out var newValue))
|
||||
await ValueChanged.InvokeAsync(newValue);
|
||||
}
|
||||
|
||||
private async Task HandleWheel(WheelEventArgs e)
|
||||
{
|
||||
double range = Max - Min;
|
||||
double wheelStep = range * 0.02;
|
||||
var newValue = e.DeltaY < 0 ? Math.Min(Value + wheelStep, Max) : Math.Max(Value - wheelStep, Min);
|
||||
await ValueChanged.InvokeAsync(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
<style>
|
||||
.track-progress-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
--track-color: var(--mud-palette-primary);
|
||||
}
|
||||
|
||||
.track-color-primary { --track-color: var(--mud-palette-primary); }
|
||||
.track-color-secondary { --track-color: var(--mud-palette-secondary); }
|
||||
.track-color-success { --track-color: var(--mud-palette-success); }
|
||||
.track-color-info { --track-color: var(--mud-palette-info); }
|
||||
.track-color-warning { --track-color: var(--mud-palette-warning); }
|
||||
.track-color-error { --track-color: var(--mud-palette-error); }
|
||||
|
||||
.progress-base-track {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: var(--track-height);
|
||||
background-color: var(--mud-palette-action-disabled-background, rgba(0,0,0,0.1));
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-active-bar {
|
||||
position: absolute;
|
||||
left: 0; top: 0; bottom: 0;
|
||||
background-color: var(--track-color);
|
||||
opacity: var(--track-opacity); /* Применяем opacity */
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.progress-buffer-bar {
|
||||
position: absolute;
|
||||
left: 0; top: 0; bottom: 0;
|
||||
background-color: var(--mud-palette-action-default-hover);
|
||||
opacity: calc(var(--track-opacity) * 0.5); /* Буфер чуть прозрачнее основного прогресса */
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.track-icon-thumb {
|
||||
position: absolute;
|
||||
transform: translateX(-50%);
|
||||
z-index: 11;
|
||||
pointer-events: none;
|
||||
color: var(--track-color);
|
||||
opacity: 0;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.track-progress-container:hover .track-icon-thumb { opacity: 1; }
|
||||
|
||||
.progress-input {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
-webkit-appearance: none;
|
||||
z-index: 10;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.progress-input::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; }
|
||||
.progress-input::-moz-range-thumb { opacity: 0; }
|
||||
</style>
|
||||
@@ -0,0 +1,147 @@
|
||||
@using System.Threading
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Авторизация Яндекс.Музыки по QR</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
@if (_qrUrl != null)
|
||||
{
|
||||
<div style="text-align: center;">
|
||||
<MudText Typo="Typo.body2" Class="mb-2">Отсканируйте QR-код приложением Яндекс</MudText>
|
||||
<MudImage Src="@_qrUrl" Style="max-width: 250px; border-radius: 12px; background-color: white;" />
|
||||
<MudText Typo="Typo.body2" Class="mt-2" Color="Color.Secondary">
|
||||
Статус: @_statusText
|
||||
</MudText>
|
||||
@if (_isWaiting)
|
||||
{
|
||||
<MudProgressCircular Indeterminate Class="mt-2" Size="Size.Small" />
|
||||
}
|
||||
@if (_isError)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-4">
|
||||
@_errorMessage
|
||||
</MudAlert>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudProgressCircular Indeterminate />
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Text" OnClick="Cancel">Отмена</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; }
|
||||
|
||||
private string _qrUrl;
|
||||
private string _sessionId;
|
||||
private string _statusText = "Ожидание сканирования";
|
||||
private bool _isWaiting = true;
|
||||
private bool _isError = false;
|
||||
private string _errorMessage = "";
|
||||
private CancellationTokenSource _cts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await StartQrFlow();
|
||||
}
|
||||
|
||||
private async Task StartQrFlow()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 1. Получить QR и sessionId
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<YandexAuthQr>>("/api/yandexaccount/qr");
|
||||
if (!response.Success || response.Data == null)
|
||||
{
|
||||
ShowError("Не удалось получить QR-код");
|
||||
return;
|
||||
}
|
||||
|
||||
_qrUrl = response.Data.QrLink;
|
||||
_sessionId = response.Data.SessionId;
|
||||
|
||||
// 2. Начать опрос статуса
|
||||
_cts = new CancellationTokenSource();
|
||||
_ = PollStatus(_cts.Token);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PollStatus(CancellationToken token)
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(500, token);
|
||||
var statusResponse = await Http.GetFromJsonAsync<ApiResponse<YandexAuthQrCheck>>($"/api/yandexaccount/qr/{_sessionId}", token);
|
||||
if (statusResponse?.Data != null)
|
||||
{
|
||||
switch (statusResponse.Data.Status)
|
||||
{
|
||||
case Shared.Enums.YandexAuthQrStatus.Pending:
|
||||
_statusText = "Ожидание подтверждения...";
|
||||
break;
|
||||
case Shared.Enums.YandexAuthQrStatus.Authorized:
|
||||
_statusText = "Авторизация успешна!";
|
||||
_isWaiting = false;
|
||||
Snackbar.Add("Авторизация выполнена", Severity.Success);
|
||||
_cts?.Cancel();
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
return;
|
||||
case Shared.Enums.YandexAuthQrStatus.Expired:
|
||||
_cts?.Cancel();
|
||||
ShowError("Срок действия QR-кода истёк");
|
||||
return;
|
||||
case Shared.Enums.YandexAuthQrStatus.Error:
|
||||
_cts?.Cancel();
|
||||
ShowError("Ошибка авторизации");
|
||||
return;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
catch (TaskCanceledException) { break; }
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowError(ex.Message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowError(string message)
|
||||
{
|
||||
_isError = true;
|
||||
_errorMessage = message;
|
||||
_isWaiting = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
_cts?.Cancel();
|
||||
MudDialog.Close(DialogResult.Cancel());
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_cts?.Cancel();
|
||||
_cts?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
@using System.Text.RegularExpressions
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Подключение Яндекс.Музыки</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudStepper @bind-ActiveIndex="_index" Vertical CenterLabels CompletedStepColor="Color.Success" @onwheel="HandleWheel">
|
||||
<ChildContent>
|
||||
<MudStep Title="Вход" Skippable>
|
||||
<MudText Typo="Typo.body2" Class="mb-4">Нажмите на кнопку и разрешите доступ приложению.</MudText>
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@PlaylistShared.Pwa.CustomIcons.Yandex"
|
||||
Href="https://oauth.yandex.ru/authorize?response_type=token&client_id=23cabbbdc6cd418abb4b39c32c41195d"
|
||||
Target="_blank"
|
||||
@onclick="() => {_index++;}"
|
||||
FullWidth>
|
||||
Войти в Яндекс
|
||||
</MudButton>
|
||||
</MudStep>
|
||||
|
||||
<MudStep Title="Добавление токена">
|
||||
Скопируйте значение <code>access_token</code> или <code>весь URL</code> из адресной строки после перенаправления.
|
||||
<MudAlert Severity="Severity.Info" Class="mt-4">
|
||||
https://music.yandex.ru/#access_token=<code>ВАШ_ТОКЕН</code>&...
|
||||
</MudAlert>
|
||||
<MudTextField @bind-Value="_rawInput" @bind-Value:after="Submit" Label="Вставьте скопированную ссылку или токен" Variant="Variant.Outlined" Margin="Margin.Dense" Error="_tokenErr" />
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" OnClick="Submit" FullWidth Class="mt-4">
|
||||
Сохранить
|
||||
</MudButton>
|
||||
</MudStep>
|
||||
</ChildContent>
|
||||
<ActionContent Context="stepper">
|
||||
<MudIconButton OnClick="@(() => stepper.PreviousStepAsync())" Icon="@Icons.Material.Filled.ArrowBack" Color="Color.Primary" Disabled="@(_index <= 0)" />
|
||||
<MudSpacer />
|
||||
<MudIconButton OnClick="@(() => stepper.NextStepAsync())" Icon="@Icons.Material.Filled.ArrowForward" Color="Color.Primary" Disabled="@(_index >= 1)" />
|
||||
</ActionContent>
|
||||
</MudStepper>
|
||||
</DialogContent>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] IMudDialogInstance MudDialog { get; set; }
|
||||
private string _rawInput = "";
|
||||
private int _index;
|
||||
private bool _tokenErr = false;
|
||||
|
||||
private async Task HandleWheel(WheelEventArgs e)
|
||||
{
|
||||
|
||||
if (e.DeltaY > 0 && _index < 1) // Прокрутка вниз -> Вперед
|
||||
{
|
||||
_index++;
|
||||
}
|
||||
else if (e.DeltaY < 0 && _index > 0) // Прокрутка вверх -> Назад
|
||||
{
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
var token = ExtractToken(_rawInput);
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
_tokenErr = true;
|
||||
Snackbar.Add("Токен не найден", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_tokenErr = false;
|
||||
|
||||
var response = await Http.PostAsJsonAsync("/api/yandexaccount/token", new SetYandexTokenRequest { Token = token });
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
Snackbar.Add("Токен успешно обновлен", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Ошибка обновления токена. Повторите позже.", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private string ExtractToken(string input) =>
|
||||
input.Contains("access_token=") ? Regex.Match(input, @"access_token=([^&]+)").Groups[1].Value : input.Trim();
|
||||
|
||||
public class SetYandexTokenRequest { public string Token { get; set; } }
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
@* Компонент с инструкцией по получению токена Яндекс.Музыки *@
|
||||
|
||||
<MudContainer Class="pa-4">
|
||||
<MudText Typo="Typo.body2" GutterBottom>
|
||||
Токен нужен для доступа к вашим плейлистам. Получите его один раз:
|
||||
</MudText>
|
||||
|
||||
<!-- Вертикальный список шагов -->
|
||||
<MudStack Class="my-4">
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
<MudPaper Elevation="0" Style="width: 28px; height: 28px; background-color: var(--mud-palette-primary); color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: bold;">1</MudPaper>
|
||||
<MudText>
|
||||
Перейдите по <MudLink Href="https://oauth.yandex.ru/authorize?response_type=token&client_id=23cabbbdc6cd418abb4b39c32c41195d" Target="_blank">ссылке</MudLink>
|
||||
</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
<MudPaper Elevation="0" Style="width: 28px; height: 28px; background-color: var(--mud-palette-primary); color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: bold;">1</MudPaper>
|
||||
<MudText>
|
||||
Авторизуйтесь в Яндексе (если ещё не вошли)
|
||||
</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
<MudPaper Elevation="0" Style="width: 28px; height: 28px; background-color: var(--mud-palette-primary); color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: bold;">1</MudPaper>
|
||||
<MudText>
|
||||
Нажмите «Разрешить»
|
||||
</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
<MudPaper Elevation="0" Style="width: 28px; height: 28px; background-color: var(--mud-palette-primary); color: white; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: bold;">1</MudPaper>
|
||||
<MudText>
|
||||
Скопируйте <strong>access_token</strong> из адресной строки после перенаправления
|
||||
</MudText>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
|
||||
<MudAlert Severity="Severity.Info" Class="mt-4">
|
||||
Пример: <code>https://music.yandex.ru/#access_token=ВАШ_ТОКЕН&...</code>
|
||||
</MudAlert>
|
||||
|
||||
<MudAlert Severity="Severity.Warning" Class="mt-2">
|
||||
Токен даёт доступ к вашим плейлистам. Никому его не сообщайте.
|
||||
</MudAlert>
|
||||
|
||||
<MudAlert Severity="Severity.Success" Class="mt-2" Icon="@Icons.Material.Filled.Security">
|
||||
Ваш токен сохраняется в зашифрованном виде и никому не передаётся.
|
||||
</MudAlert>
|
||||
</MudContainer>
|
||||
|
||||
<style>
|
||||
.instruction-steps {
|
||||
margin: 16px 0;
|
||||
}
|
||||
.step-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.step-number {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
background-color: var(--mud-palette-primary);
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: bold;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.step-content {
|
||||
flex: 1;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,236 +0,0 @@
|
||||
@using PlaylistShared.Pwa.Components.Common
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@using PlaylistShared.Shared.Enums
|
||||
@using PlaylistShared.Shared.SharedPlaylist
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudStack Style="height: 100%; overflow: hidden;">
|
||||
<MudItem>
|
||||
<MudTextField @bind-Value="_searchQuery"
|
||||
@bind-Value:after="SearchTracks"
|
||||
Variant="Variant.Outlined"
|
||||
FullWidth
|
||||
Label="Название или ссылка на трек Яндекс.Музыки"
|
||||
Disabled="@_isSearching"
|
||||
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color.Secondary" />
|
||||
|
||||
<MudToggleGroup T="TrackSearchType"
|
||||
@bind-Value="_searchType"
|
||||
@bind-Value:after="SearchTracks"
|
||||
Size="Size.Small"
|
||||
Color="Color.Primary"
|
||||
Disabled="@(_isSearching)">
|
||||
<MudToggleItem Value="TrackSearchType.All" Text="Все" />
|
||||
<MudToggleItem Value="TrackSearchType.Track" Text="Трек" />
|
||||
<MudToggleItem Value="TrackSearchType.Album" Text="Альбом" />
|
||||
<MudToggleItem Value="TrackSearchType.Artist" Text="Исполнитель" />
|
||||
</MudToggleGroup>
|
||||
</MudItem>
|
||||
|
||||
<MudTable Items="@_searchResults"
|
||||
Virtualize
|
||||
Hover
|
||||
Elevation="0"
|
||||
Class="d-flex flex-grow-1 flex-column"
|
||||
Style="min-height: 0;"
|
||||
Breakpoint="Breakpoint.Sm"
|
||||
Loading="@_isSearching">
|
||||
<RowTemplate>
|
||||
<MudTd Class="pa-1" Style="width: 100%;">
|
||||
<TrackItem Track="@context" PlaylistShareToken="@ShareToken" />
|
||||
</MudTd>
|
||||
<MudTd Class="pa-1">
|
||||
<MudToggleIconButton Toggled="@ExistingTrackIds.Contains(context.TrackId)"
|
||||
Icon="@Icons.Material.Filled.AddCircle"
|
||||
Color="@Color.Primary"
|
||||
ToggledIcon="@Icons.Material.Filled.RemoveCircle"
|
||||
ToggledColor="@Color.Error"
|
||||
ToggledChanged="() => ToggleTrack(context)" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</MudStack>
|
||||
|
||||
@code {
|
||||
[Parameter] public string ShareToken { get; set; } = string.Empty;
|
||||
[Parameter] public EventCallback OnTrackAdded { get; set; }
|
||||
[Parameter] public EventCallback OnTrackRemoved { get; set; }
|
||||
[Parameter] public HashSet<string> ExistingTrackIds { get; set; } = new();
|
||||
|
||||
private string _searchQuery = "";
|
||||
private bool _isSearching = false;
|
||||
private bool _isFirstSearch = true;
|
||||
private TrackSearchType _searchType = TrackSearchType.All;
|
||||
private List<YandexTrack> _searchResults = new();
|
||||
|
||||
private async Task SearchTracks()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_searchQuery))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var query = _searchQuery.Trim();
|
||||
var type = _searchType;
|
||||
bool byId = false;
|
||||
|
||||
if (Uri.TryCreate(_searchQuery, UriKind.Absolute, out var uri) && uri.Host == "music.yandex.ru")
|
||||
{
|
||||
try
|
||||
{
|
||||
(type, query) = ParseYandexMusicUrl(uri);
|
||||
byId = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Ошибка распознавания URL: {ex.Message}", Severity.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_isFirstSearch = false;
|
||||
_isSearching = true;
|
||||
try
|
||||
{
|
||||
var url = $"/api/yandexsearch/tracks?query={Uri.EscapeDataString(query)}&searchType={Uri.EscapeDataString(type.ToString())}&limit=20";
|
||||
if (!string.IsNullOrEmpty(ShareToken))
|
||||
url += $"&shared_id={Uri.EscapeDataString(ShareToken)}";
|
||||
if (byId)
|
||||
url += $"&byId={byId}";
|
||||
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<List<YandexTrack>>>(url);
|
||||
if (response?.Success == true)
|
||||
_searchResults = response.Data ?? new();
|
||||
else
|
||||
Snackbar.Add(response?.Error?.Message ?? "Ошибка поиска", Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Ошибка: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSearching = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task SearchTracksByQuery(string query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
private async Task ToggleTrack(YandexTrack track)
|
||||
{
|
||||
if (ExistingTrackIds.Contains(track.TrackId))
|
||||
{
|
||||
await RemoveTrack(track);
|
||||
}
|
||||
else
|
||||
{
|
||||
await AddTrack(track);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RemoveTrack(YandexTrack track)
|
||||
{
|
||||
if (!ExistingTrackIds.Remove(track.TrackId)) return;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
await RemoveTrackById(track.TrackId);
|
||||
await OnTrackRemoved.InvokeAsync();
|
||||
Snackbar.Add($"Трек \"{track.Title}\" удален", Severity.Success, c => c.SnackbarVariant = Variant.Outlined);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"{ex.Message}", Severity.Error);
|
||||
ExistingTrackIds.Add(track.TrackId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RemoveTrackById(string trackId)
|
||||
{
|
||||
var request = new UpdateTrackListRequest { TrackIds = new List<string> { trackId } };
|
||||
var response = await Http.PostAsJsonAsync($"/api/sharedplaylist/{ShareToken}/remove-tracks", request);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
await OnTrackAdded.InvokeAsync(); // уведомляем родителя, что список треков изменился
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = await response.Content.ReadFromJsonAsync<ApiResponse<object>>();
|
||||
throw new Exception(error?.Error?.Message ?? "Ошибка удаления трека");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddTrack(YandexTrack track)
|
||||
{
|
||||
if (ExistingTrackIds.Contains(track.TrackId)) return;
|
||||
ExistingTrackIds.Add(track.TrackId);
|
||||
|
||||
try
|
||||
{
|
||||
await AddTrackById(track.TrackId);
|
||||
await OnTrackAdded.InvokeAsync();
|
||||
Snackbar.Add($"Трек \"{track.Title}\" добавлен", Severity.Success, c => c.SnackbarVariant = Variant.Outlined);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"{ex.Message}", Severity.Error);
|
||||
ExistingTrackIds.Remove(track.TrackId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddTrackById(string trackId)
|
||||
{
|
||||
var request = new UpdateTrackListRequest { TrackIds = new List<string> { trackId } };
|
||||
var response = await Http.PostAsJsonAsync($"/api/sharedplaylist/{ShareToken}/add-tracks", request);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
await OnTrackAdded.InvokeAsync(); // уведомляем родителя, что список треков изменился
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = await response.Content.ReadFromJsonAsync<ApiResponse<object>>();
|
||||
throw new Exception(error?.Error?.Message ?? "Ошибка добавления трека");
|
||||
}
|
||||
}
|
||||
|
||||
private static (TrackSearchType Type, string Id) ParseYandexMusicUrl(Uri uri)
|
||||
{
|
||||
var segments = uri.AbsolutePath.Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
var dataMap = segments
|
||||
.Select((val, idx) => new { val, idx })
|
||||
.GroupBy(x => x.idx / 2)
|
||||
.ToDictionary(
|
||||
g => g.First().val,
|
||||
g => g.ElementAtOrDefault(1)?.val
|
||||
);
|
||||
|
||||
if (dataMap.TryGetValue("track", out var trackId) && !string.IsNullOrEmpty(trackId))
|
||||
return (TrackSearchType.Track, trackId);
|
||||
if (dataMap.TryGetValue("album", out var albumId) && !string.IsNullOrEmpty(albumId))
|
||||
return (TrackSearchType.Album, albumId);
|
||||
if (dataMap.TryGetValue("playlist", out var playlistId) && !string.IsNullOrEmpty(playlistId))
|
||||
return (TrackSearchType.Playlist, playlistId);
|
||||
if (dataMap.TryGetValue("artist", out var artistId) && !string.IsNullOrEmpty(artistId))
|
||||
return (TrackSearchType.Artist, artistId);
|
||||
|
||||
throw new ArgumentException("Unsupported URL pattern");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
|
||||
<MudItem Class="d-flex flex-column align-center pa-2 cursor-pointer" @onclick="HandleClick">
|
||||
@if (!string.IsNullOrEmpty(Item.CoverUrl))
|
||||
{
|
||||
<MudAvatar Size="MudBlazor.Size.Large">
|
||||
<MudImage Src="@Item.CoverUrl.FormatCoverUrl(Size, Size)" />
|
||||
</MudAvatar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAvatar Size="MudBlazor.Size.Large" Variant="Variant.Filled">
|
||||
<MudIcon Icon="@Icons.Material.Filled.AccountCircle" />
|
||||
</MudAvatar>
|
||||
}
|
||||
<MudText Typo="Typo.body2" Align="Align.Center" Class="mt-2">@Item.Title</MudText>
|
||||
<MudText Typo="Typo.caption" Align="Align.Center" Color="Color.Secondary">
|
||||
@string.Join(", ", Item.Artists.Select(a => a.Name))
|
||||
</MudText>
|
||||
</MudItem>
|
||||
|
||||
@code {
|
||||
[Parameter] public YandexAlbum Item { get; set; } = null!;
|
||||
[Parameter] public EventCallback OnClick { get; set; }
|
||||
[Parameter] public int Size { get; set; } = 50;
|
||||
|
||||
private async Task HandleClick()
|
||||
{
|
||||
if (OnClick.HasDelegate)
|
||||
{
|
||||
await OnClick.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
|
||||
<MudItem Class="d-flex flex-column align-center pa-2 cursor-pointer" @onclick="HandleClick">
|
||||
@if (!string.IsNullOrEmpty(Item.CoverUrl))
|
||||
{
|
||||
<MudAvatar Size="MudBlazor.Size.Large">
|
||||
<MudImage Src="@Item.CoverUrl.FormatCoverUrl(Size, Size)" />
|
||||
</MudAvatar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAvatar Size="MudBlazor.Size.Large" Variant="Variant.Filled">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Album" />
|
||||
</MudAvatar>
|
||||
}
|
||||
<MudText Typo="Typo.body2" Align="Align.Center" Class="mt-2">@Item.Name</MudText>
|
||||
</MudItem>
|
||||
|
||||
@code {
|
||||
[Parameter] public YandexArtist Item { get; set; } = null!;
|
||||
[Parameter] public EventCallback OnClick { get; set; }
|
||||
[Parameter] public int Size { get; set; } = 50;
|
||||
|
||||
private async Task HandleClick()
|
||||
{
|
||||
if (OnClick.HasDelegate)
|
||||
{
|
||||
await OnClick.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
@using PlaylistShared.Pwa.Components.Common
|
||||
|
||||
<MudItem Class="d-flex flex-column align-center pa-2">
|
||||
<!-- Аватар-скелет -->
|
||||
<MudAvatar Size="MudBlazor.Size.Large">
|
||||
<MudSkeleton SkeletonType="SkeletonType.Circle" Width="@Size.ToString()" Height="@Size.ToString()" />
|
||||
</MudAvatar>
|
||||
|
||||
<!-- Текст-скелет -->
|
||||
<MudSkeleton SkeletonType="SkeletonType.Text" Width="50px" Class="mt-2" />
|
||||
<MudSkeleton SkeletonType="SkeletonType.Text" Width="30px" Class="ma-0" />
|
||||
</MudItem>
|
||||
|
||||
@code {
|
||||
[Parameter] public int Size { get; set; } = 50;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
|
||||
<MudItem Class="d-flex flex-column align-center pa-2 cursor-pointer" @onclick="HandleClick">
|
||||
@if (!string.IsNullOrEmpty(Item.CoverUrl))
|
||||
{
|
||||
<MudAvatar Size="MudBlazor.Size.Large">
|
||||
<MudImage Src="@Item.CoverUrl.FormatCoverUrl(Size, Size)" />
|
||||
</MudAvatar>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAvatar Size="MudBlazor.Size.Large" Variant="Variant.Filled">
|
||||
<MudIcon Icon="@Icons.Material.Filled.PlaylistPlay" />
|
||||
</MudAvatar>
|
||||
}
|
||||
<MudText Typo="Typo.body2" Align="Align.Center" Class="mt-2">@Item.Title</MudText>
|
||||
</MudItem>
|
||||
|
||||
@code {
|
||||
[Parameter] public YandexPlaylist Item { get; set; } = null!;
|
||||
[Parameter] public EventCallback OnClick { get; set; }
|
||||
[Parameter] public int Size { get; set; } = 50;
|
||||
|
||||
private async Task HandleClick()
|
||||
{
|
||||
if (OnClick.HasDelegate)
|
||||
{
|
||||
await OnClick.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
@using PlaylistShared.Pwa.Components.Common
|
||||
@using PlaylistShared.Shared.Enums
|
||||
@using System.Security.Claims
|
||||
@using PlaylistShared.Shared.SharedPlaylist
|
||||
@inject HttpClient Http
|
||||
@inject NavigationManager Navigation
|
||||
@inject AuthenticationStateProvider AuthProvider
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<MudStack Row AlignItems="AlignItems.Center">
|
||||
@if (!string.IsNullOrEmpty(Playlist?.CoverUrl))
|
||||
{
|
||||
<MudImage Src="@Playlist.CoverUrl.FormatCoverUrl(80, 80)" Height="80" Width="80" Class="rounded" />
|
||||
}
|
||||
<MudStack>
|
||||
<MudStack Row AlignItems="AlignItems.Center" Wrap="Wrap.Wrap">
|
||||
<MudLink Href="@($"https://music.yandex.ru/playlists/{Playlist?.YandexPlaylistUuid}")"
|
||||
Typo="Typo.h5"
|
||||
Target="_blank"
|
||||
Underline="Underline.Hover">
|
||||
@Playlist?.Title
|
||||
<MudIcon Icon="@Icons.Material.Filled.OpenInNew" Size="Size.Small" Class="ml-1" />
|
||||
</MudLink>
|
||||
|
||||
<ShareButton />
|
||||
|
||||
<MudIconButton Icon="@(_isFavorite? Icons.Material.Filled.Star : Icons.Material.Outlined.StarBorder)"
|
||||
Color="Color.Warning"
|
||||
OnClick="ToggleFavorite"
|
||||
Disabled="_favoriteLoading"
|
||||
Size="Size.Medium" />
|
||||
|
||||
@if (_isCreator && _isAuthenticated)
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Settings"
|
||||
Color="Color.Default"
|
||||
OnClick="OpenPermissionsDialog"
|
||||
Title="Настройки доступа"
|
||||
Size="Size.Medium" />
|
||||
}
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
|
||||
@code {
|
||||
[Parameter] public SharedPlaylistDto? Playlist { get; set; }
|
||||
[Parameter] public EventCallback OnPermissionsChanged { get; set; }
|
||||
|
||||
private bool _isAuthenticated;
|
||||
private bool _isCreator;
|
||||
private string? _currentUserId;
|
||||
private bool _isFavorite;
|
||||
private bool _favoriteLoading;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authState = await AuthProvider.GetAuthenticationStateAsync();
|
||||
_isAuthenticated = authState.User.Identity?.IsAuthenticated == true;
|
||||
_currentUserId = authState.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
_isCreator = Playlist?.CreatorUserId.ToString() == _currentUserId;
|
||||
if (_isAuthenticated)
|
||||
{
|
||||
await CheckFavoriteStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CheckFavoriteStatus()
|
||||
{
|
||||
if (Playlist == null) return;
|
||||
try
|
||||
{
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<bool>>($"/api/favorites/{Playlist.ShareToken}/check");
|
||||
if (response?.Success == true)
|
||||
_isFavorite = response.Data;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
private async Task ToggleFavorite()
|
||||
{
|
||||
if (Playlist == null) return;
|
||||
|
||||
if (!_isAuthenticated)
|
||||
{
|
||||
Snackbar.Add("Добавление в избранное только авторизованным пользователям", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
_favoriteLoading = true;
|
||||
try
|
||||
{
|
||||
if (_isFavorite)
|
||||
{
|
||||
var response = await Http.DeleteAsync($"/api/favorites/{Playlist.ShareToken}");
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
_isFavorite = false;
|
||||
Snackbar.Add("Плейлист удалён из избранного", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Ошибка удаления из избранного", Severity.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var response = await Http.PostAsync($"/api/favorites/{Playlist.ShareToken}", null);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
_isFavorite = true;
|
||||
Snackbar.Add("Плейлист добавлен в избранное", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Ошибка добавления в избранное", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Ошибка: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_favoriteLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenPermissionsDialog()
|
||||
{
|
||||
if (Playlist == null) return;
|
||||
var initialPermissions = new UpdatePermissionsDto
|
||||
{
|
||||
ViewPermission = Playlist.ViewPermission,
|
||||
PlayPermission = Playlist.PlayPermission,
|
||||
AddPermission = Playlist.AddPermission,
|
||||
RemovePermission = Playlist.RemovePermission
|
||||
};
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ nameof(PermissionsDialog.ShareToken), Playlist.ShareToken },
|
||||
{ nameof(PermissionsDialog.InitialPermissions), initialPermissions }
|
||||
};
|
||||
var dialog = await DialogService.ShowAsync<PermissionsDialog>("Настройки доступа", parameters);
|
||||
var result = await dialog.Result;
|
||||
if (!result.Canceled)
|
||||
{
|
||||
await OnPermissionsChanged.InvokeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,33 @@ public static class LongExtensions
|
||||
/// <summary>
|
||||
/// Преобразует миллисекунды в формат Минуты:Секунды
|
||||
/// </summary>
|
||||
public static string FormatDuration(this long ms)
|
||||
public static string FormatDuration(this long ms, FormatDurationType format = FormatDurationType.mmss)
|
||||
{
|
||||
var seconds = ms / 1000;
|
||||
var mins = seconds / 60;
|
||||
var secs = seconds % 60;
|
||||
return $"{mins}:{secs:D2}";
|
||||
|
||||
var mm = seconds / 60;
|
||||
var ss = seconds % 60;
|
||||
|
||||
if (format == FormatDurationType.mmss || mm < 60)
|
||||
{
|
||||
return $"{mm}:{ss:D2}";
|
||||
}
|
||||
else if (format == FormatDurationType.hhmmss)
|
||||
{
|
||||
var hh = mm / 60;
|
||||
mm = mm / 60;
|
||||
|
||||
return $"{hh}:{mm:D2}:{ss:D2}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{mm}:{ss:D2}";
|
||||
}
|
||||
}
|
||||
|
||||
public enum FormatDurationType
|
||||
{
|
||||
mmss,
|
||||
hhmmss,
|
||||
}
|
||||
}
|
||||
7
PlaylistShared.Pwa/Icons/CustomIcons.cs
Normal file
7
PlaylistShared.Pwa/Icons/CustomIcons.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace PlaylistShared.Pwa;
|
||||
|
||||
public static class CustomIcons
|
||||
{
|
||||
public const string Yandex = @"<path d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm.72 15.79h-2.14v-1.58c-.37.49-.87.89-1.48 1.18-.61.29-1.29.44-2.03.44-1.2 0-2.13-.34-2.8-.1-1.02-.66-1.52-1.61-1.52-2.84 0-1.25.43-2.22 1.28-2.91.85-.69 2.05-1.04 3.59-1.04h1.1v-.84c0-.62-.15-1.07-.46-1.34-.31-.27-.79-.41-1.44-.41-.53 0-1.02.08-1.48.24-.46.16-.9.41-1.32.74v-1.8c.48-.25 1.01-.45 1.58-.59.57-.14 1.15-.21 1.74-.21 1.45 0 2.53.33 3.23 1 .7.67 1.05 1.66 1.05 2.97v6.29zm-2.14-5.18h-.9c-.8 0-1.4.15-1.8.44-.4.29-.6.74-.6 1.34 0 .55.16.96.48 1.23.32.27.76.41 1.32.41.51 0 .97-.13 1.37-.39.4-.26.6-.64.6-1.14v-1.89z'/>";
|
||||
public const string YandexMusic = "<path d='M23.8 9.4l-.1-.5-3.9-.9 2-3-.2-.3-3.1 1.5.3-4.2-.3-.2-2 3.4L14.3 0h-.4l.6 4.9-5.7-4.5-.5.1 4.4 5.5-8.7-2.9-.4.4 7.8 4.4-10.7.9-.1.7 11.2 1.2-9.3 7.6.4.6 11.1-6.1-2.2 10.6h.7l4.3-10 2.6 7.8.4-.3-.9-7.8 3.9 4.5.2-.4-2.9-5.5 4.2 1.5.1-.5-3.5-2.8 3.3-.7z'/>";
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
@using MudBlazor.Services
|
||||
@using PlaylistShared.Pwa.Components.Global
|
||||
@inherits LayoutComponentBase
|
||||
@inject PwaUpdateService PwaUpdateService
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ContextualActionBarService ContextualActionBarService
|
||||
@inject IBrowserViewportService BrowserViewportService
|
||||
@implements IBrowserViewportObserver
|
||||
|
||||
<MudThemeProvider Theme="@_theme" IsDarkMode="_isDarkMode" />
|
||||
<MudPopoverProvider />
|
||||
@@ -7,36 +13,49 @@
|
||||
<MudSnackbarProvider />
|
||||
|
||||
<MudLayout>
|
||||
<MudAppBar Elevation="1">
|
||||
<MudAppBar Elevation="1" Contextual Bottom = "@_actionBarBottom" Fixed>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@DrawerToggle" />
|
||||
<MudSpacer />
|
||||
<LoginDisplay />
|
||||
<MudIconButton Icon="@(DarkLightModeButtonIcon)" Color="Color.Inherit" OnClick="@DarkModeToggle" Class="ml-2" />
|
||||
<MudLink Href="https://git.frigat.duckdns.org/FrigaT/PlaylistShared" Target="_blank" Color="Color.Inherit" Underline="Underline.None" Class="ml-4">
|
||||
<MudIcon Icon="@Icons.Custom.Brands.GitHub" Size="Size.Small" Class="mr-1" /> Git
|
||||
</MudLink>
|
||||
@if (_actionBarContent != null)
|
||||
{
|
||||
@_actionBarContent
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSpacer />
|
||||
<LoginDisplay />
|
||||
<MudIconButton Icon="@(DarkLightModeButtonIcon)" Color="Color.Inherit" OnClick="@DarkModeToggle" Class="ml-2" />
|
||||
<MudLink Href="https://git.frigat.duckdns.org/FrigaT/PlaylistShared" Target="_blank" Color="Color.Inherit" Underline="Underline.None" Class="ml-4">
|
||||
<MudIcon Icon="@Icons.Custom.Brands.GitHub" Size="Size.Small" Class="mr-1" /> Git
|
||||
</MudLink>
|
||||
}
|
||||
</MudAppBar>
|
||||
|
||||
<MudDrawer @bind-Open="_drawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
|
||||
<MudDrawer @bind-Open="_drawerOpen" Class="@(_actionBarBottom ? " pt-0 pb-16" : "")" ClipMode="DrawerClipMode.Always" Elevation="2">
|
||||
<NavMenu />
|
||||
</MudDrawer>
|
||||
|
||||
<MudMainContent Class="pt-16 d-flex flex-column" Style="height: 100vh;">
|
||||
<MudItem Class="flex-grow-1 overflow-y-auto">
|
||||
@Body
|
||||
</MudItem>
|
||||
|
||||
<MudItem>
|
||||
<AudioPlayer />
|
||||
</MudItem>
|
||||
<MudMainContent Class="@("d-flex flex-column" + (_actionBarBottom ? " pt-0 pb-16" : ""))" Style="height: 100dvh;">
|
||||
@Body
|
||||
</MudMainContent>
|
||||
</MudLayout>
|
||||
|
||||
@code {
|
||||
private RenderFragment? _actionBarContent;
|
||||
private bool _actionBarBottom => _contextualPosition switch
|
||||
{
|
||||
ContextualActionBarPosition.Bottom => true,
|
||||
ContextualActionBarPosition.Top => false,
|
||||
_ => _isMobile,
|
||||
};
|
||||
private bool _isMobile = false;
|
||||
private ContextualActionBarPosition _contextualPosition = ContextualActionBarPosition.Default;
|
||||
|
||||
private bool _drawerOpen = true;
|
||||
private bool _isDarkMode = true;
|
||||
private MudTheme? _theme;
|
||||
|
||||
private DotNetObjectReference<PwaUpdateService>? _dotNetRef;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
@@ -47,6 +66,25 @@
|
||||
PaletteDark = _darkPalette,
|
||||
LayoutProperties = new LayoutProperties()
|
||||
};
|
||||
|
||||
ContextualActionBarService.OnChanged += OnContextualChangedHandler;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
_dotNetRef = DotNetObjectReference.Create(PwaUpdateService);
|
||||
await JSRuntime.InvokeVoidAsync("registerSWMessageHandler", _dotNetRef);
|
||||
await BrowserViewportService.SubscribeAsync(this, fireImmediately: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnContextualChangedHandler()
|
||||
{
|
||||
_actionBarContent = ContextualActionBarService.Content;
|
||||
_contextualPosition = ContextualActionBarService.Position;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void DrawerToggle()
|
||||
@@ -103,4 +141,21 @@
|
||||
true => Icons.Material.Rounded.AutoMode,
|
||||
false => Icons.Material.Outlined.DarkMode,
|
||||
};
|
||||
|
||||
|
||||
|
||||
Guid IBrowserViewportObserver.Id { get; } = Guid.NewGuid();
|
||||
|
||||
ResizeOptions IBrowserViewportObserver.ResizeOptions { get; } = new()
|
||||
{
|
||||
ReportRate = 250,
|
||||
NotifyOnBreakpointOnly = true
|
||||
};
|
||||
|
||||
Task IBrowserViewportObserver.NotifyBrowserViewportChangeAsync(BrowserViewportEventArgs browserViewportEventArgs)
|
||||
{
|
||||
_isMobile = browserViewportEventArgs.Breakpoint <= Breakpoint.Sm;
|
||||
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<MudCard>
|
||||
<MudCardContent Class="text-center">
|
||||
<MudText Typo="Typo.h5" Class="mb-4">Вход в PlaylistShared</MudText>
|
||||
|
||||
@*
|
||||
<MudText Typo="Typo.body2" Class="mb-6">
|
||||
Войдите через учётную запись Keycloak или используйте локальный аккаунт.
|
||||
</MudText>
|
||||
@@ -22,7 +22,7 @@
|
||||
</MudButton>
|
||||
|
||||
<MudDivider Class="my-4">или</MudDivider>
|
||||
|
||||
*@
|
||||
<!-- Локальная форма входа -->
|
||||
<MudTextField @bind-Value="_loginModel.Username" Label="Имя пользователя" Variant="Variant.Outlined" FullWidth="true" Class="mb-3" />
|
||||
<MudTextField @bind-Value="_loginModel.Password" Label="Пароль" Variant="Variant.Outlined" FullWidth="true" InputType="InputType.Password" @bind-Value:after="LocalLogin" />
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
@attribute [Authorize]
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@using PlaylistShared.Shared.Playlist
|
||||
@using PlaylistShared.Shared.SharedPlaylist
|
||||
@using PlaylistShared.Shared.Yandex
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
@@ -70,11 +71,11 @@
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private List<YandexPlaylistInfo> _playlists;
|
||||
private List<YandexPlaylistShare> _playlists;
|
||||
private bool _loading = true;
|
||||
private bool _showOnlyShared = false;
|
||||
|
||||
private List<YandexPlaylistInfo> FilteredPlaylists => _showOnlyShared ? _playlists?.Where(p => p.IsShared).ToList() : _playlists;
|
||||
private List<YandexPlaylistShare> FilteredPlaylists => _showOnlyShared ? _playlists?.Where(p => p.IsShared).ToList() : _playlists;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -86,7 +87,7 @@
|
||||
_loading = true;
|
||||
try
|
||||
{
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<List<YandexPlaylistInfo>>>("/api/playlists");
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<List<YandexPlaylistShare>>>("/api/playlists");
|
||||
if (response?.Success == true)
|
||||
_playlists = response.Data;
|
||||
else
|
||||
@@ -103,7 +104,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SharePlaylist(YandexPlaylistInfo playlist)
|
||||
private async Task SharePlaylist(YandexPlaylistShare playlist)
|
||||
{
|
||||
var request = new SharePlaylistRequest { Kind = playlist.Kind, OwnerUid = playlist.OwnerUid };
|
||||
var response = await Http.PostAsJsonAsync("/api/playlists/share", request);
|
||||
@@ -118,7 +119,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void GoToShared(YandexPlaylistInfo playlist)
|
||||
private void GoToShared(YandexPlaylistShare playlist)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(playlist.ShareToken))
|
||||
Navigation.NavigateTo($"/shared/{playlist.ShareToken}");
|
||||
|
||||
@@ -1,103 +1,88 @@
|
||||
@page "/profile"
|
||||
<PageTitle>Профиль - Playlist Share</PageTitle>
|
||||
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using PlaylistShared.Pwa.Components.Profile
|
||||
@using PlaylistShared.Shared.DTO
|
||||
@attribute [Authorize]
|
||||
@inject HttpClient Http
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@using PlaylistShared.Pwa.Components.Profile.YandexAccount
|
||||
@using PlaylistShared.Shared.Profile
|
||||
|
||||
<PageTitle>Профиль</PageTitle>
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Small" Class="mt-8">
|
||||
<MudCard>
|
||||
<MudCardHeader>
|
||||
<CardHeaderContent>
|
||||
<MudText Typo="Typo.h5">Личный кабинет</MudText>
|
||||
</CardHeaderContent>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<MudStack Row Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Class="mb-4">
|
||||
<MudText Typo="Typo.body2">
|
||||
Здесь вы можете указать токен доступа к Яндекс.Музыке.
|
||||
</MudText>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.HelpOutline"
|
||||
Color="Color.Info"
|
||||
OnClick="() => _instructionDrawerOpen = true"
|
||||
Title="Как получить токен?" />
|
||||
</MudStack>
|
||||
<MudText Typo="Typo.h4" Class="mb-6">Профиль</MudText>
|
||||
|
||||
<MudTextField @bind-Value="_token" Label="Токен Яндекс.Музыки" Variant="Variant.Outlined" FullWidth="true" />
|
||||
<MudStack Spacing="4">
|
||||
@*
|
||||
<!-- Секция почты -->
|
||||
<MudCard>
|
||||
<MudCardContent>
|
||||
<MudText Typo="Typo.h6" GutterBottom="true">Данные аккаунта</MudText>
|
||||
<MudTextField @bind-Value="_email" Label="Электронная почта" ReadOnly="true" Variant="Variant.Outlined" Margin="Margin.Dense" />
|
||||
<MudButton Variant="Variant.Text" Color="Color.Primary" Class="mt-2" Disabled="true">Сменить почту</MudButton>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
*@
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveToken" Class="mt-4" FullWidth="true">
|
||||
Сохранить токен
|
||||
</MudButton>
|
||||
|
||||
<MudText Class="mt-4" Typo="Typo.body2">Статус: @_statusText</MudText>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
<!-- Секция Яндекс.Музыки -->
|
||||
<MudCard>
|
||||
<MudCardContent>
|
||||
<MudStack Row Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
|
||||
<MudStack Spacing="0">
|
||||
<MudText Typo="Typo.h6">Яндекс.Музыка</MudText>
|
||||
<MudText Typo="Typo.body2" Color="@(_hasToken? Color.Success: Color.Error)">
|
||||
@_statusText
|
||||
</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudMenu EndIcon="@Icons.Material.Filled.ArrowDropDown"
|
||||
Label="@(_hasToken ? "Переподключить" : "Подключить")"
|
||||
Variant="Variant.Outlined"
|
||||
Dense
|
||||
Color="Color.Primary">
|
||||
<MudMenuItem OnClick="OpenTokenDialog">Token</MudMenuItem>
|
||||
<MudMenuItem OnClick="OpenQrServerDialog">QR</MudMenuItem>
|
||||
</MudMenu>
|
||||
</MudStack>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
</MudStack>
|
||||
</MudContainer>
|
||||
|
||||
<!-- Выдвижная панель с инструкцией -->
|
||||
<MudDrawer @bind-Open="_instructionDrawerOpen"
|
||||
Anchor="Anchor.Right"
|
||||
Variant="DrawerVariant.Temporary"
|
||||
Elevation="3"
|
||||
Width="500px"
|
||||
MiniWidth="0px">
|
||||
<MudDrawerHeader>
|
||||
<MudText Typo="Typo.h6">Как получить токен Яндекс.Музыки</MudText>
|
||||
</MudDrawerHeader>
|
||||
<MudDivider />
|
||||
<YandexTokenInstructions />
|
||||
</MudDrawer>
|
||||
|
||||
@code {
|
||||
private string _token = "";
|
||||
private string _email = "user@example.com";
|
||||
private string _statusText = "Загрузка...";
|
||||
private bool _instructionDrawerOpen = false;
|
||||
private bool _hasToken;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadStatus();
|
||||
}
|
||||
protected override async Task OnInitializedAsync() => await LoadStatus();
|
||||
|
||||
private async Task LoadStatus()
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<YandexTokenStatus>>("/api/yandextoken/status");
|
||||
var response = await Http.GetFromJsonAsync<ApiResponse<YandexTokenStatus>>("/api/yandexaccount/status");
|
||||
if (response?.Success == true)
|
||||
{
|
||||
_statusText = response.Data.HasToken
|
||||
? $"Токен установлен{(response.Data.IsValid ? "" : " (просрочен)")}"
|
||||
: "Токен не установлен";
|
||||
_hasToken = response.Data.HasToken;
|
||||
_statusText = _hasToken ? "Аккаунт подключен" : "Аккаунт не подключен";
|
||||
}
|
||||
}
|
||||
catch { _statusText = "Не удалось загрузить статус"; }
|
||||
catch { _statusText = "Ошибка загрузки статуса"; }
|
||||
}
|
||||
|
||||
private async Task SaveToken()
|
||||
private async Task OpenTokenDialog()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_token))
|
||||
{
|
||||
Snackbar.Add("Введите токен", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true };
|
||||
var dialog = await DialogService.ShowAsync<YandexTokenDialog>("", options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
var request = new SetYandexTokenRequest { Token = _token };
|
||||
var response = await Http.PostAsJsonAsync("/api/yandextoken/set", request);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
Snackbar.Add("Токен сохранён", Severity.Success);
|
||||
await LoadStatus();
|
||||
_token = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("Ошибка сохранения токена", Severity.Error);
|
||||
}
|
||||
if (!result.Canceled) await LoadStatus();
|
||||
}
|
||||
|
||||
public class YandexTokenStatus { public bool HasToken { get; set; } public bool IsValid { get; set; } }
|
||||
public class SetYandexTokenRequest { public string Token { get; set; } }
|
||||
}
|
||||
private async Task OpenQrServerDialog()
|
||||
{
|
||||
var options = new DialogOptions { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, FullWidth = true };
|
||||
var dialog = await DialogService.ShowAsync<YandexQrServerDialog>("", options);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (!result.Canceled) await LoadStatus();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,9 @@
|
||||
<Content Update="wwwroot\js\AudioPlayer.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="wwwroot\js\shareUtils.js">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -20,10 +20,12 @@ internal class Program
|
||||
return new HttpClient { BaseAddress = new Uri(apiUrl) };
|
||||
});
|
||||
|
||||
builder.Services.AddScoped<PwaUpdateService>();
|
||||
builder.Services.AddScoped<TokenStorage>();
|
||||
builder.Services.AddScoped<PlayerStorage>();
|
||||
builder.Services.AddScoped<AuthStateProvider>();
|
||||
builder.Services.AddScoped<AuthenticationStateProvider>(sp => sp.GetRequiredService<AuthStateProvider>());
|
||||
builder.Services.AddScoped<ContextualActionBarService>();
|
||||
builder.Services.AddScoped<ApiClient>();
|
||||
builder.Services.AddScoped<IAudioPlayerService, AudioPlayerService>();
|
||||
|
||||
|
||||
@@ -10,6 +10,23 @@
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
|
||||
"https (silent)": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://localhost:7225;http://localhost:5181",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
|
||||
"https (prod)": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
|
||||
"applicationUrl": "https://localhost:7225;http://localhost:5181"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.SharedPlaylist;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace PlaylistShared.Pwa.Services.Api;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using MudBlazor;
|
||||
using PlaylistShared.Shared;
|
||||
using PlaylistShared.Shared.DTO;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace PlaylistShared.Pwa.Services;
|
||||
@@ -10,19 +10,20 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
private readonly TokenStorage _tokenStorage;
|
||||
private readonly ISnackbar _snackbar;
|
||||
private readonly HttpClient _http;
|
||||
private readonly PlayerStorage _playerStorage;
|
||||
|
||||
private string? _currentTrackId;
|
||||
private string? _currentTrackTitle;
|
||||
private string? _currentTrackCoverUrl;
|
||||
private YandexTrack? _currentTrack;
|
||||
private bool _isPlaying;
|
||||
private double _currentVolume = 70;
|
||||
private double _currentVolume = 50;
|
||||
private double _currentProgress;
|
||||
private string _currentTime = "0:00";
|
||||
private string _totalTime = "0:00";
|
||||
private double _currentTime = 0;
|
||||
private double _totalTime = 0;
|
||||
private string _currentTimeString = "0:00";
|
||||
private string _totalTimeString = "0:00";
|
||||
|
||||
public string? CurrentTrackId => _currentTrackId;
|
||||
public string? CurrentTrackTitle => _currentTrackTitle;
|
||||
public string? CurrentTrackCoverUrl => _currentTrackCoverUrl;
|
||||
public YandexTrack? CurrentTrack => _currentTrack;
|
||||
public bool IsPlaying => _isPlaying;
|
||||
public double CurrentVolume
|
||||
{
|
||||
@@ -34,21 +35,46 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
}
|
||||
}
|
||||
public double CurrentProgress => _currentProgress;
|
||||
public string CurrentTime => _currentTime;
|
||||
public string TotalTime => _totalTime;
|
||||
public double CurrentTime => _currentTime;
|
||||
public double TotalTime => _totalTime;
|
||||
public string CurrentTimeString => _currentTimeString;
|
||||
public string TotalTimeString => _totalTimeString;
|
||||
|
||||
public event Action? OnStateChanged;
|
||||
public event Action? OnStartedTrack;
|
||||
public event Action? OnEndedTrack;
|
||||
|
||||
public AudioPlayerService(TokenStorage tokenStorage, ISnackbar snackbar, HttpClient httpClient)
|
||||
public AudioPlayerService(TokenStorage tokenStorage, ISnackbar snackbar, HttpClient httpClient, PlayerStorage playerStorage)
|
||||
{
|
||||
_tokenStorage = tokenStorage;
|
||||
_snackbar = snackbar;
|
||||
_http = httpClient;
|
||||
_playerStorage = playerStorage;
|
||||
|
||||
_ = LoadVolume();
|
||||
}
|
||||
|
||||
private async Task LoadVolume()
|
||||
{
|
||||
var savedVolume = await _playerStorage.GetVolumeAsync();
|
||||
|
||||
if (savedVolume != null)
|
||||
{
|
||||
_currentVolume = savedVolume.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// Внешние команды (вызываются из компонентов)
|
||||
public async Task LoadAndPlayAsync(string trackId, string? accessToken = null, string? playlistShareToken = null, string? title = null, string? coverUrl = null)
|
||||
public async Task LoadAndPlayAsync(string trackId, string? accessToken = null, string? playlistShareToken = null, YandexTrack? track = null)
|
||||
{
|
||||
if (_currentTrackId == trackId)
|
||||
{
|
||||
await PlayAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
_currentTrackId = trackId;
|
||||
|
||||
// Если accessToken не передан, пытаемся получить его из хранилища
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
@@ -64,13 +90,11 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
}
|
||||
|
||||
// Если title и coverUrl не переданы, нужно запросить через API
|
||||
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(coverUrl))
|
||||
if (track is null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var trackInfo = await GetTrackInfo(trackId, accessToken, playlistShareToken);
|
||||
title = trackInfo?.Title;
|
||||
coverUrl = trackInfo?.CoverUri;
|
||||
track = await GetTrackInfo(trackId, accessToken, playlistShareToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -79,12 +103,11 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
}
|
||||
}
|
||||
|
||||
_currentTrackId = trackId;
|
||||
_currentTrackTitle = title ?? "Неизвестный трек";
|
||||
_currentTrackCoverUrl = coverUrl;
|
||||
_currentTrack = track;
|
||||
_isPlaying = true;
|
||||
OnStateChanged?.Invoke();
|
||||
OnLoadAndPlayRequested?.Invoke(trackId, accessToken, playlistShareToken);
|
||||
OnStartedTrack?.Invoke();
|
||||
}
|
||||
|
||||
public async Task PlayAsync()
|
||||
@@ -92,6 +115,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
_isPlaying = true;
|
||||
OnStateChanged?.Invoke();
|
||||
OnPlayRequested?.Invoke();
|
||||
OnStartedTrack?.Invoke();
|
||||
}
|
||||
|
||||
public async Task PauseAsync()
|
||||
@@ -101,19 +125,9 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
OnPauseRequested?.Invoke();
|
||||
}
|
||||
|
||||
public async Task StopAsync()
|
||||
public async Task SeekToAsync(double second)
|
||||
{
|
||||
_isPlaying = false;
|
||||
_currentTrackId = null;
|
||||
_currentProgress = 0;
|
||||
_currentTime = "0:00";
|
||||
OnStateChanged?.Invoke();
|
||||
OnStopRequested?.Invoke();
|
||||
}
|
||||
|
||||
public async Task SeekToAsync(double percent)
|
||||
{
|
||||
OnSeekRequested?.Invoke(percent);
|
||||
OnSeekRequested?.Invoke(second);
|
||||
}
|
||||
|
||||
public async Task SetVolumeAsync(double volume)
|
||||
@@ -121,13 +135,13 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
_currentVolume = volume;
|
||||
OnStateChanged?.Invoke();
|
||||
OnVolumeChangeRequested?.Invoke(volume);
|
||||
await _playerStorage.SetVolumeAsync(volume);
|
||||
}
|
||||
|
||||
// События для связи с реальным AudioPlayer компонентом
|
||||
public event Func<string, string?, string?, Task>? OnLoadAndPlayRequested;
|
||||
public event Func<Task>? OnPlayRequested;
|
||||
public event Func<Task>? OnPauseRequested;
|
||||
public event Func<Task>? OnStopRequested;
|
||||
public event Func<double, Task>? OnSeekRequested;
|
||||
public event Func<double, Task>? OnVolumeChangeRequested;
|
||||
|
||||
@@ -144,11 +158,14 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
OnStateChanged?.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateProgress(double progress, string currentTime, string totalTime)
|
||||
public void UpdateProgress(double currentTime, double totalTime)
|
||||
{
|
||||
var progress = (currentTime / totalTime) * 100;
|
||||
_currentProgress = progress;
|
||||
_currentTime = currentTime;
|
||||
_currentTimeString = FormatDuration(currentTime);
|
||||
_totalTime = totalTime;
|
||||
_totalTimeString = FormatDuration(totalTime);
|
||||
OnStateChanged?.Invoke();
|
||||
}
|
||||
|
||||
@@ -157,8 +174,12 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
_isPlaying = false;
|
||||
_currentTrackId = null;
|
||||
_currentProgress = 0;
|
||||
_currentTime = "0:00";
|
||||
_currentTime = 0;
|
||||
_currentTimeString = "0:00";
|
||||
_totalTime = 0;
|
||||
_currentTimeString = "0:00";
|
||||
OnStateChanged?.Invoke();
|
||||
OnEndedTrack?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,7 +189,7 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
/// <param name="accessToken"></param>
|
||||
/// <param name="sharedPlaylistId"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<(string? Title, string? CoverUri)?> GetTrackInfo(string trackId, string? accessToken, string? sharedPlaylistId)
|
||||
private async Task<YandexTrack?> GetTrackInfo(string trackId, string? accessToken, string? sharedPlaylistId)
|
||||
{
|
||||
var url = $"/api/audio/track-info/{trackId}";
|
||||
if (!string.IsNullOrEmpty(accessToken))
|
||||
@@ -179,8 +200,15 @@ public class AudioPlayerService : IAudioPlayerService
|
||||
var response = await _http.GetFromJsonAsync<ApiResponse<YandexTrack>>(url);
|
||||
if (response?.Success == true)
|
||||
{
|
||||
return (response.Data.Title, response.Data.CoverUri);
|
||||
return response.Data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private string FormatDuration(double seconds)
|
||||
{
|
||||
var mins = (int)(seconds / 60);
|
||||
var secs = (int)(seconds % 60);
|
||||
return $"{mins}:{secs:D2}";
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
||||
private readonly HttpClient _http;
|
||||
private Timer? _refreshTimer;
|
||||
private ClaimsPrincipal _currentUser = new(new ClaimsIdentity());
|
||||
private string? _currentToken;
|
||||
private string? _currentRefreshToken;
|
||||
|
||||
public AuthStateProvider(TokenStorage tokenStorage, ApiClient apiClient, HttpClient http)
|
||||
{
|
||||
@@ -26,14 +28,59 @@ public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
||||
if (string.IsNullOrEmpty(token))
|
||||
return new AuthenticationState(_currentUser);
|
||||
|
||||
var principal = ParseToken(token);
|
||||
if (principal == null)
|
||||
return new AuthenticationState(_currentUser);
|
||||
var (isValid, principal) = await ValidateTokenAsync(token);
|
||||
if (isValid && principal != null)
|
||||
{
|
||||
_currentUser = principal;
|
||||
_currentToken = token;
|
||||
_currentRefreshToken = refreshToken;
|
||||
_http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
ScheduleTokenRefresh(token, refreshToken);
|
||||
return new AuthenticationState(principal);
|
||||
}
|
||||
|
||||
_currentUser = principal;
|
||||
_http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
ScheduleTokenRefresh(token, refreshToken);
|
||||
return new AuthenticationState(principal);
|
||||
// Токен невалиден – пробуем обновить
|
||||
if (!string.IsNullOrEmpty(refreshToken))
|
||||
{
|
||||
var newTokenResponse = await _apiClient.RefreshTokenAsync(refreshToken);
|
||||
if (newTokenResponse != null && !string.IsNullOrEmpty(newTokenResponse.Token))
|
||||
{
|
||||
await MarkUserAsAuthenticated(newTokenResponse.Token, newTokenResponse.RefreshToken);
|
||||
// После MarkUserAsAuthenticated состояние обновится через NotifyAuthenticationStateChanged,
|
||||
// но текущий вызов всё равно должен вернуть нового пользователя
|
||||
var (newIsValid, newPrincipal) = await ValidateTokenAsync(newTokenResponse.Token);
|
||||
if (newIsValid && newPrincipal != null)
|
||||
return new AuthenticationState(newPrincipal);
|
||||
}
|
||||
}
|
||||
|
||||
// Всё плохо — логаут
|
||||
await MarkUserAsLoggedOut();
|
||||
return new AuthenticationState(_currentUser);
|
||||
}
|
||||
|
||||
// Вспомогательный метод проверки валидности токена (включая срок)
|
||||
private async Task<(bool IsValid, ClaimsPrincipal? Principal)> ValidateTokenAsync(string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwt = handler.ReadJwtToken(token);
|
||||
|
||||
// Проверяем, не истёк ли токен
|
||||
if (jwt.ValidTo < DateTime.UtcNow)
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
var identity = new ClaimsIdentity(jwt.Claims, "jwt");
|
||||
var principal = new ClaimsPrincipal(identity);
|
||||
return (true, principal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MarkUserAsAuthenticated(string token, string refreshToken)
|
||||
@@ -41,6 +88,8 @@ public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
||||
await _tokenStorage.SetTokensAsync(token, refreshToken);
|
||||
var principal = ParseToken(token);
|
||||
_currentUser = principal ?? new ClaimsPrincipal(new ClaimsIdentity());
|
||||
_currentToken = token;
|
||||
_currentRefreshToken = refreshToken;
|
||||
_http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
||||
}
|
||||
@@ -49,10 +98,51 @@ public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
||||
{
|
||||
await _tokenStorage.ClearTokensAsync();
|
||||
_currentUser = new ClaimsPrincipal(new ClaimsIdentity());
|
||||
_currentToken = null;
|
||||
_currentRefreshToken = null;
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
_refreshTimer?.Dispose();
|
||||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
||||
}
|
||||
|
||||
public async Task<string?> TryRefreshTokenAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentRefreshToken))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
var newToken = await _apiClient.RefreshTokenAsync(_currentRefreshToken);
|
||||
if (newToken != null && !string.IsNullOrEmpty(newToken.Token))
|
||||
{
|
||||
await MarkUserAsAuthenticated(newToken.Token, newToken.RefreshToken);
|
||||
return newToken.Token;
|
||||
}
|
||||
else
|
||||
{
|
||||
await MarkUserAsLoggedOut();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
await MarkUserAsLoggedOut();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTokenExpiringSoon()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentToken))
|
||||
return false;
|
||||
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwt = handler.ReadJwtToken(_currentToken);
|
||||
var expiresAt = jwt.ValidTo;
|
||||
var timeToExpiry = expiresAt - DateTime.UtcNow;
|
||||
return timeToExpiry < TimeSpan.FromMinutes(1);
|
||||
}
|
||||
|
||||
private ClaimsPrincipal? ParseToken(string token)
|
||||
{
|
||||
try
|
||||
@@ -62,7 +152,7 @@ public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
||||
var identity = new ClaimsIdentity(jwt.Claims, "jwt");
|
||||
return new ClaimsPrincipal(identity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -81,18 +171,7 @@ public class AuthStateProvider : AuthenticationStateProvider, IDisposable
|
||||
_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();
|
||||
}
|
||||
await TryRefreshTokenAsync();
|
||||
}, null, (int)refreshTime.TotalMilliseconds, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
|
||||
25
PlaylistShared.Pwa/Services/ContextualActionBarService.cs
Normal file
25
PlaylistShared.Pwa/Services/ContextualActionBarService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace PlaylistShared.Pwa.Services;
|
||||
|
||||
public class ContextualActionBarService
|
||||
{
|
||||
// Событие, которое будет вызываться при изменении содержимого панели
|
||||
public event Action? OnChanged;
|
||||
|
||||
public RenderFragment? Content { get; set; } = null;
|
||||
|
||||
public ContextualActionBarPosition Position { get; set; } = ContextualActionBarPosition.Default;
|
||||
|
||||
public void ChangeParameters()
|
||||
{
|
||||
OnChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ContextualActionBarPosition
|
||||
{
|
||||
Default,
|
||||
Top,
|
||||
Bottom,
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace PlaylistShared.Pwa.Services;
|
||||
using PlaylistShared.Shared.Yandex;
|
||||
|
||||
namespace PlaylistShared.Pwa.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Глобальный сервис управления аудиоплеером.
|
||||
@@ -19,17 +21,20 @@ public interface IAudioPlayerService
|
||||
/// <summary>Прогресс воспроизведения в процентах (0–100).</summary>
|
||||
double CurrentProgress { get; }
|
||||
|
||||
/// <summary>Текущее время в секундах.</summary>
|
||||
double CurrentTime { get; }
|
||||
|
||||
/// <summary>Общая длительность в секундах</summary>
|
||||
double TotalTime { get; }
|
||||
|
||||
/// <summary>Отформатированное текущее время (мм:сс).</summary>
|
||||
string CurrentTime { get; }
|
||||
string CurrentTimeString { get; }
|
||||
|
||||
/// <summary>Отформатированная общая длительность (мм:сс).</summary>
|
||||
string TotalTime { get; }
|
||||
string TotalTimeString { get; }
|
||||
|
||||
/// <summary>Отформатированное название текущего трека.</summary>
|
||||
string? CurrentTrackTitle { get; }
|
||||
|
||||
/// <summary>URL обложки текущего трека.</summary>
|
||||
string? CurrentTrackCoverUrl { get; }
|
||||
/// <summary>Текущий трек.</summary>
|
||||
YandexTrack? CurrentTrack { get; }
|
||||
#endregion
|
||||
|
||||
#region Команды управления (вызываются из компонентов)
|
||||
@@ -39,7 +44,7 @@ public interface IAudioPlayerService
|
||||
/// <param name="sharedPlaylistId">ID расшаренного плейлиста (для неавторизованного доступа).</param>
|
||||
/// <param name="title">Название трека. (Если не передано, вызывает api для получения)</param>
|
||||
/// <param name="coverUrl">URL обложки трека. (Если не передано, вызывает api для получения)</param>
|
||||
Task LoadAndPlayAsync(string trackId, string? accessToken = null, string? playlistShareToken = null, string? title = null, string? coverUrl = null);
|
||||
Task LoadAndPlayAsync(string trackId, string? accessToken = null, string? playlistShareToken = null, YandexTrack? track = null);
|
||||
|
||||
/// <summary>Воспроизвести (если трек загружен и на паузе).</summary>
|
||||
Task PlayAsync();
|
||||
@@ -47,11 +52,8 @@ public interface IAudioPlayerService
|
||||
/// <summary>Поставить на паузу.</summary>
|
||||
Task PauseAsync();
|
||||
|
||||
/// <summary>Остановить воспроизведение и выгрузить трек.</summary>
|
||||
Task StopAsync();
|
||||
|
||||
/// <summary>Перемотать на указанный процент (0–100).</summary>
|
||||
Task SeekToAsync(double percent);
|
||||
/// <summary>Перемотать на секунды.</summary>
|
||||
Task SeekToAsync(double second);
|
||||
|
||||
/// <summary>Установить громкость (0–100).</summary>
|
||||
Task SetVolumeAsync(double volume);
|
||||
@@ -64,6 +66,10 @@ public interface IAudioPlayerService
|
||||
/// Подписывайтесь на него, чтобы перерисовывать UI (например, иконку "пауза/плей").
|
||||
/// </summary>
|
||||
event Action? OnStateChanged;
|
||||
|
||||
event Action? OnStartedTrack;
|
||||
|
||||
event Action? OnEndedTrack;
|
||||
#endregion
|
||||
|
||||
#region События для связи с реальным компонентом AudioPlayer (Эти события вызываются сервисом)
|
||||
@@ -76,10 +82,7 @@ public interface IAudioPlayerService
|
||||
/// <summary>Запрос на паузу.</summary>
|
||||
event Func<Task>? OnPauseRequested;
|
||||
|
||||
/// <summary>Запрос на остановку и выгрузку трека.</summary>
|
||||
event Func<Task>? OnStopRequested;
|
||||
|
||||
/// <summary>Запрос на перемотку (процент 0–100).</summary>
|
||||
/// <summary>Запрос на перемотку (секунды).</summary>
|
||||
event Func<double, Task>? OnSeekRequested;
|
||||
|
||||
/// <summary>Запрос на изменение громкости (0–100).</summary>
|
||||
@@ -94,7 +97,7 @@ public interface IAudioPlayerService
|
||||
void SetCurrentTrack(string? trackId);
|
||||
|
||||
/// <summary>Обновить прогресс и отображаемое время.</summary>
|
||||
void UpdateProgress(double progress, string currentTime, string totalTime);
|
||||
void UpdateProgress(double currentTime, double totalTime);
|
||||
|
||||
/// <summary>Уведомить об окончании трека.</summary>
|
||||
void NotifyTrackEnded();
|
||||
|
||||
33
PlaylistShared.Pwa/Services/PwaUpdateService.cs
Normal file
33
PlaylistShared.Pwa/Services/PwaUpdateService.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.JSInterop;
|
||||
using MudBlazor;
|
||||
|
||||
namespace PlaylistShared.Pwa.Services;
|
||||
|
||||
public class PwaUpdateService
|
||||
{
|
||||
private readonly ISnackbar _snackbar;
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
|
||||
public PwaUpdateService(ISnackbar snackbar, IJSRuntime jsRuntime)
|
||||
{
|
||||
_snackbar = snackbar;
|
||||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnNewVersionAvailable()
|
||||
{
|
||||
_snackbar.Add("Доступна новая версия! Обновите страницу.", Severity.Info, configure: options =>
|
||||
{
|
||||
options.Action = "Обновить";
|
||||
options.ShowCloseIcon = false;
|
||||
options.RequireInteraction = true;
|
||||
options.OnClick = _ =>
|
||||
{
|
||||
_jsRuntime.InvokeVoidAsync("location.reload", true);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
options.CloseAfterNavigation = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,12 @@ events {
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Не раскрывайть версию Nginx в ответах.
|
||||
server_tokens off;
|
||||
|
||||
# Ограничение запросов от одного IP‑адреса, чтобы предотвратить DDoS‑атаки и злоупотребление ресурсами.
|
||||
limit_req_zone $binary_remote_addr zone=one:10m rate=60r/s;
|
||||
|
||||
# Сжатие
|
||||
gzip on;
|
||||
@@ -20,6 +26,8 @@ http {
|
||||
|
||||
# Для Service Worker – запрещаем кэширование, чтобы он всегда был свежим
|
||||
location = /service-worker.js {
|
||||
etag off;
|
||||
add_header Last-Modified "";
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
@@ -28,6 +36,8 @@ http {
|
||||
|
||||
# Для файла манифеста Service Worker assets – тоже не кэшируем
|
||||
location = /service-worker-assets.js {
|
||||
etag off;
|
||||
add_header Last-Modified "";
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
@@ -36,6 +46,8 @@ http {
|
||||
|
||||
# Для файла index.html – тоже не кэшируем
|
||||
location = /index.html {
|
||||
etag off;
|
||||
add_header Last-Modified "";
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
|
||||
@@ -109,41 +109,19 @@ code {
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
.track-cover-container {
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
transition: transform 0.2s ease;
|
||||
/* Горизонтальный скролинг */
|
||||
.horizontal-scroll {
|
||||
overflow-x: auto;
|
||||
scroll-snap-type: x mandatory;
|
||||
overflow-y: hidden; /* отключаем вертикальный скролл */
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.track-cover-container:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.play-overlay {
|
||||
transition: opacity 0.2s ease;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Фиксированный плеер внизу */
|
||||
.fixed-player {
|
||||
position: sticky;
|
||||
display: flex;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
right: 0;
|
||||
justify-content: center;
|
||||
background-color: var(--mud-palette-background);
|
||||
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Отступ снизу, когда плеер виден */
|
||||
.page-with-player {
|
||||
padding-bottom: 80px; /* Высота плеера (подберите под свою тему) */
|
||||
}
|
||||
|
||||
/* На мобильных устройствах можно уменьшить отступ */
|
||||
@media (max-width: 600px) {
|
||||
.page-with-player {
|
||||
padding-bottom: 100px; /* если плеер выше на мобильных */
|
||||
.horizontal-scroll:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
/* Для WebKit (Chrome, Edge, Safari) можно включить горизонтальный скролл мышью */
|
||||
.horizontal-scroll {
|
||||
scrollbar-width: thin;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
@@ -168,6 +168,15 @@
|
||||
<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>
|
||||
<script>
|
||||
function registerSWMessageHandler(dotNetHelper) {
|
||||
navigator.serviceWorker.addEventListener('message', event => {
|
||||
if (event.data && event.data.type === 'SW_ACTIVATED') {
|
||||
dotNetHelper.invokeMethodAsync('OnNewVersionAvailable');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -26,14 +26,13 @@
|
||||
const stop = () => { audio.pause(); audio.currentTime = 0; };
|
||||
const setVolume = (volume) => { audio.volume = toNumber(volume); };
|
||||
const setCurrentTime = (time) => { audio.currentTime = toNumber(time); };
|
||||
const getDuration = () => durationReady ? durationValue : 0;
|
||||
const getCurrentTime = () => toNumber(audio.currentTime);
|
||||
|
||||
audio.addEventListener('loadedmetadata', () => {
|
||||
const current = toNumber(audio.currentTime);
|
||||
durationValue = toNumber(audio.duration);
|
||||
durationReady = durationValue > 0;
|
||||
if (dotNetHelper && durationReady) {
|
||||
dotNetHelper.invokeMethodAsync('OnDurationReady', durationValue);
|
||||
dotNetHelper.invokeMethodAsync('OnTimeUpdate', current, durationValue);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,6 +49,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
audio.addEventListener('progress', () => {
|
||||
if (dotNetHelper) {
|
||||
if (audio.buffered.length > 0 && audio.duration) {
|
||||
const bufferedEnd = toNumber(audio.buffered.end(audio.buffered.length - 1));
|
||||
dotNetHelper.invokeMethodAsync('OnDownloadProgress', bufferedEnd);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Возвращаем все методы, которые будут вызываться из C#
|
||||
return { loadAndPlay, play, pause, stop, setVolume, setCurrentTime, getDuration, getCurrentTime };
|
||||
return { loadAndPlay, play, pause, stop, setVolume, setCurrentTime };
|
||||
}
|
||||
19
PlaylistShared.Pwa/wwwroot/js/shareUtils.js
Normal file
19
PlaylistShared.Pwa/wwwroot/js/shareUtils.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export function isSupported() {
|
||||
return !!navigator.share;
|
||||
}
|
||||
|
||||
export async function shareLink(title, text, url) {
|
||||
if (!navigator.share) {
|
||||
return { success: false, error: 'Web Share API не поддерживается' };
|
||||
}
|
||||
try {
|
||||
await navigator.share({ title, text, url });
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
if (error.name === 'AbortError') {
|
||||
return { success: false, cancelled: true };
|
||||
}
|
||||
console.error('Ошибка при шеринге:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,15 @@
|
||||
"short_name": "PlaylistShare",
|
||||
"id": "./",
|
||||
"start_url": "./",
|
||||
"scope": "/",
|
||||
"handle_links": "preferred",
|
||||
"display": "standalone",
|
||||
"background_color": "#1a1a27",
|
||||
"theme_color": "#7e6fff",
|
||||
"theme_color": "#1a1a27",
|
||||
"launch_handler": {
|
||||
"client_mode": "focus-existing"
|
||||
},
|
||||
|
||||
"prefer_related_applications": false,
|
||||
"icons": [
|
||||
{
|
||||
|
||||
@@ -8,20 +8,17 @@ 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$/ ];
|
||||
const offlineAssetsInclude = [/\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/, /\.webmanifest$/];
|
||||
// ИСКЛЮЧАЕМ также service-worker-assets.js
|
||||
const offlineAssetsExclude = [/^service-worker\.js$/, /\/service-worker-assets\.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');
|
||||
|
||||
self.skipWaiting();
|
||||
|
||||
// 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)))
|
||||
@@ -30,10 +27,14 @@ async function onInstall(event) {
|
||||
}
|
||||
|
||||
async function onActivate(event) {
|
||||
console.info('Service worker: Activate');
|
||||
|
||||
await self.clients.claim();
|
||||
|
||||
// НОВОЕ: Уведомляем все открытые вкладки о том, что новый SW активирован
|
||||
const clientsList = await self.clients.matchAll();
|
||||
clientsList.forEach(client => {
|
||||
client.postMessage({ type: 'SW_ACTIVATED', version: self.assetsManifest.version });
|
||||
});
|
||||
|
||||
// Delete unused caches
|
||||
const cacheKeys = await caches.keys();
|
||||
await Promise.all(cacheKeys
|
||||
@@ -42,13 +43,16 @@ async function onActivate(event) {
|
||||
}
|
||||
|
||||
async function onFetch(event) {
|
||||
// НОВОЕ: никогда не перехватываем файлы Service Worker
|
||||
const url = event.request.url;
|
||||
if (url.includes('/service-worker.js') || url.includes('/service-worker-assets.js')) {
|
||||
return fetch(event.request);
|
||||
}
|
||||
|
||||
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);
|
||||
&& !manifestUrlList.some(u => u === event.request.url);
|
||||
|
||||
const request = shouldServeIndexHtml ? 'index.html' : event.request;
|
||||
const cache = await caches.open(cacheName);
|
||||
@@ -56,4 +60,4 @@ async function onFetch(event) {
|
||||
}
|
||||
|
||||
return cachedResponse || fetch(event.request);
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,5 @@ public enum TrackSearchType
|
||||
Album,
|
||||
Playlist,
|
||||
Track,
|
||||
}
|
||||
MyPlaylists,
|
||||
}
|
||||
|
||||
12
PlaylistShared.Shared/Enums/YandexAuthQrStatus.cs
Normal file
12
PlaylistShared.Shared/Enums/YandexAuthQrStatus.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Enums;
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum YandexAuthQrStatus
|
||||
{
|
||||
Pending,
|
||||
Authorized,
|
||||
Expired,
|
||||
Error,
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Playlist;
|
||||
namespace PlaylistShared.Shared.SharedPlaylist;
|
||||
|
||||
/// <summary>Запрос на создание нового шеринг-плейлиста.</summary>
|
||||
public class SharePlaylistDto
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace PlaylistShared.Shared.Playlist;
|
||||
namespace PlaylistShared.Shared.SharedPlaylist;
|
||||
|
||||
public class SharePlaylistRequest
|
||||
{
|
||||
27
PlaylistShared.Shared/Yandex/YandexAlbum.cs
Normal file
27
PlaylistShared.Shared/Yandex/YandexAlbum.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Информация о альбоме из Яндекс.Музыки.</summary>
|
||||
public class YandexAlbum
|
||||
{
|
||||
/// <summary>Идентификатор альбома (id).</summary>
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; set; } = null!;
|
||||
|
||||
/// <summary>Наименование альбома.</summary>
|
||||
[JsonPropertyName("title")]
|
||||
public string Title { get; set; } = null!;
|
||||
|
||||
/// <summary>Исполнители альбома.</summary>
|
||||
[JsonPropertyName("artists")]
|
||||
public List<YandexArtist> Artists { get; set; } = null!;
|
||||
|
||||
/// <summary>Описание альбома.</summary>
|
||||
[JsonPropertyName("description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>URL обложки альбома.</summary>
|
||||
[JsonPropertyName("coverUrl")]
|
||||
public string? CoverUrl { get; set; }
|
||||
}
|
||||
23
PlaylistShared.Shared/Yandex/YandexArtist.cs
Normal file
23
PlaylistShared.Shared/Yandex/YandexArtist.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Информация о исполнителе из Яндекс.Музыки.</summary>
|
||||
public class YandexArtist
|
||||
{
|
||||
/// <summary>Идентификатор исполнителя (id).</summary>
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; set; } = null!;
|
||||
|
||||
/// <summary>Наименование исполнителя.</summary>
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>Описание исполнителя.</summary>
|
||||
[JsonPropertyName("description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>URL исполнителя.</summary>
|
||||
[JsonPropertyName("coverUrl")]
|
||||
public string? CoverUrl { get; set; }
|
||||
}
|
||||
13
PlaylistShared.Shared/Yandex/YandexAuthQr.cs
Normal file
13
PlaylistShared.Shared/Yandex/YandexAuthQr.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Результат авторизации QR</summary>
|
||||
public class YandexAuthQr
|
||||
{
|
||||
[JsonPropertyName("qrLink")]
|
||||
public string QrLink { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("sessionId")]
|
||||
public string SessionId { get; set; } = string.Empty;
|
||||
}
|
||||
11
PlaylistShared.Shared/Yandex/YandexAuthQrCheck.cs
Normal file
11
PlaylistShared.Shared/Yandex/YandexAuthQrCheck.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using PlaylistShared.Shared.Enums;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Результат авторизации QR</summary>
|
||||
public class YandexAuthQrCheck
|
||||
{
|
||||
[JsonPropertyName("status")]
|
||||
public YandexAuthQrStatus Status { get; set; } = YandexAuthQrStatus.Pending;
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Playlist;
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Информация о плейлисте из Яндекс.Музыки (для импорта).</summary>
|
||||
public class YandexPlaylistInfo
|
||||
/// <summary>Информация о плейлисте из Яндекс.Музыки.</summary>
|
||||
public class YandexPlaylist
|
||||
{
|
||||
/// <summary>Идентификатор плейлиста (uuid).</summary>
|
||||
[JsonPropertyName("uuid")]
|
||||
public string Uuid { get; set; } = null!;
|
||||
|
||||
/// <summary>Идентификатор плейлиста (kind).</summary>
|
||||
[JsonPropertyName("kind")]
|
||||
public string Kind { get; set; } = null!;
|
||||
@@ -28,12 +32,4 @@ public class YandexPlaylistInfo
|
||||
/// <summary>Кол-во треков.</summary>
|
||||
[JsonPropertyName("trackCount")]
|
||||
public int TrackCount { get; set; }
|
||||
|
||||
/// <summary>Расшаренный</summary>
|
||||
[JsonPropertyName("isShared")]
|
||||
public bool IsShared { get; set; }
|
||||
|
||||
/// <summary>Расшаренная ссылка</summary>
|
||||
[JsonPropertyName("shareToken")]
|
||||
public string? ShareToken { get; set; }
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using PlaylistShared.Shared.DTO;
|
||||
|
||||
namespace PlaylistShared.Shared.SharedPlaylist;
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
public class YandexPlaylistData
|
||||
{
|
||||
16
PlaylistShared.Shared/Yandex/YandexPlaylistShare.cs
Normal file
16
PlaylistShared.Shared/Yandex/YandexPlaylistShare.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Информация о плейлисте из Яндекс.Музыки с пометкой о шаринге.</summary>
|
||||
public class YandexPlaylistShare : YandexPlaylist
|
||||
{
|
||||
|
||||
/// <summary>Расшаренный</summary>
|
||||
[JsonPropertyName("isShared")]
|
||||
public bool IsShared { get; set; }
|
||||
|
||||
/// <summary>Расшаренная ссылка</summary>
|
||||
[JsonPropertyName("shareToken")]
|
||||
public string? ShareToken { get; set; }
|
||||
}
|
||||
43
PlaylistShared.Shared/Yandex/YandexSearchResult.cs
Normal file
43
PlaylistShared.Shared/Yandex/YandexSearchResult.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Информация о плейлисте из Яндекс.Музыки (для импорта).</summary>
|
||||
public class YandexSearchResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Найденные треки.
|
||||
/// </summary>
|
||||
[JsonPropertyName("tracks")]
|
||||
public List<YandexTrack>? Tracks { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Найденные плейлисты.
|
||||
/// </summary>
|
||||
[JsonPropertyName("playlists")]
|
||||
public List<YandexPlaylist>? Playlists { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Персональные плейлисты.
|
||||
/// </summary>
|
||||
[JsonPropertyName("personalPlaylists")]
|
||||
public List<YandexPlaylist>? PersonalPlaylists { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Плейлисты, которые понравились.
|
||||
/// </summary>
|
||||
[JsonPropertyName("likedPlaylists")]
|
||||
public List<YandexPlaylist>? LikedPlaylists { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Найденные исполнители.
|
||||
/// </summary>
|
||||
[JsonPropertyName("artists")]
|
||||
public List<YandexArtist>? Artists { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Найденные альбомы.
|
||||
/// </summary>
|
||||
[JsonPropertyName("albumns")]
|
||||
public List<YandexAlbum>? Albums { get; set; } = null;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace PlaylistShared.Shared.DTO;
|
||||
namespace PlaylistShared.Shared.Yandex;
|
||||
|
||||
/// <summary>Результат поиска трека в Яндекс.Музыке.</summary>
|
||||
public class YandexTrack
|
||||
@@ -12,7 +12,7 @@ public class YandexTrack
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("artists")]
|
||||
public List<string> Artists { get; set; } = new();
|
||||
public List<YandexArtist> Artists { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("coverUri")]
|
||||
public string CoverUri { get; set; } = string.Empty;
|
||||
Reference in New Issue
Block a user