From 1f803fd44b4401d98a3a0efde3858370d18eb132 Mon Sep 17 00:00:00 2001 From: Insomniachi Date: Sat, 10 Feb 2024 11:19:33 +0530 Subject: [PATCH] move more secrets to github, fix crash when unable to find id --- .github/workflows/Deploy.yml | 2 + .../Services/AniList/AniListService.cs | 6 +-- Totoro.Core/Services/DiscordRichPresense.cs | 5 ++- Totoro.Core/Services/FileService.cs | 3 +- Totoro.Core/Services/OfflineAnimeIdService.cs | 44 ++++++++++--------- .../Services/Simkl/SimklAnimeService.cs | 2 + .../SettingsSections/AnimePluginsSection.xaml | 10 ----- .../AnimePluginsSection.xaml.cs | 2 - .../SettingsSections/TrackingSection.xaml | 10 +++++ .../SettingsSections/TrackingSection.xaml.cs | 2 + Totoro.WinUI/appsettings.json | 4 +- 11 files changed, 50 insertions(+), 40 deletions(-) diff --git a/.github/workflows/Deploy.yml b/.github/workflows/Deploy.yml index 187bd420..c841dd2d 100644 --- a/.github/workflows/Deploy.yml +++ b/.github/workflows/Deploy.yml @@ -48,6 +48,8 @@ jobs: ClientId: ${{ secrets.MAL_CLIENT_ID }} ClientIdAniList: ${{ secrets.ANILIST_CLIENT_ID }} ClientIdSimkl: ${{ secrets.SIMKL_CLIENT_ID }} + SimklSecret: ${{ secrets.SIMKL_SECRET }} + ClientIdDiscord: ${{ secrets.DISCORD_CLIENT_ID }} - name: 'Build Installer' run: msbuild ${{ env.INSTALLER_PATH }} /property:Configuration=Release /property:BuildVersion=${{ steps.version.outputs.version-without-v }} /property:BasePath=${{ env.PUBLISH_FOLDER }} diff --git a/Totoro.Core/Services/AniList/AniListService.cs b/Totoro.Core/Services/AniList/AniListService.cs index a4c86f18..eb8c27a9 100644 --- a/Totoro.Core/Services/AniList/AniListService.cs +++ b/Totoro.Core/Services/AniList/AniListService.cs @@ -115,7 +115,7 @@ public async Task GetBannerImage(long id) { var animeId = await _animeIdService.GetId(_settings.DefaultListService, ListServiceType.AniList, id); - if (animeId is { AniList: null }) + if (animeId is { AniList: null } or null) { return string.Empty; } @@ -133,7 +133,7 @@ public async Task GetBannerImage(long id) { var animeId = await _animeIdService.GetId(_settings.DefaultListService, ListServiceType.AniList, id); - if (animeId is { AniList: null } ) + if (animeId is { AniList: null } or null) { return (null, null); } @@ -141,7 +141,7 @@ public async Task GetBannerImage(long id) var response = await _anilistClient.SendQueryAsync(new GraphQL.GraphQLRequest { Query = new QueryQueryBuilder().WithMedia(new MediaQueryBuilder() - .WithNextAiringEpisode(new AiringScheduleQueryBuilder() + .WithNextAiringEpisode(new AiringScheduleQueryBuilder() .WithEpisode() .WithTimeUntilAiring()), id: (int)animeId.AniList).Build() }); diff --git a/Totoro.Core/Services/DiscordRichPresense.cs b/Totoro.Core/Services/DiscordRichPresense.cs index 215f1b5b..eab43faa 100644 --- a/Totoro.Core/Services/DiscordRichPresense.cs +++ b/Totoro.Core/Services/DiscordRichPresense.cs @@ -1,11 +1,12 @@  using DiscordRPC; +using Microsoft.Extensions.Configuration; namespace Totoro.Core.Services; -public class DiscordRichPresense : IDiscordRichPresense +public class DiscordRichPresense(IConfiguration configuration) : IDiscordRichPresense { - private readonly DiscordRpcClient _client = new("997177919052984622"); + private readonly DiscordRpcClient _client = new(configuration["ClientIdDiscord"]); public void Initialize() => _client.Initialize(); public bool IsInitialized => _client.IsInitialized; diff --git a/Totoro.Core/Services/FileService.cs b/Totoro.Core/Services/FileService.cs index 4b05691b..3c682c85 100644 --- a/Totoro.Core/Services/FileService.cs +++ b/Totoro.Core/Services/FileService.cs @@ -7,7 +7,8 @@ public class FileService : IFileService { private readonly JsonSerializerSettings _settings = new() { - DefaultValueHandling = DefaultValueHandling.Ignore + DefaultValueHandling = DefaultValueHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, }; public T Read(string folderPath, string fileName) diff --git a/Totoro.Core/Services/OfflineAnimeIdService.cs b/Totoro.Core/Services/OfflineAnimeIdService.cs index ca4a887d..b5d7afc9 100644 --- a/Totoro.Core/Services/OfflineAnimeIdService.cs +++ b/Totoro.Core/Services/OfflineAnimeIdService.cs @@ -78,32 +78,34 @@ public async Task UpdateOfflineMappings() var id = new AnimeIdExtended(); var obj = item.AsObject(); - foreach (var key in keys) + foreach (var key in keys.Where(obj.ContainsKey)) { - if (obj.ContainsKey(key)) + var value = obj[key].GetValue(); + switch (key) { - var value = obj[key].GetValue(); - switch (key) - { - case "livechart_id": - id.LiveChart = value; - break; - case "anidb_id": - id.AniDb = value; - break; - case "kitsu_id": - id.Kitsu = value; - break; - case "mal_id": - id.MyAnimeList = value; - break; - case "anilist_id": - id.AniList = value; - break; - } + case "livechart_id": + id.LiveChart = value; + break; + case "anidb_id": + id.AniDb = value; + break; + case "kitsu_id": + id.Kitsu = value; + break; + case "mal_id": + id.MyAnimeList = value; + break; + case "anilist_id": + id.AniList = value; + break; } } + if (id.IsEmpty()) + { + continue; + } + _ids.Add(id); } _idsMap = GetMapping(settings.DefaultListService); diff --git a/Totoro.Core/Services/Simkl/SimklAnimeService.cs b/Totoro.Core/Services/Simkl/SimklAnimeService.cs index 42f52f51..d06ba17e 100644 --- a/Totoro.Core/Services/Simkl/SimklAnimeService.cs +++ b/Totoro.Core/Services/Simkl/SimklAnimeService.cs @@ -78,4 +78,6 @@ public bool HasId(ListServiceType type) _ => false }; } + + public bool IsEmpty() => this is { AniDb: null, AniList: null, MyAnimeList: null, Kitsu: null, LiveChart: null, Simkl: null }; } diff --git a/Totoro.WinUI/Views/SettingsSections/AnimePluginsSection.xaml b/Totoro.WinUI/Views/SettingsSections/AnimePluginsSection.xaml index 5c35b28f..6314bfd3 100644 --- a/Totoro.WinUI/Views/SettingsSections/AnimePluginsSection.xaml +++ b/Totoro.WinUI/Views/SettingsSections/AnimePluginsSection.xaml @@ -75,16 +75,6 @@ OnContent="On" /> - -