-
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.
Merge pull request #204 from RandomStudio/video-focus-mode
TARGET MR: Add Video focus mode
- Loading branch information
Showing
26 changed files
with
647 additions
and
486 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
5 changes: 1 addition & 4 deletions
5
...ddToNewsletterList/addToNewsletterList.js → netlify/functions/addToNewsletterList.ts
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,32 @@ | ||
import type { HandlerEvent } from '@netlify/functions'; | ||
import { formatVideoData } from '../../src/utils/videoUtils'; | ||
import { getVideosList } from './getVideosList'; | ||
|
||
const handler = async (event: HandlerEvent) => { | ||
const items = await getVideosList(); | ||
|
||
const hasSpecifiedId = event.path.split('/').length > 4; | ||
|
||
if (!hasSpecifiedId) { | ||
return { | ||
statusCode: 404, | ||
}; | ||
} | ||
|
||
const id = event.path.split('/').at(-1); | ||
|
||
const details = items.find(item => item.guid === id); | ||
|
||
if (!details) { | ||
return { | ||
statusCode: 400, | ||
}; | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(await formatVideoData(details)), | ||
}; | ||
}; | ||
|
||
export { handler }; |
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,46 @@ | ||
import sharp from 'sharp'; | ||
import type { HandlerEvent } from '@netlify/functions'; | ||
|
||
const getImage = async url => { | ||
const response = await fetch(url); | ||
|
||
return Buffer.from(await response.arrayBuffer()); | ||
}; | ||
|
||
export const createBlurredImage = async (thumbnailUrl: string) => { | ||
const image = await getImage(thumbnailUrl); | ||
|
||
const buffer = await sharp(image) | ||
.raw() | ||
.ensureAlpha() | ||
.resize(12, 12, { fit: 'inside' }) | ||
.toFormat(sharp.format.png) | ||
.toBuffer(); | ||
|
||
return buffer.toString('base64'); | ||
}; | ||
|
||
export const handler = async (event: HandlerEvent) => { | ||
if (!event.queryStringParameters) { | ||
return { | ||
statusCode: 404, | ||
}; | ||
} | ||
|
||
const { thumbnailUrl } = event.queryStringParameters; | ||
|
||
if (!thumbnailUrl) { | ||
return { | ||
statusCode: 400, | ||
}; | ||
} | ||
|
||
const imageString = await createBlurredImage(thumbnailUrl); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
imageString, | ||
}), | ||
}; | ||
}; |
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,37 @@ | ||
export const getVideosList = async () => { | ||
try { | ||
const response = await fetch( | ||
`https://video.bunnycdn.com/library/${process.env.BUNNY_LIBRARY_ID}/videos?itemsPerPage=1000`, | ||
{ | ||
headers: { | ||
accept: 'application/json', | ||
'content-type': 'application/*+json', | ||
AccessKey: process.env.BUNNY_TOKEN, | ||
}, | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error('Unable to retrieve list of videos from Bunny'); | ||
} | ||
|
||
const { items } = await response.json(); | ||
|
||
return items; | ||
} catch (error) { | ||
console.error(error); | ||
|
||
return []; | ||
} | ||
}; | ||
|
||
const handler = async () => { | ||
const items = await getVideosList(); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(items), | ||
}; | ||
}; | ||
|
||
export { handler }; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.