[Gutenberg] Image Size networking (native)#12714
Conversation
10e3238 to
cf662f2
Compare
|
You can trigger an installable build for these changes by visiting CircleCI here. |
Now it properly checks if the url is the one of an image
…e-size-networking-native
This is only required if the network call is started from the JS side.
| self.blog = blog | ||
| } | ||
|
|
||
| func request(response: @escaping Response) { |
There was a problem hiding this comment.
I found quite confusing the response/Response naming for a callback, when the argument to that callback will be the actual response. Maybe we can use the more generic completion?
| } | ||
|
|
||
| private var selfHostedPath: String { | ||
| let removedEditContext = path.replacingOccurrences(of: "context=edit", with: "context=view") |
There was a problem hiding this comment.
Switching the context to view happens to work fine for this specific use case, but it likely won't for others. I don't like the idea of implementing it generically and pretending that apiFetch can now work for anything else, as it might lead to subtle undetected bugs.
Since I understand this is a temporary solution to an immediate problem, I think we should enforce that this system only works with a known set of API paths. So for any request other than getting media sizes, I would probably return a Not implemented error, or ignore the request and just log a warning.
There was a problem hiding this comment.
I think adding this kind of guard makes sense. Assuming we always expect the platforms to be in sync, it would be nice to have that guard on the JS-side so that we don't have to replicate it on both platforms.
There was a problem hiding this comment.
I thought on having some kind of white list of paths that we accept to avoid surprises.
This implementation also only do GET requests so far, so there's another reason for this. 👍
I agree that is probably better to do this on JS side, then probably this context change should also go on the JS side?
There was a problem hiding this comment.
I agree that is probably better to do this on JS side, then probably this context change should also go on the JS side?
👍 The more path manipulation we move to the JS side (i.e., the siteId if that's available in JS), the better imo. I was planning to investigate that once I got the Android implementation wrapped up.
There was a problem hiding this comment.
The SiteID is a WPCom thing, probably we don't want it on gutenberg repo.
| @@ -0,0 +1,62 @@ | |||
| import Alamofire | |||
|
|
|||
| struct GutenbergNetworkRequest { | |||
There was a problem hiding this comment.
This is just a bit of a rant, but specially after doing JS for a while, I find interesting how reluctant we all are to use top level functions on Swift. There's no point in rewriting this, but it's something that keeps catching my attention 😁
There was a problem hiding this comment.
I like the Struct to pack some properties inside it, and have methods with less arguments.
At first I did static functions (that would work as well as top level functions), but I didn't like having all the internal helper functions needing the whole set of arguments.
…ry/gutenberg-image-size-networking-native
|
I'm currently seeing an error when try to update the size of an image for a self-hosted site. I'll try to investigate this some tomorrow. I am seeing this show up in the logs, although I don't know whether it is related yet: |
|
Hey @etoledom ! I merged |
Helps to avoid getting unexpected responses and hard to track down bugs: wordpress-mobile/WordPress-iOS#12714 (comment)
…ry/gutenberg-image-size-networking-native
ee6b8c8 to
67065a0
Compare
|
There are a few known issues: wordpress-mobile/gutenberg-mobile#1455 (comment) - I'm hoping those are not blockers for this PR (I'm currently working on those). Keeping that in mind, I believe this is ready for another 👀 |
|
Hey there! I've moved this to 13.8 since 13.7 has been cut. If you want this to make it to 13.7, please feel free to ping me. |
SergioEstevao
left a comment
There was a problem hiding this comment.
Working fine!
Tested it on WP.com regular, WP.com Atomic and self-hosted sites.
…e-size-networking-native
Alternative to #12706
As a proof of concept, this PR implements the minimum necessary to make Image Size works.
In the future we might need to create a more generic api call with a dynamic request method (given from gutenberg). We also might need to handle other api version Paths.
Related PRs:
gutenberg-mobile: wordpress-mobile/gutenberg-mobile#1455To test:
Update release notes:
RELEASE-NOTES.txtif necessary.