Skip to content

Commit

Permalink
fix(thumbnails): use correct thumbnail url
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandebalthasar committed May 21, 2024
1 parent c666389 commit aa74bbd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/api/StrapiApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class StrapiApi implements IApi {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private strapiMediaToThumbnail(response: any): Thumbnail {
const isURL = (url: string) => {
const urlPattern = /^https?:\/\/.+$/i;

Check failure on line 45 in src/api/StrapiApi.ts

View workflow job for this annotation

GitHub Actions / lint (16.x)

Delete `;`
return urlPattern.test(url)
}

if (response.attributes?.Thumbnails?.data != null) {
const thumbnailObj = response.attributes?.Thumbnails?.data[0]
const { createdAt, updatedAt } = thumbnailObj.attributes
Expand All @@ -49,7 +54,9 @@ export class StrapiApi implements IApi {
const thumbnailFormated = {
id: `${thumbnailObj.id}`,
ext: thumbnail.ext,
src: `${this.baseUrl}${thumbnail.url}`,
// The src can be either an url or a path
// ie. src: 'https://example.com/image.jpg' or src: '/image.jpg'
src: isURL(thumbnail.url) ? thumbnail.url : `${this.baseUrl}${thumbnail.url}`,

Check failure on line 59 in src/api/StrapiApi.ts

View workflow job for this annotation

GitHub Actions / lint (16.x)

Replace `·?·thumbnail.url` with `⏎····················?·thumbnail.url⏎···················`
createdAt,
updatedAt,
}
Expand Down

0 comments on commit aa74bbd

Please sign in to comment.