Skip to content

Commit e6d6139

Browse files
jkmasselclaude
andcommitted
Use WpApiClient apiRoot for route discovery instead of manifest fetching
Remove fetchWpComManifestRoutes and fetchSiteManifestRoutes from WpApiClientProvider. EditorSettingsRepository now uses the standard WpApiClient.request { it.apiRoot().get() } for all site types, which already handles WP.com vs self-hosted URL resolution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a48dd38 commit e6d6139

File tree

2 files changed

+0
-121
lines changed

2 files changed

+0
-121
lines changed

WordPress/src/main/java/org/wordpress/android/repositories/EditorSettingsRepository.kt

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -81,65 +81,6 @@ class EditorSettingsRepository @Inject constructor(
8181
}
8282

8383
private suspend fun fetchRouteSupport(site: SiteModel) {
84-
if (site.isWPCom || site.isUsingWpComRestApi) {
85-
fetchRouteSupportViaManifest(site)
86-
} else if (
87-
!site.apiRestUsernamePlain.isNullOrEmpty() &&
88-
!site.apiRestPasswordPlain.isNullOrEmpty()
89-
) {
90-
fetchRouteSupportViaClient(site)
91-
} else {
92-
fetchRouteSupportViaSiteManifest(site)
93-
}
94-
}
95-
96-
private suspend fun fetchRouteSupportViaManifest(
97-
site: SiteModel
98-
) {
99-
val routes = wpApiClientProvider
100-
.fetchWpComManifestRoutes(site)
101-
applyManifestRoutes(site, routes)
102-
}
103-
104-
private suspend fun fetchRouteSupportViaSiteManifest(
105-
site: SiteModel
106-
) {
107-
val routes = wpApiClientProvider
108-
.fetchSiteManifestRoutes(site)
109-
applyManifestRoutes(site, routes)
110-
}
111-
112-
private fun applyManifestRoutes(
113-
site: SiteModel,
114-
routes: Set<String>?
115-
) {
116-
if (routes != null) {
117-
val supportsSettings = routes.any {
118-
it.contains("wp-block-editor/") &&
119-
it.endsWith("/settings")
120-
}
121-
val supportsAssets = routes.any {
122-
it.endsWith("/editor-assets")
123-
}
124-
appPrefsWrapper.setSiteSupportsEditorSettings(
125-
site, supportsSettings
126-
)
127-
appPrefsWrapper.setSiteSupportsEditorAssets(
128-
site, supportsAssets
129-
)
130-
} else {
131-
appPrefsWrapper.setSiteSupportsEditorSettings(
132-
site, false
133-
)
134-
appPrefsWrapper.setSiteSupportsEditorAssets(
135-
site, false
136-
)
137-
}
138-
}
139-
140-
private suspend fun fetchRouteSupportViaClient(
141-
site: SiteModel
142-
) {
14384
val client = wpApiClientProvider.getWpApiClient(site)
14485
val response = client.request { it.apiRoot().get() }
14586

libs/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/rs/WpApiClientProvider.kt

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -166,68 +166,6 @@ class WpApiClientProvider @Inject constructor(
166166
}
167167
}
168168

169-
/**
170-
* Fetches the WP.com site manifest (API root index) and
171-
* returns the set of route paths.
172-
* Returns `null` on failure.
173-
*/
174-
suspend fun fetchWpComManifestRoutes(
175-
site: SiteModel
176-
): Set<String>? {
177-
val siteHost = URL(site.url).host
178-
val manifestUrl =
179-
"https://public-api.wordpress.com" +
180-
"/wp-json/?rest_route=/sites/$siteHost"
181-
val token = accountStore.accessToken ?: return null
182-
return fetchManifestRoutes(manifestUrl, "Bearer $token")
183-
}
184-
185-
/**
186-
* Fetches the site's API root index directly (no auth)
187-
* and returns the set of route paths.
188-
* Returns `null` on failure.
189-
*/
190-
suspend fun fetchSiteManifestRoutes(
191-
site: SiteModel
192-
): Set<String>? {
193-
val manifestUrl = site.buildUrl()
194-
return fetchManifestRoutes(manifestUrl)
195-
}
196-
197-
@Suppress("TooGenericExceptionCaught")
198-
private suspend fun fetchManifestRoutes(
199-
url: String,
200-
authHeader: String? = null
201-
): Set<String>? {
202-
val request = okhttp3.Request.Builder()
203-
.url(url)
204-
.apply {
205-
if (authHeader != null) {
206-
addHeader("Authorization", authHeader)
207-
}
208-
}
209-
.build()
210-
val client = OkHttpClient.Builder().build()
211-
return kotlinx.coroutines.withContext(
212-
kotlinx.coroutines.Dispatchers.IO
213-
) {
214-
try {
215-
client.newCall(request).execute().use { resp ->
216-
if (!resp.isSuccessful) return@use null
217-
val body = resp.body?.string()
218-
?: return@use null
219-
val json = org.json.JSONObject(body)
220-
val routes =
221-
json.optJSONObject("routes")
222-
?: return@use null
223-
routes.keys().asSequence().toSet()
224-
}
225-
} catch (e: Exception) {
226-
null
227-
}
228-
}
229-
}
230-
231169
fun getApiRootUrlFrom(site: SiteModel): String = site.buildUrl()
232170

233171
private fun SiteModel.buildUrl(): String =

0 commit comments

Comments
 (0)