Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions scripts/src/lambda-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CloudFrontClient,
CreateInvalidationCommand,
} from "@aws-sdk/client-cloudfront";
import { getImageLinksPlaywright } from "./main";
import { getImageLinksPlaywright, getPexelsFeaturedUploadsUrl } from "./main";

const s3Client = new S3Client({ region: "us-west-2" });
const cloudfrontClient = new CloudFrontClient({ region: "us-west-2" });
Expand All @@ -24,8 +24,7 @@ export async function handler(
): Promise<APIGatewayProxyResult> {
console.log("Lambda handler started");
try {
const pexelsUrl =
"https://www.pexels.com/@perry-z-1662054943/featured-uploads/";
const pexelsUrl = getPexelsFeaturedUploadsUrl();
console.log(`Fetching images from: ${pexelsUrl}`);
const imageLinks = await getImageLinksPlaywright(pexelsUrl);
Comment on lines 26 to 29

Expand Down
24 changes: 21 additions & 3 deletions scripts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ interface ImageData {
images: string[];
}

const PEXELS_FEATURED_UPLOADS_URL_ENV = "PEXELS_FEATURED_UPLOADS_URL";

function getPexelsFeaturedUploadsUrl(): string {
const pexelsUrl = process.env[PEXELS_FEATURED_UPLOADS_URL_ENV]?.trim();

if (!pexelsUrl) {
throw new Error(
`${PEXELS_FEATURED_UPLOADS_URL_ENV} environment variable is required`,
);
}

return pexelsUrl;
}
Comment on lines +10 to +20

async function findLoadMoreButton(
page: Page,
): Promise<ElementHandle<SVGElement | HTMLElement> | null> {
Expand Down Expand Up @@ -223,8 +237,7 @@ function saveLinksToJson(links: string[], filename: string): void {
}

async function main(): Promise<void> {
const pexelsUrl =
"https://www.pexels.com/@perry-z-1662054943/featured-uploads/";
const pexelsUrl = getPexelsFeaturedUploadsUrl();
const links = await getImageLinksPlaywright(pexelsUrl);

if (links && links.length > 0) {
Expand All @@ -245,4 +258,9 @@ if (require.main === module) {
main().catch(console.error);
}

export { getImageLinksPlaywright, saveLinksToJson, findLoadMoreButton };
export {
getImageLinksPlaywright,
getPexelsFeaturedUploadsUrl,
saveLinksToJson,
findLoadMoreButton,
};