From 1070d4b87f664e85ff7defa530727c97337d16db Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 3 Jun 2020 23:17:21 +0200 Subject: saving nodes!! --- frontend/util/index.js | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'frontend/util/index.js') 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) => { -- cgit v1.2.3-70-g09d2