diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-06-03 23:17:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-06-03 23:17:21 +0200 |
| commit | 1070d4b87f664e85ff7defa530727c97337d16db (patch) | |
| tree | 471bee57ad263527540a70f5e09be5dffeac44dd /frontend/util/index.js | |
| parent | 0325476d87d102f817108112772d39a64b5d1419 (diff) | |
saving nodes!!
Diffstat (limited to 'frontend/util/index.js')
| -rw-r--r-- | frontend/util/index.js | 44 |
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) => { |
