Skip to content

Commit 5b97713

Browse files
authored
Merge pull request #87 from Perry2004/feat/load-pexels-url-from-env-var
feat: load pexels url from env var
2 parents 99d08d1 + 671fe03 commit 5b97713

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

scripts/src/lambda-handler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
CloudFrontClient,
99
CreateInvalidationCommand,
1010
} from "@aws-sdk/client-cloudfront";
11-
import { getImageLinksPlaywright } from "./main";
11+
import { getImageLinksPlaywright, getPexelsFeaturedUploadsUrl } from "./main";
1212

1313
const s3Client = new S3Client({ region: "us-west-2" });
1414
const 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

scripts/src/main.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff 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+
822
async function findLoadMoreButton(
923
page: Page,
1024
): Promise<ElementHandle<SVGElement | HTMLElement> | null> {
@@ -223,8 +237,7 @@ function saveLinksToJson(links: string[], filename: string): void {
223237
}
224238

225239
async 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+
};

0 commit comments

Comments
 (0)