Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ local.properties
/android/.gradle
/android/.kotlin
/android/.idea
/android/app/src/main/assets/wp_com_oauth_credentials.json

## Production Build Products
/android/Gutenberg/src/main/assets/assets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class RESTAPIRepository(
private val json = Json { ignoreUnknownKeys = true }

private val apiRoot = configuration.siteApiRoot.trimEnd('/')
private val editorSettingsUrl = "$apiRoot$EDITOR_SETTINGS_PATH"
private val activeThemeUrl = "$apiRoot$ACTIVE_THEME_PATH"
private val siteSettingsUrl = "$apiRoot$SITE_SETTINGS_PATH"
private val postTypesUrl = "$apiRoot$POST_TYPES_PATH"
private val namespace = configuration.siteApiNamespace.firstOrNull()
private val editorSettingsUrl = buildNamespacedUrl(EDITOR_SETTINGS_PATH)
private val activeThemeUrl = buildNamespacedUrl(ACTIVE_THEME_PATH)
private val siteSettingsUrl = buildNamespacedUrl(SITE_SETTINGS_PATH)
private val postTypesUrl = buildNamespacedUrl(POST_TYPES_PATH)

/**
* Cleanup any expired cache entries.
Expand Down Expand Up @@ -72,7 +73,7 @@ class RESTAPIRepository(
}

private fun buildPostUrl(id: Int): String {
return "$apiRoot/wp/v2/posts/$id?context=edit"
return buildNamespacedUrl("/wp/v2/posts/$id?context=edit")
}

// MARK: Editor Settings
Expand Down Expand Up @@ -139,7 +140,7 @@ class RESTAPIRepository(
}

private fun buildPostTypeUrl(type: String): String {
return "$apiRoot/wp/v2/types/$type?context=edit"
return buildNamespacedUrl("/wp/v2/types/$type?context=edit")
}

// MARK: GET Active Theme
Expand Down Expand Up @@ -212,6 +213,26 @@ class RESTAPIRepository(
return urlResponse
}

/**
* Builds a URL from the API root and path, inserting the site API namespace
* after the version segment if one is configured.
*
* For example, with namespace `sites/123/` and path `/wp/v2/types`:
* the result is `$apiRoot/wp/v2/sites/123/types`.
*/
private fun buildNamespacedUrl(path: String): String {
if (namespace == null) {
return "$apiRoot$path"
}

val parts = path.removePrefix("/").split("/", limit = 3)
if (parts.size < 3) {
return "$apiRoot$path"
}

return "$apiRoot/${parts[0]}/${parts[1]}/$namespace${parts[2]}"
}

companion object {
private const val EDITOR_SETTINGS_PATH = "/wp-block-editor/v1/settings"
private const val ACTIVE_THEME_PATH = "/wp/v2/themes?context=edit&status=active"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,13 @@ class EditorAssetsLibrary(

private fun editorAssetsUrl(configuration: EditorConfiguration): String {
val baseUrl = configuration.siteApiRoot.trimEnd('/')
return "$baseUrl/wpcom/v2/editor-assets?exclude=core,gutenberg"
val namespace = configuration.siteApiNamespace.firstOrNull()

return if (namespace != null) {
"$baseUrl/wpcom/v2/${namespace}editor-assets?exclude=core,gutenberg"
} else {
"$baseUrl/wpcom/v2/editor-assets?exclude=core,gutenberg"
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".GutenbergKitApplication"
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down Expand Up @@ -32,6 +33,16 @@
android:scheme="gutenbergkit" >
</data>
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="wpcom-authorized"
android:scheme="gutenbergkit" >
</data>
</intent-filter>
</activity>
<activity
android:name=".EditorActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"client_id": 0,
"client_secret": ""
}
Loading
Loading