-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support media single fetch, upload, and delete using WordPress-rs #22036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support media single fetch, upload, and delete using WordPress-rs #22036
Conversation
…ort-media-upload-and-delete-application-password
Generated by 🚫 Danger |
|
App Name | ![]() |
|
Flavor | Jalapeno | |
Build Type | Debug | |
Version | pr22036-ab0ecb1 | |
Commit | ab0ecb1 | |
Direct Download | wordpress-prototype-build-pr22036-ab0ecb1.apk |
|
App Name | ![]() |
|
Flavor | Jalapeno | |
Build Type | Debug | |
Version | pr22036-ab0ecb1 | |
Commit | ab0ecb1 | |
Direct Download | jetpack-prototype-build-pr22036-ab0ecb1.apk |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #22036 +/- ##
=======================================
Coverage 39.02% 39.02%
=======================================
Files 2153 2153
Lines 101494 101494
Branches 15585 15585
=======================================
Hits 39613 39613
Misses 58384 58384
Partials 3497 3497 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates media operations (fetch, upload, delete) from XML-RPC to WordPress REST API using the WordPress-rs client for self-hosted sites with application passwords. The changes introduce a new REST API flow alongside existing XML-RPC and WordPress.com API flows.
- Adds new MediaRSApiRestClient for WordPress REST API operations
- Updates MediaStore to route self-hosted REST API requests to the new client
- Implements fetch, upload, and delete functionality with proper error handling
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
MediaStore.java | Routes self-hosted REST API calls to new MediaRSApiRestClient |
MediaRSApiRestClient.kt | Implements media operations using WordPress-rs with authentication and error handling |
...c/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRSApiRestClient.kt
Outdated
Show resolved
Hide resolved
...c/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/media/MediaRSApiRestClient.kt
Outdated
Show resolved
Hide resolved
dispatcher.dispatch(UploadActionBuilder.newUploadedMediaAction(payload)) | ||
} | ||
|
||
private fun getWpApiClient(site: SiteModel): WpApiClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getWpApiClient method creates a new WpApiClient instance on every call. Consider caching the client instance per site to avoid unnecessary object creation and potential connection overhead.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to cache the object because every call is associated with a specific site. Maybe we could create a map to store one client per site. I'm not sure that won't create other problems, though.
Anyway, we were advised that WpApiClient
is supporting multiple instances and created to be used that way.
…ort-media-upload-and-delete-application-password
Project dependencies changeslist! Upgraded Dependencies
rs.wordpress.api:android:trunk-0d7174336f381588dd577e60384225fa7b9f80c4, (changed from trunk-1ae11b4e897192f5064912d201e92539eb0b3416)
rs.wordpress.api:kotlin:trunk-0d7174336f381588dd577e60384225fa7b9f80c4, (changed from trunk-1ae11b4e897192f5064912d201e92539eb0b3416) tree +--- project :libs:fluxc
-| \--- rs.wordpress.api:android:trunk-1ae11b4e897192f5064912d201e92539eb0b3416
-| +--- com.squareup.okhttp3:okhttp:4.12.0 (*)
-| +--- com.squareup.okhttp3:okhttp-tls:4.12.0
-| | +--- com.squareup.okhttp3:okhttp:4.12.0 (*)
-| | +--- com.squareup.okio:okio:3.6.0 -> 3.9.0 (*)
-| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.9.10 (*)
-| +--- net.java.dev.jna:jna:5.17.0
-| +--- rs.wordpress.api:kotlin:trunk-1ae11b4e897192f5064912d201e92539eb0b3416
-| | +--- com.squareup.okhttp3:okhttp:4.12.0 (*)
-| | +--- com.squareup.okhttp3:okhttp-tls:4.12.0 (*)
-| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2 (*)
-| | \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 (*)
-| \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 (*)
+| \--- rs.wordpress.api:android:trunk-0d7174336f381588dd577e60384225fa7b9f80c4
+| +--- com.squareup.okhttp3:okhttp:4.12.0 (*)
+| +--- com.squareup.okhttp3:okhttp-tls:4.12.0
+| | +--- com.squareup.okhttp3:okhttp:4.12.0 (*)
+| | +--- com.squareup.okio:okio:3.6.0 -> 3.9.0 (*)
+| | \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21 -> 1.9.10 (*)
+| +--- net.java.dev.jna:jna:5.17.0
+| +--- rs.wordpress.api:kotlin:trunk-0d7174336f381588dd577e60384225fa7b9f80c4
+| | +--- com.squareup.okhttp3:okhttp:4.12.0 (*)
+| | +--- com.squareup.okhttp3:okhttp-tls:4.12.0 (*)
+| | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2 (*)
+| | \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 (*)
+| \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 (*)
-\--- rs.wordpress.api:android:trunk-1ae11b4e897192f5064912d201e92539eb0b3416 (*)
+\--- rs.wordpress.api:android:trunk-0d7174336f381588dd577e60384225fa7b9f80c4 (*) |
val client = getWpApiClient(site) | ||
|
||
val mediaResponse = client.request { requestBuilder -> | ||
requestBuilder.media().retrieveWithEditContext(media.mediaId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ This is for my own understanding: if we retrieve media with an edit context, does that mean that users without edit privilege will be unable to fetch media?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. And probably @oguzkocer will better answer this question.
Here is the context:
We are not differentiating between media access when requesting it in the client right now, so I opted to ask for the less restrictive media mode like iOS seems to be doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we retrieve media with an edit context, does that mean that users without edit privilege will be unable to fetch media?
That's correct. I think we shouldn't even show the Media
page if the user doesn't have these permissions. Best way to go about this is probably to check how wp-admin looks/works for a user with subscriber role.
…lete-application-password
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, nice work!
Description
Depends on: Automattic/wordpress-rs#810
This PR is migrating some of the media calls of our current XML-RPC flow.
Specifically, we are now allowing single media fetching, upload, and delete media.
All of these new flows are integrated with FluxC since is the common point from where all the UI calls are centralised. I have created a new MediaClient to easily isolate the new code from the FluxC module so it will make FluxC migration easier.
Testing instructions
Verify you can browse media
Verify you can upload media
Verify you can delete media
Verify you can upload media directly when writing a post
Do other smoke tests with media
Screen.Recording.2025-07-21.at.16.40.58.mov