|
18 | 18 | import Divider from "src/svelte/shared/components/divider.svelte"; |
19 | 19 | import { fetchSocialMediaImage } from "../services/fetch-social-media-image"; |
20 | 20 | import { |
21 | | - getSocialMediaImageEntry, |
22 | | - isSocialMediaImageEntryExpired, |
23 | | - putSocialMediaImageUrl, |
24 | | - } from "../services/social-media-image-cache"; |
| 21 | + getSMICacheEntry, |
| 22 | + isSMICacheEntryExpired, |
| 23 | + putSMICacheEntry, |
| 24 | + } from "../services/smi-cache"; |
25 | 25 | import { CoverImageFit } from "src/types"; |
| 26 | + import Logger from "js-logger"; |
26 | 27 |
|
27 | 28 | type SocialMediaImageResult = { |
28 | 29 | status: "SUCCESS" | "NOT_FOUND" | "EXPIRED" | "NO_IMAGE"; |
|
134 | 135 | } |
135 | 136 |
|
136 | 137 | async function handleImageError(event: Event) { |
| 138 | + Logger.trace({ |
| 139 | + fileName: "grid-card.svelte", |
| 140 | + functionName: "handleImageError", |
| 141 | + message: "called", |
| 142 | + }); |
| 143 | +
|
137 | 144 | const target = event.target as HTMLImageElement; |
138 | 145 | target.onerror = null; // Prevent infinite loop |
139 | 146 |
|
| 147 | + Logger.debug( |
| 148 | + { |
| 149 | + fileName: "grid-card.svelte", |
| 150 | + functionName: "handleImageError", |
| 151 | + message: "target.src", |
| 152 | + }, |
| 153 | + { |
| 154 | + src: target.src, |
| 155 | + }, |
| 156 | + ); |
| 157 | +
|
140 | 158 | let websiteUrl = target.src; |
141 | 159 | if (websiteUrl.endsWith("/")) { |
142 | 160 | websiteUrl = websiteUrl.slice(0, -1); // Remove the trailing slash |
143 | 161 | } |
| 162 | + Logger.debug( |
| 163 | + { |
| 164 | + fileName: "grid-card.svelte", |
| 165 | + functionName: "handleImageError", |
| 166 | + message: "websiteUrl", |
| 167 | + }, |
| 168 | + { |
| 169 | + websiteUrl, |
| 170 | + }, |
| 171 | + ); |
144 | 172 |
|
145 | 173 | if (loadSocialMediaImage) { |
146 | 174 | const socialUrl = await fetchSocialMediaImage(websiteUrl); |
147 | 175 | if (socialUrl) { |
148 | | - await putSocialMediaImageUrl(websiteUrl, socialUrl); |
| 176 | + await putSMICacheEntry(websiteUrl, socialUrl); |
149 | 177 | target.src = socialUrl; |
150 | 178 | } else { |
151 | | - await putSocialMediaImageUrl(websiteUrl, null); |
| 179 | + await putSMICacheEntry(websiteUrl, null); |
152 | 180 | } |
153 | 181 | } |
154 | 182 | } |
155 | 183 |
|
156 | 184 | async function getCachedSocialMediaImageUrl( |
157 | 185 | websiteUrl: string, |
158 | 186 | ): Promise<SocialMediaImageResult> { |
159 | | - const entry = await getSocialMediaImageEntry(websiteUrl); |
| 187 | + const entry = await getSMICacheEntry(websiteUrl); |
160 | 188 |
|
161 | 189 | if (entry) { |
162 | 190 | const { socialMediaImageUrl } = entry; |
163 | 191 |
|
164 | 192 | if (socialMediaImageUrl) { |
165 | | - const isExpired = await isSocialMediaImageEntryExpired(entry); |
| 193 | + const isExpired = await isSMICacheEntryExpired(entry); |
166 | 194 | if (!isExpired) { |
167 | 195 | return { status: "SUCCESS", url: socialMediaImageUrl }; |
168 | 196 | } else { |
|
179 | 207 | $: if (imageUrl) { |
180 | 208 | isImageLoaded = false; |
181 | 209 | getCachedSocialMediaImageUrl(imageUrl).then((result) => { |
| 210 | + Logger.debug( |
| 211 | + { |
| 212 | + fileName: "grid-card.svelte", |
| 213 | + functionName: "getCachedSocialMediaImage", |
| 214 | + message: "result", |
| 215 | + }, |
| 216 | + { |
| 217 | + result, |
| 218 | + }, |
| 219 | + ); |
| 220 | +
|
182 | 221 | const { status, url } = result; |
183 | 222 | if (status === "SUCCESS") { |
184 | 223 | imgSrc = url!; |
|
0 commit comments