From a3aa394b37f3b3dcea9beeffd4a9f1adf73d79e0 Mon Sep 17 00:00:00 2001 From: Jemma Poffinbarger Date: Tue, 14 Jan 2025 21:52:15 -0600 Subject: [PATCH] feat: update config to add bucket --- config.example.json | 3 ++- src/services/juxt-web/routes/admin/admin.js | 20 +++++++++---------- .../juxt-web/routes/console/messages.js | 4 ++-- src/services/juxt-web/routes/console/posts.js | 4 ++-- src/util.js | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/config.example.json b/config.example.json index 92fb96c..d751073 100644 --- a/config.example.json +++ b/config.example.json @@ -23,7 +23,8 @@ "secret": "" }, "endpoint": "https://nyc3.digitaloceanspaces.com", - "region": "us-east-1" + "region": "us-east-1", + "bucket": "bucket" }, "grpc": { "friends": { diff --git a/src/services/juxt-web/routes/admin/admin.js b/src/services/juxt-web/routes/admin/admin.js index 52a0128..d929ee9 100644 --- a/src/services/juxt-web/routes/admin/admin.js +++ b/src/services/juxt-web/routes/admin/admin.js @@ -217,9 +217,9 @@ router.post('/communities/new', upload.fields([{ name: 'browserIcon', maxCount: const icon64 = await util.resizeImage(req.files.browserIcon[0].buffer.toString('base64'), 64, 64); const icon32 = await util.resizeImage(req.files.browserIcon[0].buffer.toString('base64'), 32, 32); - if (!await util.uploadCDNAsset('pn-cdn', `icons/${communityID}/128.png`, icon128, 'public-read') || - !await util.uploadCDNAsset('pn-cdn', `icons/${communityID}/64.png`, icon64, 'public-read') || - !await util.uploadCDNAsset('pn-cdn', `icons/${communityID}/32.png`, icon32, 'public-read')) { + if (!await util.uploadCDNAsset(`icons/${communityID}/128.png`, icon128, 'public-read') || + !await util.uploadCDNAsset(`icons/${communityID}/64.png`, icon64, 'public-read') || + !await util.uploadCDNAsset(`icons/${communityID}/32.png`, icon32, 'public-read')) { return res.sendStatus(422); } @@ -230,8 +230,8 @@ router.post('/communities/new', upload.fields([{ name: 'browserIcon', maxCount: // Wii U Header const WiiUHeader = await util.resizeImage(req.files.WiiUbrowserHeader[0].buffer.toString('base64'), 1280, 180); - if (!await util.uploadCDNAsset('pn-cdn', `headers/${communityID}/3DS.png`, CTRHeader, 'public-read') || - !await util.uploadCDNAsset('pn-cdn', `headers/${communityID}/WiiU.png`, WiiUHeader, 'public-read')) { + if (!await util.uploadCDNAsset(`headers/${communityID}/3DS.png`, CTRHeader, 'public-read') || + !await util.uploadCDNAsset(`headers/${communityID}/WiiU.png`, WiiUHeader, 'public-read')) { return res.sendStatus(422); } @@ -302,9 +302,9 @@ router.post('/communities/:id', upload.fields([{ name: 'browserIcon', maxCount: const icon64 = await util.resizeImage(req.files.browserIcon[0].buffer.toString('base64'), 64, 64); const icon32 = await util.resizeImage(req.files.browserIcon[0].buffer.toString('base64'), 32, 32); - if (!await util.uploadCDNAsset('pn-cdn', `icons/${communityID}/128.png`, icon128, 'public-read') || - !await util.uploadCDNAsset('pn-cdn', `icons/${communityID}/64.png`, icon64, 'public-read') || - !await util.uploadCDNAsset('pn-cdn', `icons/${communityID}/32.png`, icon32, 'public-read')) { + if (!await util.uploadCDNAsset(`icons/${communityID}/128.png`, icon128, 'public-read') || + !await util.uploadCDNAsset(`icons/${communityID}/64.png`, icon64, 'public-read') || + !await util.uploadCDNAsset(`icons/${communityID}/32.png`, icon32, 'public-read')) { return res.sendStatus(422); } @@ -314,7 +314,7 @@ router.post('/communities/:id', upload.fields([{ name: 'browserIcon', maxCount: // 3DS Header if (req.files.CTRbrowserHeader) { const CTRHeader = await util.resizeImage(req.files.CTRbrowserHeader[0].buffer.toString('base64'), 400, 220); - if (!await util.uploadCDNAsset('pn-cdn', `headers/${communityID}/3DS.png`, CTRHeader, 'public-read')) { + if (!await util.uploadCDNAsset(`headers/${communityID}/3DS.png`, CTRHeader, 'public-read')) { return res.sendStatus(422); } } @@ -322,7 +322,7 @@ router.post('/communities/:id', upload.fields([{ name: 'browserIcon', maxCount: // Wii U Header if (req.files.WiiUbrowserHeader) { const WiiUHeader = await util.resizeImage(req.files.WiiUbrowserHeader[0].buffer.toString('base64'), 1280, 180); - if (!await util.uploadCDNAsset('pn-cdn', `headers/${communityID}/WiiU.png`, WiiUHeader, 'public-read')) { + if (!await util.uploadCDNAsset(`headers/${communityID}/WiiU.png`, WiiUHeader, 'public-read')) { return res.sendStatus(422); } } diff --git a/src/services/juxt-web/routes/console/messages.js b/src/services/juxt-web/routes/console/messages.js index 3cf4dbf..27651d8 100644 --- a/src/services/juxt-web/routes/console/messages.js +++ b/src/services/juxt-web/routes/console/messages.js @@ -69,7 +69,7 @@ router.post('/new', async function (req, res) { if (req.body._post_type === 'painting' && req.body.painting) { painting = req.body.painting.replace(/\0/g, '').trim(); paintingURI = await util.processPainting(painting, true); - if (!await util.uploadCDNAsset('pn-cdn', `paintings/${req.pid}/${postID}.png`, paintingURI, 'public-read')) { + if (!await util.uploadCDNAsset(`paintings/${req.pid}/${postID}.png`, paintingURI, 'public-read')) { res.status(422); return res.render(req.directory + '/error.ejs', { code: 422, @@ -82,7 +82,7 @@ router.post('/new', async function (req, res) { } if (req.body.screenshot) { screenshot = req.body.screenshot.replace(/\0/g, '').trim(); - if (await util.uploadCDNAsset('pn-cdn', `screenshots/${req.pid}/${postID}.jpg`, Buffer.from(screenshot, 'base64'), 'public-read')) { + if (await util.uploadCDNAsset(`screenshots/${req.pid}/${postID}.jpg`, Buffer.from(screenshot, 'base64'), 'public-read')) { res.status(422); return res.render(req.directory + '/error.ejs', { code: 422, diff --git a/src/services/juxt-web/routes/console/posts.js b/src/services/juxt-web/routes/console/posts.js index b9cea79..1d3042b 100644 --- a/src/services/juxt-web/routes/console/posts.js +++ b/src/services/juxt-web/routes/console/posts.js @@ -229,7 +229,7 @@ async function newPost(req, res) { painting = req.body.painting; } paintingURI = await util.processPainting(painting, true); - if (!await util.uploadCDNAsset('pn-cdn', `paintings/${req.pid}/${postID}.png`, paintingURI, 'public-read')) { + if (!await util.uploadCDNAsset(`paintings/${req.pid}/${postID}.png`, paintingURI, 'public-read')) { res.status(422); return res.render(req.directory + '/error.ejs', { code: 422, @@ -242,7 +242,7 @@ async function newPost(req, res) { } if (req.body.screenshot) { screenshot = req.body.screenshot.replace(/\0/g, '').trim(); - if (!await util.uploadCDNAsset('pn-cdn', `screenshots/${req.pid}/${postID}.jpg`, Buffer.from(screenshot, 'base64'), 'public-read')) { + if (!await util.uploadCDNAsset(`screenshots/${req.pid}/${postID}.jpg`, Buffer.from(screenshot, 'base64'), 'public-read')) { res.status(422); return res.render(req.directory + '/error.ejs', { code: 422, diff --git a/src/util.js b/src/util.js index 2ff08cd..5f89c5b 100644 --- a/src/util.js +++ b/src/util.js @@ -316,11 +316,11 @@ function processLanguage(paramPackData) { return translations.EN; } } -async function uploadCDNAsset(bucket, key, data, acl) { +async function uploadCDNAsset(key, data, acl) { const awsPutParams = new PutObjectCommand({ Body: data, Key: key, - Bucket: bucket, + Bucket: config.aws.bucket, ACL: acl }); try {