diff --git a/example.env b/example.env index 626100d..8e07339 100644 --- a/example.env +++ b/example.env @@ -10,6 +10,7 @@ PN_ACT_CONFIG_EMAIL_SES_REGION=region PN_ACT_CONFIG_EMAIL_SES_ACCESS_KEY=ACCESS_KEY PN_ACT_CONFIG_EMAIL_SES_SECRET_KEY=ACCESS_SECRET PN_ACT_CONFIG_EMAIL_FROM=Company Name +PN_ACT_CONFIG_S3_BUCKET=BUCKET_NAME PN_ACT_CONFIG_S3_ENDPOINT=nyc3.digitaloceanspaces.com PN_ACT_CONFIG_S3_ACCESS_KEY=ACCESS_KEY PN_ACT_CONFIG_S3_ACCESS_SECRET=ACCESS_SECRET diff --git a/src/config-manager.ts b/src/config-manager.ts index 7d98100..dc3080d 100644 --- a/src/config-manager.ts +++ b/src/config-manager.ts @@ -54,6 +54,7 @@ export const config: Config = { from: process.env.PN_ACT_CONFIG_EMAIL_FROM || '' }, s3: { + bucket: process.env.PN_ACT_CONFIG_S3_BUCKET || '', endpoint: process.env.PN_ACT_CONFIG_S3_ENDPOINT || '', key: process.env.PN_ACT_CONFIG_S3_ACCESS_KEY || '', secret: process.env.PN_ACT_CONFIG_S3_ACCESS_SECRET || '', @@ -182,6 +183,11 @@ if (!config.hcaptcha.secret) { disabledFeatures.captcha = true; } +if (!config.s3.bucket) { + LOG_WARN('Failed to find S3 bucket config. Disabling feature. To enable feature set the PN_ACT_CONFIG_S3_BUCKET environment variable'); + disabledFeatures.s3 = true; +} + if (!config.s3.endpoint) { LOG_WARN('Failed to find S3 endpoint config. Disabling feature. To enable feature set the PN_ACT_CONFIG_S3_ENDPOINT environment variable'); disabledFeatures.s3 = true; diff --git a/src/models/pnid.ts b/src/models/pnid.ts index 5e2cc34..a5509d0 100644 --- a/src/models/pnid.ts +++ b/src/models/pnid.ts @@ -198,8 +198,8 @@ PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promi const userMiiKey = `mii/${this.pid}`; - await uploadCDNAsset('pn-cdn', `${userMiiKey}/standard.tga`, tga, 'public-read'); - await uploadCDNAsset('pn-cdn', `${userMiiKey}/normal_face.png`, miiStudioNormalFaceImageData, 'public-read'); + await uploadCDNAsset(config.s3.bucket, `${userMiiKey}/standard.tga`, tga, 'public-read'); + await uploadCDNAsset(config.s3.bucket, `${userMiiKey}/normal_face.png`, miiStudioNormalFaceImageData, 'public-read'); const expressions = ['frustrated', 'smile_open_mouth', 'wink_left', 'sorrow', 'surprise_open_mouth']; for (const expression of expressions) { @@ -210,7 +210,7 @@ PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promi instanceCount: 1, }); const miiStudioExpressionImageData = await got(miiStudioExpressionUrl).buffer(); - await uploadCDNAsset('pn-cdn', `${userMiiKey}/${expression}.png`, miiStudioExpressionImageData, 'public-read'); + await uploadCDNAsset(config.s3.bucket, `${userMiiKey}/${expression}.png`, miiStudioExpressionImageData, 'public-read'); } const miiStudioBodyUrl = mii.studioUrl({ @@ -219,7 +219,7 @@ PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promi instanceCount: 1, }); const miiStudioBodyImageData = await got(miiStudioBodyUrl).buffer(); - await uploadCDNAsset('pn-cdn', `${userMiiKey}/body.png`, miiStudioBodyImageData, 'public-read'); + await uploadCDNAsset(config.s3.bucket, `${userMiiKey}/body.png`, miiStudioBodyImageData, 'public-read'); }); PNIDSchema.method('scrub', async function scrub() { diff --git a/src/types/common/config.ts b/src/types/common/config.ts index 3554c56..cc6390f 100644 --- a/src/types/common/config.ts +++ b/src/types/common/config.ts @@ -27,6 +27,7 @@ export interface Config { from: string; }; s3: { + bucket: string; endpoint: string; key: string; secret: string;