From 242b492573ea919a980ba7984c62b006e07e4547 Mon Sep 17 00:00:00 2001 From: Drew Bollinger Date: Fri, 22 Dec 2023 14:58:44 -0800 Subject: [PATCH] more fake branches for uploaded files --- api/services/S3Helper.js | 4 +--- api/utils/cfAuthClient.js | 3 +-- scripts/localstack-setup.js | 25 ++++++++++++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/api/services/S3Helper.js b/api/services/S3Helper.js index 7ea14040f..3457b2a6d 100644 --- a/api/services/S3Helper.js +++ b/api/services/S3Helper.js @@ -49,6 +49,7 @@ class S3Client { results.push(...page[property]); } } + return results; } @@ -99,9 +100,6 @@ class S3Client { // Concatenate S3 pages until there are enough for OUR page size // eslint-disable-next-line no-restricted-syntax for await (const page of paginator) { - if (!page.Contents) { - break; - } objects.push(...page.Contents); if (objects.length >= totalMaxObjects) { break; diff --git a/api/utils/cfAuthClient.js b/api/utils/cfAuthClient.js index 3dd9417eb..67e2801a4 100644 --- a/api/utils/cfAuthClient.js +++ b/api/utils/cfAuthClient.js @@ -40,8 +40,7 @@ class CloudFoundryAuthClient { response_type: 'token', }).toString(), }) - .then(response => response.data.access_token) - .catch(err => console.error(err)); + .then(response => response.data.access_token); } tokenExpired() { diff --git a/scripts/localstack-setup.js b/scripts/localstack-setup.js index db3b3d549..9e2122fbb 100755 --- a/scripts/localstack-setup.js +++ b/scripts/localstack-setup.js @@ -4,7 +4,6 @@ const { Op } = require('sequelize'); const { Build, - BuildLog, BuildTask, Site, } = require('../api/models'); @@ -21,6 +20,16 @@ const s3 = new S3Client({ }, }); +const fakeIndex = ` + +site + + +Website + + +`; + const cmd = new CreateBucketCommand({ Bucket: config.s3BuildLogs.bucket }); s3.send(cmd); @@ -29,14 +38,24 @@ Site.findAll() sites.forEach(async (site) => { const siteCmd = new CreateBucketCommand({ Bucket: site.awsBucketName }); await s3.send(siteCmd); - const folders = ['preview', 'site', 'demo'] + const folders = ['site', 'demo']; folders.forEach((folder) => { const folderCmd = new PutObjectCommand({ + Body: fakeIndex, Bucket: site.awsBucketName, - Key: `${folder}/${site.owner}/${site.repository}`, + Key: `${folder}/${site.owner}/${site.repository}/index.html`, }); s3.send(folderCmd); }); + const fakePreviews = ['branch1', 'branch2', 'branch3']; + fakePreviews.forEach((branch) => { + const previewCmd = new PutObjectCommand({ + Body: fakeIndex, + Bucket: site.awsBucketName, + Key: `preview/${site.owner}/${site.repository}/${branch}/index.html`, + }); + s3.send(previewCmd); + }); }); }) .catch(err => console.error(err));