5
5
using System . Net ;
6
6
using System . Net . Http ;
7
7
using System . Net . Http . Json ;
8
+ using System . Text . Json ;
9
+ using System . Text . Json . Serialization ;
8
10
using System . Threading ;
9
11
using System . Threading . Tasks ;
10
12
@@ -16,6 +18,11 @@ public record CommunityPluginSource(string ManifestFileUrl)
16
18
17
19
private List < UserPlugin > plugins = new ( ) ;
18
20
21
+ private static JsonSerializerOptions PluginStoreItemSerializationOption = new JsonSerializerOptions ( )
22
+ {
23
+ DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingDefault
24
+ } ;
25
+
19
26
/// <summary>
20
27
/// Fetch and deserialize the contents of a plugins.json file found at <see cref="ManifestFileUrl"/>.
21
28
/// We use conditional http requests to keep repeat requests fast.
@@ -32,12 +39,15 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
32
39
33
40
request . Headers . Add ( "If-None-Match" , latestEtag ) ;
34
41
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 ) ;
36
44
37
45
if ( response . StatusCode == HttpStatusCode . OK )
38
46
{
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 ;
41
51
42
52
Log . Info ( nameof ( CommunityPluginSource ) , $ "Loaded { this . plugins . Count } plugins from { ManifestFileUrl } ") ;
43
53
return this . plugins ;
@@ -49,7 +59,8 @@ public async Task<List<UserPlugin>> FetchAsync(CancellationToken token)
49
59
}
50
60
else
51
61
{
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 } ") ;
53
64
throw new Exception ( $ "Failed to load resource { ManifestFileUrl } with response { response . StatusCode } ") ;
54
65
}
55
66
}
0 commit comments