Blazor & WASM in combination to get statistics from Spotify API for performing the song analysis. With separate microservices for auth, Spotify, user data tracking, and application, connected through gRPC with Polly.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Home.razor 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. @page "/home"
  2. @using Grpc.Core
  3. @using GrpcShared.DTO
  4. @using GrpcShared.DTO.Track
  5. @using NemAnBlazor.Services.Interfaces
  6. @using System.Net
  7. @inject Blazored.LocalStorage.ILocalStorageService localStorage
  8. @inject IStatsClientService spotifyService
  9. @inject ITrackClientService trackService
  10. @inject IAuthClientService AuthService
  11. @inject IIdentityClientService identityService
  12. <h3>Home</h3>
  13. <p>login radi</p>
  14. @code {
  15. protected override async Task OnInitializedAsync()
  16. {
  17. string tokenS = await localStorage.GetItemAsync<string>("token");
  18. string refreshT = await localStorage.GetItemAsync<string>("refresh_token");
  19. //tokenS = "BQBMgFm6jnFNWWeZEMGIRP_f-ENPid7Kw8JubAyuWAe4JK0S1DPFGlaAdZ_Fey6ePkCnz8-cqC0oyRmrciWUy5ISUTQKDe8PTQn4iBRMYCgM0n4GnS1xAErHJcm4Vpu2TAngk-4vQUOfTQRcedNTfCaHKP4uFJgTlTI7JHGrtB-_EZLnFcZ2OQe31oFQIJ1wM3ZtvwnN";
  20. TokenMessage token = new TokenMessage { Token = tokenS, RefreshToken = refreshT };
  21. try
  22. {
  23. CurrentTrackResponse track = await spotifyService.GetCurrentlyPlayingTrack(token);
  24. //if token expired, refresh it
  25. if (track.ResponseMsg == System.Net.HttpStatusCode.Unauthorized)
  26. {
  27. string? tempToken = await SpotifyHelper.TryRefreshToken(AuthService, token, localStorage);
  28. tokenS = tempToken == null ? tokenS : tempToken;
  29. //if refreshed token is null, that means that refresh token was invalid, so you should redirect to login
  30. }
  31. }
  32. catch (RpcException e)
  33. {
  34. if (e.StatusCode == StatusCode.Cancelled)
  35. {
  36. return;
  37. }
  38. throw;
  39. }
  40. //napravi komponentu koja ce da prikazuje sta trenutno slusas i passuj joj parametre
  41. //var trackById = await trackService.GetById(new GrpcShared.DTO.TrackByID.TrackRequest { TrackID = "4fy1A2WBTPX55mUI16TQXa", Token = tokenS });
  42. try
  43. {
  44. var items = await spotifyService.GetTopItems(new GrpcShared.DTO.TopItem.TopItemRequest { Token = tokenS, IsTracks = false, Offset = 5 });
  45. if (items.ResponseMsg == System.Net.HttpStatusCode.Unauthorized)
  46. {
  47. string? tempToken = await SpotifyHelper.TryRefreshToken(AuthService, token, localStorage);
  48. tokenS = tempToken == null ? tokenS : tempToken;
  49. }
  50. }
  51. catch (RpcException e)
  52. {
  53. if (e.StatusCode == StatusCode.Cancelled)
  54. {
  55. return;
  56. }
  57. throw;
  58. }
  59. }
  60. }