|
156 | 156 | }, |
157 | 157 | ); |
158 | 158 |
|
159 | | - let websiteUrl = target.src; |
160 | | - if (websiteUrl.endsWith("/")) { |
161 | | - websiteUrl = websiteUrl.slice(0, -1); // Remove the trailing slash |
162 | | - } |
163 | | - Logger.debug( |
164 | | - { |
165 | | - fileName: "grid-card.svelte", |
166 | | - functionName: "handleImageError", |
167 | | - message: "websiteUrl", |
168 | | - }, |
169 | | - { |
170 | | - websiteUrl, |
171 | | - }, |
172 | | - ); |
173 | | -
|
174 | 159 | if (loadSocialMediaImage) { |
175 | | - const socialUrl = await fetchSocialMediaImage(websiteUrl); |
| 160 | + const socialUrl = await fetchSocialMediaImage(target.src); |
176 | 161 | if (socialUrl) { |
177 | | - await putSMICacheEntry(websiteUrl, socialUrl); |
| 162 | + await putSMICacheEntry(target.src, socialUrl); |
178 | 163 | target.src = socialUrl; |
179 | 164 | } else { |
180 | | - await putSMICacheEntry(websiteUrl, null); |
| 165 | + await putSMICacheEntry(target.src, null); |
181 | 166 | } |
182 | 167 | } |
183 | 168 | } |
|
190 | 175 | functionName: "getCachedSocialMediaUrl", |
191 | 176 | message: "result", |
192 | 177 | }); |
193 | | - const entry = await getSMICacheEntry(websiteUrl); |
| 178 | +
|
| 179 | + //e.target.src will use the DOM href which may end in a slash |
| 180 | + //target.src will output https://x.com/ if the URL is https://x.com |
| 181 | + //this will cause the cache to not find the image |
| 182 | + //We need to use the URL API to get a consistent URL format |
| 183 | + //See line 160 |
| 184 | + const url = new URL(websiteUrl); |
| 185 | + const entry = await getSMICacheEntry(url.href); |
194 | 186 |
|
195 | 187 | if (entry) { |
196 | 188 | const { smiUrl } = entry; |
197 | 189 |
|
198 | 190 | if (smiUrl) { |
199 | 191 | const isExpired = await isSMICacheEntryExpired(entry); |
200 | 192 | if (!isExpired) { |
201 | | - return { status: "SUCCESS", websiteUrl, smiUrl }; |
| 193 | + return { status: "SUCCESS", websiteUrl: url.href, smiUrl }; |
202 | 194 | } else { |
203 | | - return { status: "EXPIRED", websiteUrl, smiUrl }; // Image found but expired |
| 195 | + return { status: "EXPIRED", websiteUrl: url.href, smiUrl }; // Image found but expired |
204 | 196 | } |
205 | 197 | } else { |
206 | | - return { status: "NO_IMAGE", websiteUrl, smiUrl }; // Image was previously cached but doesn't exist |
| 198 | + return { status: "NO_IMAGE", websiteUrl: url.href, smiUrl }; // Image was previously cached but doesn't exist |
207 | 199 | } |
208 | 200 | } |
209 | 201 |
|
210 | | - return { status: "NOT_FOUND", websiteUrl, smiUrl: null }; // Website URL doesn't have a cached image |
| 202 | + return { status: "NOT_FOUND", websiteUrl: url.href, smiUrl: null }; // Website URL doesn't have a cached image |
211 | 203 | } |
212 | 204 |
|
213 | 205 | $: if (imageUrl) { |
|
0 commit comments