export async function writeChefData()

in lib/recipes-data/src/lib/s3.ts [235:277]


export async function writeChefData({
	chefData,
	Key,
	BucketName,
	FastlyApiKey,
	contentPrefix,
}: {
	chefData: ChefInfoFile;
	Key: string;
	BucketName: string;
	FastlyApiKey: string;
	contentPrefix: string;
}) {
	console.log('Marshalling data...');
	const formattedData = JSON.stringify(chefData);

	const prevEtag = await getExistingEtag(Key, BucketName);
	console.log(`Old etag is ${prevEtag ?? '(undefined)'}`);

	console.log(`Done. Writing to s3://${BucketName}/${Key}...`);
	const req = new PutObjectCommand({
		Bucket: BucketName,
		Key,
		Body: formattedData,
		ContentType: 'application/json',
		CacheControl: DefaultCacheControlParams,
	});

	await s3Client.send(req);
	console.log('Done. Purging CDN...');
	const newEtag = await getExistingEtag(Key, BucketName);
	console.log(`New etag is ${newEtag ?? '(undefined)'}`);
	if (!!prevEtag && newEtag != prevEtag) {
		await sendFastlyPurgeRequest({
			contentPath: Key,
			apiKey: FastlyApiKey,
			contentPrefix,
		});
		console.log('Done.');
	} else {
		console.log('No change detected to contributor data, not flushing cache');
	}
}