-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { z } from "zod"; | ||
|
||
const imageFormatSchema = z.object({ | ||
name: z.string(), | ||
hash: z.string(), | ||
ext: z.string(), | ||
mime: z.string(), | ||
path: z.string().nullable(), | ||
width: z.number(), | ||
height: z.number(), | ||
size: z.number(), | ||
url: z.string(), | ||
}); | ||
|
||
export type ImageFormat = z.infer<typeof imageFormatSchema>; | ||
|
||
export const imageSchema = z.object({ | ||
data: z.object({ | ||
attributes: z.object({ | ||
name: z.string(), | ||
alternativeText: z.string().nullable(), | ||
caption: z.string().nullable(), | ||
width: z.number(), | ||
height: z.number(), | ||
formats: z.object({ | ||
large: imageFormatSchema.nullable(), | ||
medium: imageFormatSchema.nullable(), | ||
small: imageFormatSchema.nullable(), | ||
thumbnail: imageFormatSchema.nullable(), | ||
}), | ||
hash: z.string(), | ||
ext: z.string(), | ||
mime: z.string(), | ||
size: z.number(), | ||
url: z.string(), | ||
previewUrl: z.string().nullable(), | ||
provider: z.string(), | ||
provider_metadata: z.string().nullable(), | ||
createdAt: z.string(), | ||
updatedAt: z.string(), | ||
}), | ||
}), | ||
}); | ||
|
||
export type ImageType = z.infer<typeof imageSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
export const getLargestImage = (img: any) => { | ||
import { ImageType } from "@/schemas/Image"; | ||
|
||
export const getLargestImageUrl = (img: ImageType) => { | ||
try { | ||
const formats = img.data.attributes.formats; | ||
|
||
const largestFormat = | ||
formats.large || formats.medium || formats.small || formats.thumbnail; | ||
const largestFormat = formats.large ?? | ||
formats.medium ?? | ||
formats.small ?? | ||
formats.thumbnail ?? { url: "" }; | ||
|
||
return `${process.env.STRAPI_URL}${largestFormat.url}`; | ||
} catch { | ||
return ''; | ||
return process.env.STRAPI_URL; | ||
} | ||
}; |