-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: async secureDeliveryProxyUrlResolver
#677
Changes from all commits
9181cea
e9e1a8b
3917397
f2c871e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,9 +138,9 @@ export class EditorImageFader extends Block { | |
* @param {String} [options.filter] | ||
* @param {String} [options.operation] | ||
* @param {Number} [options.value] | ||
* @returns {String} | ||
* @returns {Promise<String>} | ||
*/ | ||
_imageSrc({ url = this._url, filter = this._filter, operation, value } = {}) { | ||
async _imageSrc({ url = this._url, filter = this._filter, operation, value } = {}) { | ||
let transformations = { ...this._transformations }; | ||
|
||
if (operation) { | ||
|
@@ -149,17 +149,17 @@ export class EditorImageFader extends Block { | |
|
||
// do not use getBoundingClientRect because scale transform affects it | ||
let width = this.offsetWidth; | ||
return this.proxyUrl(viewerImageSrc(url, width, transformations)); | ||
return await this.proxyUrl(viewerImageSrc(url, width, transformations)); | ||
} | ||
|
||
/** | ||
* @private | ||
* @param {String} operation | ||
* @param {Number} value | ||
* @returns {Keypoint} | ||
* @returns {Promise<Keypoint>} | ||
*/ | ||
_constructKeypoint(operation, value) { | ||
let src = this._imageSrc({ operation, value }); | ||
async _constructKeypoint(operation, value) { | ||
let src = await this._imageSrc({ operation, value }); | ||
Comment on lines
+161
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review asynchronous methods Both Consider adding checks or using techniques like debouncing or locking to ensure that the state used in these methods is still valid when the asynchronous operations complete. Also applies to: 190-197 |
||
return { | ||
src, | ||
image: null, | ||
|
@@ -187,14 +187,14 @@ export class EditorImageFader extends Block { | |
* @param {String | null} filter | ||
* @param {Number} value | ||
*/ | ||
_addKeypoint(operation, filter, value) { | ||
async _addKeypoint(operation, filter, value) { | ||
let shouldSkip = () => | ||
!this._isSame(operation, filter) || this._value !== value || !!this._keypoints.find((kp) => kp.value === value); | ||
|
||
if (shouldSkip()) { | ||
return; | ||
} | ||
let keypoint = this._constructKeypoint(operation, value); | ||
let keypoint = await this._constructKeypoint(operation, value); | ||
let image = new Image(); | ||
image.src = keypoint.src; | ||
let stop = this._handleImageLoading(keypoint.src); | ||
|
@@ -308,10 +308,10 @@ export class EditorImageFader extends Block { | |
} | ||
|
||
/** @param {import('./types.js').Transformations} transformations */ | ||
setTransformations(transformations) { | ||
async setTransformations(transformations) { | ||
this._transformations = transformations; | ||
if (this._previewImage) { | ||
let src = this._imageSrc(); | ||
let src = await this._imageSrc(); | ||
Comment on lines
+311
to
+314
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify error handling in The method This change adds error handling to the
|
||
let stop = this._handleImageLoading(src); | ||
this._previewImage.src = src; | ||
this._previewImage.addEventListener('load', stop, { once: true }); | ||
|
@@ -335,11 +335,11 @@ export class EditorImageFader extends Block { | |
* @param {Number} options.value | ||
* @param {String} [options.filter] | ||
*/ | ||
preload({ url, filter, operation, value }) { | ||
async preload({ url, filter, operation, value }) { | ||
this._cancelBatchPreload && this._cancelBatchPreload(); | ||
|
||
let keypoints = keypointsRange(operation, value); | ||
let srcList = keypoints.map((kp) => this._imageSrc({ url, filter, operation, value: kp })); | ||
let srcList = await Promise.all(keypoints.map((kp) => this._imageSrc({ url, filter, operation, value: kp }))); | ||
Comment on lines
+338
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling to The This change introduces error handling to the
ToolsBiome
|
||
let { cancel } = batchPreloadImages(srcList); | ||
|
||
this._cancelBatchPreload = cancel; | ||
|
@@ -400,7 +400,7 @@ export class EditorImageFader extends Block { | |
* @param {String} [options.filter] | ||
* @param {Boolean} [options.fromViewer] | ||
*/ | ||
activate({ url, operation, value, filter, fromViewer }) { | ||
async activate({ url, operation, value, filter, fromViewer }) { | ||
this._isActive = true; | ||
this._hidden = false; | ||
this._url = url; | ||
|
@@ -411,12 +411,14 @@ export class EditorImageFader extends Block { | |
|
||
let isOriginal = typeof value !== 'number' && !filter; | ||
if (isOriginal) { | ||
let src = this._imageSrc({ operation, value }); | ||
let src = await this._imageSrc({ operation, value }); | ||
this._setOriginalSrc(src); | ||
this._container && this._container.remove(); | ||
return; | ||
} | ||
this._keypoints = keypointsRange(operation, value).map((keyValue) => this._constructKeypoint(operation, keyValue)); | ||
this._keypoints = await Promise.all( | ||
keypointsRange(operation, value).map((keyValue) => this._constructKeypoint(operation, keyValue)), | ||
); | ||
|
||
this._update(operation, value); | ||
this._initNodes(); | ||
|
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.
Type assertion added for
transformations
.The use of
@ts-expect-error
indicates that there is a known TypeScript issue here. It would be beneficial to resolve this issue rather than suppressing the error. If the type assertion is incorrect, it could lead to runtime errors.Committable suggestion