personal-website/lib/notion/utils/extractUrlFromFile.ts
Filipe Medeiros 9a9638237f
feat: initial commit
Signed-off-by: Filipe Medeiros <hello@filipesm.eu>
2023-12-03 12:25:52 +01:00

23 lines
472 B
TypeScript

const extractUrlFromFile = (
image:
| {
type?: 'external'
external: {
url: string
}
}
| {
type?: 'file'
file: {
url: string
expiry_time: string
}
},
) => {
if (image.type === 'external') return image.external.url
else if (image.type === 'file') return image.file.url
else throw new Error('Notion API returned unexpected result')
}
export default extractUrlFromFile