@@ -87,13 +87,20 @@ impl AutoDiscoveryResult {
87
87
) -> Option < & AutoDiscoveryAttemptResult > {
88
88
self . attempts . get ( attempt_type)
89
89
}
90
+
91
+ pub fn is_wordpress_site ( & self ) -> bool {
92
+ self . attempts
93
+ . iter ( )
94
+ . any ( |( _, result) | result. is_wordpress_site . is_successful ( ) )
95
+ }
90
96
}
91
97
92
98
#[ derive( Debug , Clone , uniffi:: Object ) ]
93
99
pub struct AutoDiscoveryAttemptResult {
94
100
pub attempt_type : AutoDiscoveryAttemptType ,
95
101
pub attempt_site_url : String ,
96
- pub result : Result < AutoDiscoveryAttemptSuccess , AutoDiscoveryAttemptFailure > ,
102
+ pub api_discovery_result : Result < AutoDiscoveryAttemptSuccess , AutoDiscoveryAttemptFailure > ,
103
+ pub is_wordpress_site : IsWordPressSiteAttemptResult ,
97
104
}
98
105
99
106
#[ uniffi:: export]
@@ -103,18 +110,18 @@ impl AutoDiscoveryAttemptResult {
103
110
}
104
111
105
112
fn error_message ( & self ) -> Option < String > {
106
- match & self . result {
113
+ match & self . api_discovery_result {
107
114
Ok ( _) => None ,
108
115
Err ( error) => Some ( error. error_message ( ) ) ,
109
116
}
110
117
}
111
118
112
119
fn is_successful ( & self ) -> bool {
113
- self . result . is_ok ( )
120
+ self . api_discovery_result . is_ok ( )
114
121
}
115
122
116
123
fn is_network_error ( & self ) -> bool {
117
- match & self . result {
124
+ match & self . api_discovery_result {
118
125
Ok ( _) => false ,
119
126
Err ( error) => error. is_network_error ( ) ,
120
127
}
@@ -125,124 +132,57 @@ impl AutoDiscoveryAttemptResult {
125
132
}
126
133
127
134
fn has_failed_to_parse_site_url ( & self ) -> bool {
128
- match & self . result {
135
+ match & self . api_discovery_result {
129
136
Ok ( success) => false ,
130
137
Err ( error) => error. parsed_site_url ( ) . is_none ( ) ,
131
138
}
132
139
}
133
140
134
141
fn has_failed_to_parse_api_root_url ( & self ) -> Option < bool > {
135
- match & self . result {
142
+ match & self . api_discovery_result {
136
143
Ok ( success) => Some ( false ) ,
137
144
Err ( error) => error. has_failed_to_parse_api_root_url ( ) ,
138
145
}
139
146
}
140
147
141
148
fn has_failed_to_parse_api_details ( & self ) -> Option < bool > {
142
- match & self . result {
149
+ match & self . api_discovery_result {
143
150
Ok ( success) => Some ( false ) ,
144
151
Err ( error) => error. has_failed_to_parse_api_details ( ) ,
145
152
}
146
153
}
147
154
148
155
fn parsed_site_url ( & self ) -> Option < Arc < ParsedUrl > > {
149
- match & self . result {
156
+ match & self . api_discovery_result {
150
157
Ok ( success) => Some ( Arc :: new ( success. parsed_site_url . clone ( ) ) ) ,
151
158
Err ( error) => error. parsed_site_url ( ) . map ( |p| Arc :: new ( p. clone ( ) ) ) ,
152
159
}
153
160
}
154
161
155
162
fn api_root_url ( & self ) -> Option < Arc < ParsedUrl > > {
156
- match & self . result {
163
+ match & self . api_discovery_result {
157
164
Ok ( success) => Some ( Arc :: new ( success. api_root_url . clone ( ) ) ) ,
158
165
Err ( error) => error. api_root_url ( ) . map ( |p| Arc :: new ( p. clone ( ) ) ) ,
159
166
}
160
167
}
161
168
162
169
fn api_details ( & self ) -> Option < Arc < WpApiDetails > > {
163
- match & self . result {
170
+ match & self . api_discovery_result {
164
171
Ok ( success) => Some ( Arc :: new ( success. api_details . clone ( ) ) ) ,
165
172
Err ( _) => None ,
166
173
}
167
174
}
168
175
}
169
176
170
- #[ derive( Debug , uniffi:: Record ) ]
171
- pub struct IsWordPressSiteUniffiResult {
172
- pub user_input_attempt : Arc < IsWordPressSiteAttemptResult > ,
173
- pub successful_attempt : Option < Arc < IsWordPressSiteAttemptResult > > ,
174
- pub auto_https_attempt : Option < Arc < IsWordPressSiteAttemptResult > > ,
175
- pub auto_dot_php_extension_for_wp_admin_attempt : Option < Arc < IsWordPressSiteAttemptResult > > ,
176
- }
177
-
178
- #[ derive( Debug ) ]
179
- pub struct IsWordPressSiteResult {
180
- pub attempts : HashMap < AutoDiscoveryAttemptType , IsWordPressSiteAttemptResult > ,
181
- }
182
-
183
- impl From < IsWordPressSiteResult > for IsWordPressSiteUniffiResult {
184
- fn from ( value : IsWordPressSiteResult ) -> Self {
185
- let get_attempt_result = |attempt_type| {
186
- value
187
- . get_attempt ( & attempt_type)
188
- . map ( |a| Arc :: new ( a. clone ( ) ) )
189
- } ;
190
- Self {
191
- user_input_attempt : Arc :: new ( value. user_input_attempt ( ) . clone ( ) ) ,
192
- successful_attempt : value. find_successful ( ) . map ( |a| Arc :: new ( a. clone ( ) ) ) ,
193
- auto_https_attempt : get_attempt_result ( AutoDiscoveryAttemptType :: AutoHttps ) ,
194
- auto_dot_php_extension_for_wp_admin_attempt : get_attempt_result (
195
- AutoDiscoveryAttemptType :: AutoDotPhpExtensionForWpAdmin ,
196
- ) ,
197
- }
198
- }
199
- }
200
-
201
- impl IsWordPressSiteResult {
202
- pub fn is_successful ( & self ) -> bool {
203
- self . attempts
204
- . iter ( )
205
- . any ( |( _, result) | result. is_successful ( ) )
206
- }
207
-
208
- pub fn user_input_attempt ( & self ) -> & IsWordPressSiteAttemptResult {
209
- self . get_attempt ( & AutoDiscoveryAttemptType :: UserInput )
210
- . expect ( "User input url is always attempted" )
211
- }
212
-
213
- pub fn get_attempt (
214
- & self ,
215
- attempt_type : & AutoDiscoveryAttemptType ,
216
- ) -> Option < & IsWordPressSiteAttemptResult > {
217
- self . attempts . get ( attempt_type)
218
- }
219
-
220
- pub fn find_successful ( & self ) -> Option < & IsWordPressSiteAttemptResult > {
221
- // If the user attempt is successful, prefer it over other attempts
222
- let user_input_attempt = self . user_input_attempt ( ) ;
223
- if user_input_attempt. is_successful ( ) {
224
- return Some ( user_input_attempt) ;
225
- }
226
- self . attempts . iter ( ) . find_map ( |( _, result) | {
227
- if result. is_successful ( ) {
228
- Some ( result)
229
- } else {
230
- None
231
- }
232
- } )
233
- }
234
- }
235
-
236
177
#[ derive( Debug , Clone , uniffi:: Object ) ]
237
178
pub struct IsWordPressSiteAttemptResult {
238
- pub attempt_type : AutoDiscoveryAttemptType ,
239
179
pub api_link_header_result : Result < FindApiRootLinkHeaderSuccess , FindApiRootLinkHeaderFailure > ,
240
180
pub fetch_wp_json_result : Result < FetchWpJsonSuccess , FetchWpJsonFailure > ,
241
181
pub parse_html_result : Result < IsWordPressSiteParseHtmlResult , ParseHtmlFailure > ,
242
182
}
243
183
244
184
impl IsWordPressSiteAttemptResult {
245
- fn is_successful ( & self ) -> bool {
185
+ pub fn is_successful ( & self ) -> bool {
246
186
self . api_link_header_result . is_ok ( )
247
187
|| self . fetch_wp_json_result . is_ok ( )
248
188
|| self
@@ -411,18 +351,6 @@ pub enum AutoDiscoveryAttemptFailure {
411
351
}
412
352
413
353
impl AutoDiscoveryAttemptFailure {
414
- pub fn into_attempt_result (
415
- self ,
416
- attempt_type : AutoDiscoveryAttemptType ,
417
- attempt_site_url : String ,
418
- ) -> AutoDiscoveryAttemptResult {
419
- AutoDiscoveryAttemptResult {
420
- attempt_type,
421
- attempt_site_url,
422
- result : Err ( self ) ,
423
- }
424
- }
425
-
426
354
pub fn error_message ( & self ) -> String {
427
355
match self {
428
356
AutoDiscoveryAttemptFailure :: ParseSiteUrl { error } => error. to_string ( ) ,
0 commit comments