From 0925c28d5a4f328264c39d5591dc736795541683 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 6 May 2023 16:25:09 +0000 Subject: [PATCH] fetch image?? --- .../src/components/MkImgWithBlurhash.vue | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/components/MkImgWithBlurhash.vue b/packages/frontend/src/components/MkImgWithBlurhash.vue index 22619ba2fd..ebca855ed0 100644 --- a/packages/frontend/src/components/MkImgWithBlurhash.vue +++ b/packages/frontend/src/components/MkImgWithBlurhash.vue @@ -1,6 +1,5 @@ @@ -62,13 +61,9 @@ const offscreen = computed(() => { }, [_offscreen]); return _offscreen; }); -let loaded = $ref(false); let canvasWidth = $ref(props.width); let canvasHeight = $ref(props.height); - -function onLoad() { - loaded = true; -} +let url = $ref(); watch([() => props.width, () => props.height], () => { const ratio = props.width / props.height; @@ -83,6 +78,20 @@ watch([() => props.width, () => props.height], () => { immediate: true, }); +watch([() => props.src], () => { + if (url) { + URL.revokeObjectURL(url); + url = undefined; + } + if (props.src) { + fetch(props.src, { mode: 'no-cors' }) + .then((res) => res.blob()) + .then((blob) => { + url = URL.createObjectURL(blob); + }); + } +}, { immediate: true }); + function draw() { if (props.hash == null || !offscreen.value) return; worker.postMessage({ @@ -103,7 +112,7 @@ onMounted(() => { } else { // 100ms後に画像の読み込みが完了していなければblurhashを描画する setTimeout(() => { - if (!loaded) { + if (!url) { draw(); } }, 100);