Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function fetchPayload(context: IPlayContext, boxId: string): Promise
{
const payloadUrl = `${context.payloadBaseUrl}/${boxId}_payload.json`;
const payloadContent = await fetch.json(payloadUrl, "GET") as IPlayPayload;
const payloadFileName = context.files["payload.json"] = context.boxDir + "/payload.json";
const payloadFilePath = path.resolve(context.job.jobDir, payloadFileName);
// fetch and write thumbnail image
const thumbImage = await fetch.buffer(payloadContent.message.pubThumb, "GET");
const thumbFileName = context.files["image-thumb.jpg"] = "image-thumb.jpg";
const thumbFilePath = path.resolve(context.job.jobDir, thumbFileName);
// fetch and write preview image
const previewImage = await fetch.buffer(payloadContent.message.pubPreview, "GET");
const previewFileName = context.files["image-preview.jpg"] = "image-preview.jpg";
const previewFilePath = path.resolve(context.job.jobDir, previewFileName);
return Promise.all([
fs.writeFile(payloadFilePath, JSON.stringify(payloadContent, null, 2)),
fs.writeFile(thumbFilePath, Buffer.from(thumbImage)),
fs.writeFile(previewFilePath, Buffer.from(previewImage))