From 2f04342a6da1e3ac5c5637a8a3982e9cdf2cb193 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Mon, 11 Mar 2024 21:02:39 -0600 Subject: [PATCH] add settings for American Cloud storage --- .env.sample | 9 ++++++++- README.md | 13 ++++++++----- package.json | 2 +- server.js | 7 +++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.env.sample b/.env.sample index 24f5976..cac2a4c 100644 --- a/.env.sample +++ b/.env.sample @@ -1,19 +1,26 @@ #AWS_ACCESS_KEY=??? -#AWS_BUCKET_NAME=image +#AWS_BUCKET_NAME=giftsimagetest +#AWS_ENDPOINT_SERVER=a2-west.americancloud.com #AWS_REGION=US #AWS_SECRET_KEY=??? +#S3_SET_ACL=true AWS_ACCESS_KEY=??? AWS_BUCKET_NAME=gifts-image-test +AWS_ENDPOINT_SERVER=gifts-image-test.s3.amazonaws.com AWS_REGION=us-west-1 AWS_SECRET_KEY=??? +#S3_SET_ACL=false +# needed to check limits #ENDORSER_API_URL=http://localhost:3000 #ENDORSER_API_URL=https://test-api.endorser.ch #ENDORSER_API_URL=https://api.endorser.ch INFURA_PROJECT_ID=??? +# host where the final image can be accessed by the public +# default is https://test-image.timesafari.app #DOWNLOAD_IMAGE_SERVER=test-image.timesafari.app # default is 3000 diff --git a/README.md b/README.md index c871849..12ac4fc 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,7 @@ # Image Server Remaining: -- try American Cloud - dockerize -- images.timesafari.app - -- pretty-up the client, show thumbnail ## setup @@ -47,4 +43,11 @@ JWT=`node -e "$CODE"`; curl -X DELETE -H "Authorization: Bearer $JWT" http://loc * Do the necessary steps from "setup" above. -* In AWS, set up bucket and erase any test data. +* In object storage, set up bucket and erase any test data. + +* In DNS, set a permanent web forward to the correct storage location. + + +## deploy to prod subsequent times + +* Add CHANGELOG.md entry. diff --git a/package.json b/package.json index e5f8c6b..78eb295 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "image-trade", + "name": "Images for Trade", "version": "0.0.1", "description": "", "license": "UNLICENSED", diff --git a/server.js b/server.js index 679514e..e623388 100644 --- a/server.js +++ b/server.js @@ -41,7 +41,9 @@ const endorserApiUrl = process.env.ENDORSER_API_URL || 'https://test-api.endorse // Configure AWS const s3Client = new S3Client({ + endpoint: 'https://' + process.env.AWS_ENDPOINT_SERVER, region: process.env.AWS_REGION, + forcePathStyle: true, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY, secretAccessKey: process.env.AWS_SECRET_KEY @@ -209,6 +211,9 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => { ContentType: reqFile.mimetype, // File content type Key: fileName, // File name to use in S3 }; + if (process.env.S3_SET_ACL === 'true') { + params.ACL = 'public-read'; + } const command = new PutObjectCommand(params); const response = await s3Client.send(command); if (response.$metadata.httpStatusCode !== 200) { @@ -224,6 +229,8 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => { console.error("Error deleting temp file", reqFile.path, "with error (but continuing):", err); } }); + // AWS URL: https://gifts-image-test.s3.amazonaws.com/gifts-image-test/FILE + // American Cloud URL: https://a2-west.americancloud.com/TENANT:giftsimagetest/FILE return res.status(200).send(JSON.stringify({success: true, url: finalUrl})); } } catch (uploadError) {