1- using System . Reflection ;
2- using System . Text . Json ;
3- using System . Text . Json . Serialization ;
1+ using System . Text . Json ;
42using Flurl . Http ;
53using Jint . Native . Json ;
64using SmartImage . Lib . Results ;
@@ -62,6 +60,11 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
6260 } ;
6361 obj = JsonSerializer . Deserialize < Root > ( s , js ) ;
6462 }
63+ catch ( JsonException e ) {
64+ sr . ErrorMessage = e . Message ;
65+ sr . Status = SearchResultStatus . Failure ;
66+ goto ret ;
67+ }
6568 catch ( FlurlHttpException e ) {
6669 sr . ErrorMessage = e . Message ;
6770 sr . Status = SearchResultStatus . Unavailable ;
@@ -117,7 +120,7 @@ private class Match
117120 public int hash_size ;
118121 public string searched_url ;
119122 public Post post ;
120- public int title_similarity ;
123+ public double title_similarity ;
121124 }
122125
123126 private class Post
@@ -160,9 +163,9 @@ private class SearchSettings
160163 public bool check_title ;
161164 public int max_depth ;
162165 public bool meme_filter ;
163- public int target_annoy_distance ;
164- public int target_meme_match_percent ;
165- public int target_match_percent ;
166+ public double target_annoy_distance ;
167+ public double target_meme_match_percent ;
168+ public double target_match_percent ;
166169 }
167170
168171 private class SearchTimes
@@ -187,44 +190,4 @@ private class SearchTimes
187190 }
188191
189192 #endregion
190- }
191-
192- public class NonPublicMembersConverter < T > : JsonConverter < T > where T : class
193- {
194- public override T Read ( ref Utf8JsonReader reader , Type typeToConvert , JsonSerializerOptions options )
195- {
196- T instance = ( T ) Activator . CreateInstance ( typeToConvert , nonPublic : true ) ;
197-
198- while ( reader . Read ( ) ) {
199- if ( reader . TokenType == JsonTokenType . EndObject ) {
200- break ;
201- }
202-
203- if ( reader . TokenType != JsonTokenType . PropertyName ) {
204- throw new JsonException ( ) ;
205- }
206-
207- string propertyName = reader . GetString ( ) ;
208-
209- PropertyInfo propertyInfo =
210- typeToConvert . GetProperty ( propertyName ,
211- BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ) ;
212-
213- if ( propertyInfo != null && propertyInfo . CanWrite ) {
214- reader . Read ( ) ; // Move to the property value
215- object value = JsonSerializer . Deserialize ( ref reader , propertyInfo . PropertyType , options ) ;
216- propertyInfo . SetValue ( instance , value ) ;
217- }
218- else {
219- reader . Skip ( ) ;
220- }
221- }
222-
223- return instance ;
224- }
225-
226- public override void Write ( Utf8JsonWriter writer , T value , JsonSerializerOptions options )
227- {
228- JsonSerializer . Serialize ( writer , value , options ) ;
229- }
230193}
0 commit comments