55using System . Net ;
66using System . Net . Http ;
77using System . Net . Http . Json ;
8+ using System . Text . Json ;
9+ using System . Text . Json . Serialization ;
810using System . Threading ;
911using System . Threading . Tasks ;
1012
@@ -16,6 +18,11 @@ public record CommunityPluginSource(string ManifestFileUrl)
1618
1719 private List < UserPlugin > plugins = new ( ) ;
1820
21+ private static JsonSerializerOptions PluginStoreItemSerializationOption = new JsonSerializerOptions ( )
22+ {
23+ DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingDefault
24+ } ;
25+
1926 /// <summary>
2027 /// Fetch and deserialize the contents of a plugins.json file found at <see cref="ManifestFileUrl"/>.
2128 /// We use conditional http requests to keep repeat requests fast.
@@ -32,12 +39,15 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
3239
3340 request . Headers . Add ( "If-None-Match" , latestEtag ) ;
3441
35- using var response = await Http . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , token ) . ConfigureAwait ( false ) ;
42+ using var response = await Http . SendAsync ( request , HttpCompletionOption . ResponseHeadersRead , token )
43+ . ConfigureAwait ( false ) ;
3644
3745 if ( response . StatusCode == HttpStatusCode . OK )
3846 {
39- this . plugins = await response . Content . ReadFromJsonAsync < List < UserPlugin > > ( cancellationToken : token ) . ConfigureAwait ( false ) ;
40- this . latestEtag = response . Headers . ETag . Tag ;
47+ this . plugins = await response . Content
48+ . ReadFromJsonAsync < List < UserPlugin > > ( PluginStoreItemSerializationOption , cancellationToken : token )
49+ . ConfigureAwait ( false ) ;
50+ this . latestEtag = response . Headers . ETag ? . Tag ;
4151
4252 Log . Info ( nameof ( CommunityPluginSource ) , $ "Loaded { this . plugins . Count } plugins from { ManifestFileUrl } ") ;
4353 return this . plugins ;
@@ -49,7 +59,8 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
4959 }
5060 else
5161 {
52- Log . Warn ( nameof ( CommunityPluginSource ) , $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
62+ Log . Warn ( nameof ( CommunityPluginSource ) ,
63+ $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
5364 throw new Exception ( $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
5465 }
5566 }
0 commit comments