Skip to content

Commit 305504d

Browse files
committed
improve asset + fallback urls
1 parent ecad6c4 commit 305504d

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

MyApp.ServiceInterface/AppData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ public string AssetUrl(string url) => !url.Contains("://")
13931393
public string FallbackAssetUrl(string url) => !url.Contains("://")
13941394
? Config.FallbackAssetsBaseUrl != null && Config.FallbackAssetsBaseUrl != Config.AssetsBaseUrl
13951395
? Config.FallbackAssetsBaseUrl.CombineWith(url)
1396-
: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300'%3E%3Crect width='400' height='300' fill='%23f3f4f6'/%3E%3Cg transform='translate(200,150)'%3E%3Crect x='-50' y='-40' width='100' height='80' fill='none' stroke='%23d1d5db' stroke-width='2' rx='4'/%3E%3Ccircle cx='-25' cy='-15' r='8' fill='%23d1d5db'/%3E%3Cpath d='M-35 10 L-15 -10 L5 10 L25 -5 L25 25 L-35 25 Z' fill='%23d1d5db'/%3E%3C/g%3E%3Ctext x='200' y='220' text-anchor='middle' fill='%239ca3af' font-family='Arial, sans-serif' font-size='14'%3EImage not available%3C/text%3E%3C/svg%3E"
1396+
: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300'%3E%3Crect width='400' height='300' fill='%23364153'/%3E%3Cg transform='translate(200,150)'%3E%3Crect x='-50' y='-40' width='100' height='80' fill='none' stroke='%23d1d5db' stroke-width='2' rx='4'/%3E%3Ccircle cx='-25' cy='-15' r='8' fill='%23d1d5db'/%3E%3Cpath d='M-35 10 L-15 -10 L5 10 L25 -5 L25 25 L-35 25 Z' fill='%23d1d5db'/%3E%3C/g%3E%3Ctext x='200' y='220' text-anchor='middle' fill='%239ca3af' font-family='Arial, sans-serif' font-size='14'%3EImage not available%3C/text%3E%3C/svg%3E"
13971397
: url;
13981398
}
13991399

MyApp/wwwroot/pages/Generation.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646
<div v-if="isType('Audio')" class="w-full h-full cursor-pointer flex flex-col justify-between"
4747
@click.stop="refAudio?.player?.toggle()"
4848
>
49-
<img src="/img/bg-audio.svg" class="absolute top-0 left-0 h-20 w-full">
49+
<img :src="store.assetUrl('/img/bg-audio.svg')" class="absolute top-0 left-0 h-20 w-full">
5050
5151
<div class="mt-20 mb-12 flex-grow flex items-center">
5252
<svg class="mx-auto size-64 text-purple-600 dark:text-purple-400 mb-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -59,7 +59,8 @@ export default {
5959
<template v-else>
6060
<!-- Main Image - only show if rating is viewable -->
6161
<img v-if="selectedUrl && store.isRatingViewable(selectedArtifact)"
62-
:src="selectedUrl"
62+
:src="store.assetUrl(selectedUrl)"
63+
:onerror="store.imgOnError(selectedUrl)"
6364
:alt="selectedArtifact.caption || generation.description || 'Generated image'"
6465
class="max-w-full max-h-full object-contain"
6566
:class="{ 'cursor-zoom-in': !store.prefs.zoomIn, 'cursor-zoom-out':store.prefs.zoomIn }"
@@ -100,7 +101,8 @@ export default {
100101
:class="{ 'ring-2 ring-blue-500': artifact.url === selectedUrl }"
101102
@click="selectedUrl = artifact.url">
102103
<img v-if="store.isRatingViewable(artifact)"
103-
:src="artifact.url"
104+
:src="store.assetUrl(artifact.url)"
105+
:onerror="store.imgOnError(artifact.url)"
104106
:alt="'Artifact ' + artifact.id"
105107
class="w-full object-cover">
106108

MyApp/wwwroot/pages/Home.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export default {
4343
<!-- Image Container with dynamic aspect ratio -->
4444
<RouterLink :to="{ path:'/generations/' + artifact.generationId }">
4545
<div class="overflow-hidden bg-gray-100 dark:bg-gray-700" :style="'aspect-ratio: ' + getAspectRatio(artifact)">
46-
<img :src="store.assetUrl(artifact.url)"
47-
onerror="this.src=store.fallbackAssetUrl(artifact.url)"
46+
<img :src="store.assetUrl(artifact.url)"
47+
:onerror="store.imgOnError(artifact.url)"
4848
alt="Generated artifact"
4949
class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300 cursor-pointer"
5050
loading="lazy"

MyApp/wwwroot/pages/Images.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import RatingsBadge from "./components/RatingsBadge.mjs"
1212
export const ArtifactImage = {
1313
template:`<div v-if="artifact" class="overflow-hidden" :style="store.getBackgroundStyle(artifact) + ';' + imageStyle">
1414
<img :alt="artifact.prompt" :width="width" :height="height" :class="imageClass"
15-
:src="imageSrc" :loading="loading || 'lazy'" @error="imageSrc=store.fallbackAssetUrl(artifact.url)">
15+
:src="store.assetUrl(imageSrc)" :loading="loading || 'lazy'" :onerror="store.imgOnError(artifact.url)">
1616
</div>`,
1717
props: {
1818
/** @type {import('vue').PropType<Artifact>} */
@@ -328,7 +328,8 @@ export default {
328328
329329
<!-- Image -->
330330
<img
331-
:src="selectedImage.url"
331+
:src="store.assetUrl(selectedImage.url)"
332+
:onerror="store.imgOnError(selectedImage.url)"
332333
:alt="selectedImage.prompt || 'Generated image'"
333334
class="max-w-full max-h-full object-contain rounded-lg"
334335
:width="selectedImage.width"

MyApp/wwwroot/pages/lib/store.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ let o = {
13331333
},
13341334
/** Generate a placeholder image with an icon instead of solid black */
13351335
placeholderImageDataUri() {
1336-
return `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300'%3E%3Crect width='400' height='300' fill='%23f3f4f6'/%3E%3Cg transform='translate(200,150)'%3E%3Crect x='-50' y='-40' width='100' height='80' fill='none' stroke='%23d1d5db' stroke-width='2' rx='4'/%3E%3Ccircle cx='-25' cy='-15' r='8' fill='%23d1d5db'/%3E%3Cpath d='M-35 10 L-15 -10 L5 10 L25 -5 L25 25 L-35 25 Z' fill='%23d1d5db'/%3E%3C/g%3E%3Ctext x='200' y='220' text-anchor='middle' fill='%239ca3af' font-family='Arial, sans-serif' font-size='14'%3EImage not available%3C/text%3E%3C/svg%3E`
1336+
return `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 300'%3E%3Crect width='400' height='300' fill='%23364153'/%3E%3Cg transform='translate(200,150)'%3E%3Crect x='-50' y='-40' width='100' height='80' fill='none' stroke='%23d1d5db' stroke-width='2' rx='4'/%3E%3Ccircle cx='-25' cy='-15' r='8' fill='%23d1d5db'/%3E%3Cpath d='M-35 10 L-15 -10 L5 10 L25 -5 L25 25 L-35 25 Z' fill='%23d1d5db'/%3E%3C/g%3E%3Ctext x='200' y='220' text-anchor='middle' fill='%239ca3af' font-family='Arial, sans-serif' font-size='14'%3EImage not available%3C/text%3E%3C/svg%3E`
13371337
},
13381338

13391339
assetUrl(url) {
@@ -1352,6 +1352,9 @@ let o = {
13521352
: this.placeholderImageDataUri()
13531353
: url
13541354
},
1355+
imgOnError(url) {
1356+
return `this.src=${JSON.stringify(this.fallbackAssetUrl(url))}`
1357+
},
13551358

13561359
// Ratings
13571360
isRatingViewable(artifact) {

0 commit comments

Comments
 (0)