Skip to content
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

Fix for uploading images. #450

Merged
merged 6 commits into from
Jun 9, 2023
Merged

Conversation

pszczesniak
Copy link
Contributor

To get correct url we need to do one more fetch (like GitHub does).

Closes #444.

@mlewand mlewand self-requested a review June 7, 2023 07:23
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have serious doubt in regard to order of asynchronous code here.

src/app/plugins/githubuploadadapter.js Outdated Show resolved Hide resolved
src/app/plugins/githubuploadadapter.js Outdated Show resolved Hide resolved
src/app/plugins/githubuploadadapter.js Outdated Show resolved Hide resolved
@dufipl

This comment was marked as resolved.

@dufipl

This comment was marked as resolved.

@charlttsie

This comment was marked as resolved.

@pszczesniak
Copy link
Contributor Author

pszczesniak commented Jun 9, 2023

#450 (comment) Fixed in e10de92.
#450 (comment) Fixed in e10de92.
#450 (comment) Fixed in e10de92.

@pszczesniak pszczesniak requested a review from mlewand June 9, 2023 08:46
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some code to be polished.

We'll do a live-review and run though these items.

// The final URL of the file is already known, even before the upload. We save it here.
returnUrl = response.asset.href;
// Assign asset response to variable
assetResponse = response;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name for this variable should be improved.

assetResponse implies that it's a response from the request made by sendAssetRequest - while that's not the case here.

This is a result of requesting /upload/policies/assets - so I'd say asset upload policy (with an emphasize on policy). So a more fitting name would be uploadPolicyResponse.

Actually the comments here could be improved a bit.

return this.sendAssetRequest( assetResponse )
.then( returnUrl => {
// Upload concluded! Simply send the file URL back, according to CKEditor specs.
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why decorating returned URL format from plain string to a object here?

Since we created a new method sendAssetRequest, wouldn't it better to encapsulate this logic there?

.then( response => response.json() )
.then( response => {
// The final URL of the file is already known, even before the upload. We save it here.
return response.href;

default: returnUrl
};
// Step 3: Retrieve the final uploaded asset URL using response data gathered on Step 1.
return this.sendAssetRequest( assetResponse )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the sendAssetRequest be a private method, just like the others around here. No need to expose it.

@@ -129,10 +129,14 @@ export class Adapter {
this._sendRequest( data );
} ) )
.then( ( /* { file, response } */ ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since handling here became very messy I took the liberty to extract all of these 3 promise handlers to 3 separate functions with decent names so that it's more obvious for people what they do, and so that they became somewhat more separated.

@mlewand mlewand self-requested a review June 9, 2023 10:37
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes added in 8e1c3b1.

Code looks good, let's wait for R+ from the QA team. Once we have it we can merge it straight away and release the fixed version!

@dufipl
Copy link

dufipl commented Jun 9, 2023

No image preview when adding inline comment during code review

Steps

  1. Open the inline code comment editor within a PR
  2. Add an image to the comment

Result

No preview, but after a while it is possible to send comments and image show up:

Nagranie.z.ekranu.2023-06-9.o.15.07.54.mov

@pszczesniak
Copy link
Contributor Author

#450 (comment) Need to take a closer look on some CSS that probably leaks into this type of editor:

@pszczesniak
Copy link
Contributor Author

#450 (comment) fixed in 7166dee.

@mlewand mlewand merged commit 946fb5b into master Jun 9, 2023
@mlewand mlewand deleted the ghw/444-uploading-images-doesnt-work branch June 9, 2023 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uploading images doesn't work
4 participants