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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. @page "/home"
  2. @using GrpcShared.DTO
  3. @using GrpcShared.DTO.Track
  4. @using NemAnBlazor.Services.Interfaces
  5. @inject Blazored.LocalStorage.ILocalStorageService localStorage
  6. @inject IStatsClientService spotifyService
  7. @inject ITrackClientService trackService
  8. @inject IAuthClientService AuthService
  9. <h3>Home</h3>
  10. <p>login radi</p>
  11. @code {
  12. protected override async Task OnInitializedAsync()
  13. {
  14. string tokenS = await localStorage.GetItemAsync<string>("token");
  15. string refreshT = await localStorage.GetItemAsync<string>("refresh_token");
  16. //tokenS = "BQBMgFm6jnFNWWeZEMGIRP_f-ENPid7Kw8JubAyuWAe4JK0S1DPFGlaAdZ_Fey6ePkCnz8-cqC0oyRmrciWUy5ISUTQKDe8PTQn4iBRMYCgM0n4GnS1xAErHJcm4Vpu2TAngk-4vQUOfTQRcedNTfCaHKP4uFJgTlTI7JHGrtB-_EZLnFcZ2OQe31oFQIJ1wM3ZtvwnN";
  17. TokenMessage token = new TokenMessage { Token = tokenS, RefreshToken = refreshT };
  18. CurrentTrackResponse response = await spotifyService.GetCurrentlyPlayingTrack(token);
  19. //if token expired, refresh it
  20. if (response.ResponseMsg == System.Net.HttpStatusCode.Unauthorized)
  21. {
  22. string? tempToken = await SpotifyHelper.TryRefreshToken(AuthService, token, localStorage);
  23. tokenS = tempToken == null ? tokenS : tempToken;
  24. //if refreshed token is null, that means that refresh token was invalid, so you should redirect to login
  25. }
  26. //napravi komponentu koja ce da prikazuje sta trenutno slusas i passuj joj parametre
  27. //var trackById = await trackService.GetById(new GrpcShared.DTO.TrackByID.TrackRequest { TrackID = "4fy1A2WBTPX55mUI16TQXa", Token = tokenS });
  28. var items = await spotifyService.GetTopItems(new GrpcShared.DTO.TopItem.TopItemRequest { Token = tokenS, IsTracks = false, Offset = 5 });
  29. if (items.ResponseMsg == System.Net.HttpStatusCode.Unauthorized)
  30. {
  31. string? tempToken = await SpotifyHelper.TryRefreshToken(AuthService, token, localStorage);
  32. tokenS = tempToken == null ? tokenS : tempToken;
  33. }
  34. }
  35. }