File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 CloudFrontClient ,
99 CreateInvalidationCommand ,
1010} from "@aws-sdk/client-cloudfront" ;
11- import { getImageLinksPlaywright } from "./main" ;
11+ import { getImageLinksPlaywright , getPexelsFeaturedUploadsUrl } from "./main" ;
1212
1313const s3Client = new S3Client ( { region : "us-west-2" } ) ;
1414const cloudfrontClient = new CloudFrontClient ( { region : "us-west-2" } ) ;
@@ -24,8 +24,7 @@ export async function handler(
2424) : Promise < APIGatewayProxyResult > {
2525 console . log ( "Lambda handler started" ) ;
2626 try {
27- const pexelsUrl =
28- "https://www.pexels.com/@perry-z-1662054943/featured-uploads/" ;
27+ const pexelsUrl = getPexelsFeaturedUploadsUrl ( ) ;
2928 console . log ( `Fetching images from: ${ pexelsUrl } ` ) ;
3029 const imageLinks = await getImageLinksPlaywright ( pexelsUrl ) ;
3130
Original file line number Diff line number Diff line change @@ -5,6 +5,20 @@ interface ImageData {
55 images : string [ ] ;
66}
77
8+ const PEXELS_FEATURED_UPLOADS_URL_ENV = "PEXELS_FEATURED_UPLOADS_URL" ;
9+
10+ function getPexelsFeaturedUploadsUrl ( ) : string {
11+ const pexelsUrl = process . env [ PEXELS_FEATURED_UPLOADS_URL_ENV ] ?. trim ( ) ;
12+
13+ if ( ! pexelsUrl ) {
14+ throw new Error (
15+ `${ PEXELS_FEATURED_UPLOADS_URL_ENV } environment variable is required` ,
16+ ) ;
17+ }
18+
19+ return pexelsUrl ;
20+ }
21+
822async function findLoadMoreButton (
923 page : Page ,
1024) : Promise < ElementHandle < SVGElement | HTMLElement > | null > {
@@ -223,8 +237,7 @@ function saveLinksToJson(links: string[], filename: string): void {
223237}
224238
225239async function main ( ) : Promise < void > {
226- const pexelsUrl =
227- "https://www.pexels.com/@perry-z-1662054943/featured-uploads/" ;
240+ const pexelsUrl = getPexelsFeaturedUploadsUrl ( ) ;
228241 const links = await getImageLinksPlaywright ( pexelsUrl ) ;
229242
230243 if ( links && links . length > 0 ) {
@@ -245,4 +258,9 @@ if (require.main === module) {
245258 main ( ) . catch ( console . error ) ;
246259}
247260
248- export { getImageLinksPlaywright , saveLinksToJson , findLoadMoreButton } ;
261+ export {
262+ getImageLinksPlaywright ,
263+ getPexelsFeaturedUploadsUrl ,
264+ saveLinksToJson ,
265+ findLoadMoreButton ,
266+ } ;
You can’t perform that action at this time.
0 commit comments