From 4d762dc394da4f4e5f0babe8f5ece5e80b70678c Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 10 Mar 2024 14:38:38 -0600 Subject: [PATCH] parameterize the download-image server --- .env.sample | 24 ++++++++++++++++++++++++ server.js | 5 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..24f5976 --- /dev/null +++ b/.env.sample @@ -0,0 +1,24 @@ + +#AWS_ACCESS_KEY=??? +#AWS_BUCKET_NAME=image +#AWS_REGION=US +#AWS_SECRET_KEY=??? +AWS_ACCESS_KEY=??? +AWS_BUCKET_NAME=gifts-image-test +AWS_REGION=us-west-1 +AWS_SECRET_KEY=??? + +#ENDORSER_API_URL=http://localhost:3000 +#ENDORSER_API_URL=https://test-api.endorser.ch +#ENDORSER_API_URL=https://api.endorser.ch + +INFURA_PROJECT_ID=??? + +#DOWNLOAD_IMAGE_SERVER=test-image.timesafari.app + +# default is 3000 +#PORT=3000 + +# default is jdbc:sqlite:./sqlite-db.sqlite +# file name also referenced in flyway.conf and in code +#SQLITE_FILE=./image-db.sqlite diff --git a/server.js b/server.js index f2657d6..ebd3a30 100644 --- a/server.js +++ b/server.js @@ -20,6 +20,7 @@ const port = process.env.PORT || 3001; // file name also referenced in flyway.conf and potentially in .env files or in environment variables const dbFile = process.env.SQLITE_FILE || './image-db.sqlite'; const bucketName = process.env.AWS_BUCKET_NAME || 'gifts-image-test'; +const imageServer = process.env.DOWNLOAD_IMAGE_SERVER || 'test-image.timesafari.app'; const ethrDidResolver = getResolver; const resolver = @@ -36,7 +37,7 @@ const db = new sqlite3.Database(dbFile, (err) => { } }); -const endorserApiUrl = process.env.ENDORSER_API_URL || 'http://localhost:3000'; +const endorserApiUrl = process.env.ENDORSER_API_URL || 'https://test-api.endorser.ch'; // Configure AWS const s3Client = new S3Client({ @@ -173,7 +174,7 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => { // record the upload in the database const currentDate = new Date().toISOString(); const localFile = reqFile.path.startsWith(uploadDir + '/') ? reqFile.path.substring(uploadDir.length + 1) : reqFile.path; - const finalUrl = `https://${bucketName}.s3.amazonaws.com/${fileName}`; + const finalUrl = `https://${imageServer}/${fileName}`; await new Promise((resolve, reject) => { db.run( 'INSERT INTO image (time, did, local_file, size, final_file, url) VALUES (?, ?, ?, ?, ?, ?)',