Skip to content

Commit

Permalink
move more secrets to github,
Browse files Browse the repository at this point in the history
fix crash when unable to find id
  • Loading branch information
insomniachi committed Feb 10, 2024
1 parent 5823ea8 commit 1f803fd
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 3 additions & 3 deletions Totoro.Core/Services/AniList/AniListService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task<string> 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;
}
Expand All @@ -133,15 +133,15 @@ public async Task<string> 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);
}

var response = await _anilistClient.SendQueryAsync<Query>(new GraphQL.GraphQLRequest
{
Query = new QueryQueryBuilder().WithMedia(new MediaQueryBuilder()
.WithNextAiringEpisode(new AiringScheduleQueryBuilder()
.WithNextAiringEpisode(new AiringScheduleQueryBuilder()
.WithEpisode()
.WithTimeUntilAiring()), id: (int)animeId.AniList).Build()
});
Expand Down
5 changes: 3 additions & 2 deletions Totoro.Core/Services/DiscordRichPresense.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Totoro.Core/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(string folderPath, string fileName)
Expand Down
44 changes: 23 additions & 21 deletions Totoro.Core/Services/OfflineAnimeIdService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<long>();
switch (key)
{
var value = obj[key].GetValue<long>();
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);
Expand Down
2 changes: 2 additions & 0 deletions Totoro.Core/Services/Simkl/SimklAnimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
10 changes: 0 additions & 10 deletions Totoro.WinUI/Views/SettingsSections/AnimePluginsSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@
OnContent="On" />
</labs:SettingsCard>

<labs:SettingsCard
Description="This repository is to store and provide the mapping between various anime sources, (https://github.com/Fribb/anime-lists)"
Header="Offline Anime DB"
HeaderIcon="{ui:FontIcon Glyph=&#xE78C;}">
<Button
Command="{x:Bind UpdateOfflineDb}"
Content="Update"
Style="{ThemeResource AccentButtonStyle}" />
</labs:SettingsCard>

<Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ public SettingsViewModel ViewModel
DependencyProperty.Register("ViewModel", typeof(SettingsViewModel), typeof(AnimePluginsSection), new PropertyMetadata(null));


public ICommand UpdateOfflineDb { get; }
public ICommand ResetProvider { get; }

public AnimePluginsSection()
{
InitializeComponent();

UpdateOfflineDb = ReactiveCommand.CreateFromTask(() => App.GetService<IOfflineAnimeIdService>().UpdateOfflineMappings());
ResetProvider = ReactiveCommand.Create<string>(provider => App.GetService<IPluginOptionsStorage<AnimeProvider>>().ResetConfig(provider));
}

Expand Down
10 changes: 10 additions & 0 deletions Totoro.WinUI/Views/SettingsSections/TrackingSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,15 @@
Value="{x:Bind ViewModel.Settings.TimeRemainingWhenEpisodeCompletesInSeconds, Mode=TwoWay}" />
</labs:SettingsCard>

<labs:SettingsCard
Description="This repository is to store and provide the mapping between various anime sources, (https://github.com/Fribb/anime-lists)"
Header="Offline Anime DB"
HeaderIcon="{ui:FontIcon Glyph=&#xE78C;}">
<Button
Command="{x:Bind UpdateOfflineDb}"
Content="Update"
Style="{ThemeResource AccentButtonStyle}" />
</labs:SettingsCard>

</StackPanel>
</Page>
2 changes: 2 additions & 0 deletions Totoro.WinUI/Views/SettingsSections/TrackingSection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public SettingsViewModel ViewModel
public static readonly DependencyProperty ViewModelProperty =
DependencyProperty.Register("ViewModel", typeof(SettingsViewModel), typeof(TrackingSection), new PropertyMetadata(null));

public ICommand UpdateOfflineDb { get; }

public TrackingSection()
{
InitializeComponent();
UpdateOfflineDb = ReactiveCommand.CreateFromTask(() => App.GetService<IOfflineAnimeIdService>().UpdateOfflineMappings());
}

protected override void OnNavigatedTo(NavigationEventArgs e)
Expand Down
4 changes: 3 additions & 1 deletion Totoro.WinUI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
},
"ClientId": "",
"ClientIdAniList": "",
"ClientIdSimkl": ""
"ClientIdSimkl": "",
"SimklSecret": "",
"ClientIdDiscord": ""
}

0 comments on commit 1f803fd

Please sign in to comment.