summaryrefslogtreecommitdiff
path: root/frontend/util/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/util/index.js')
-rw-r--r--frontend/util/index.js44
1 files changed, 25 insertions, 19 deletions
diff --git a/frontend/util/index.js b/frontend/util/index.js
index 02a7a4d..e951182 100644
--- a/frontend/util/index.js
+++ b/frontend/util/index.js
@@ -92,25 +92,31 @@ export const uploadUri = ({ sha256, ext }) => '/static/data/uploads' + sha256_tr
export const metadataUri = (sha256, tag) => '/metadata/' + sha256 + '/' + tag + '/'
export const keyframeUri = (sha256, frame) => '/metadata/' + sha256 + '/keyframe/' + pad(frame, 6) + '/'
-export const preloadImage = opt => {
- let { verified, hash, frame, url } = opt
- if (hash && frame) {
- url = imageUrl(verified, hash, frame, 'md')
- }
- const image = new Image()
- let loaded = false
- image.onload = () => {
- if (loaded) return
- loaded = true
- image.onload = null
- }
- // console.log(img.src)
- image.crossOrigin = 'anonymous'
- image.src = url
- if (image.complete) {
- image.onload()
- }
-}
+export const preloadImage = url => (
+ new Promise((resolve, reject) => {
+ const image = new Image()
+ let loaded = false
+ image.onload = () => {
+ if (loaded) return
+ loaded = true
+ image.onload = null
+ image.onerror = null
+ resolve(image)
+ }
+ image.onerror = () => {
+ if (loaded) return
+ image.onload = null
+ image.onerror = null
+ resolve(image)
+ }
+ // console.log(img.src)
+ // image.crossOrigin = 'anonymous'
+ image.src = url
+ if (image.complete) {
+ image.onload()
+ }
+ })
+)
export const cropImage = (url, crop) => {
return new Promise((resolve, reject) => {