Skip to content

Commit

Permalink
Merge pull request #143 from PretendoNetwork/bucket-config
Browse files Browse the repository at this point in the history
Mii uploads: use config for bucket name
  • Loading branch information
binaryoverload authored Jan 18, 2025
2 parents 04d206e + 6e724c2 commit d170450
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
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
Expand Down
6 changes: 6 additions & 0 deletions src/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/models/pnid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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({
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/types/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface Config {
from: string;
};
s3: {
bucket: string;
endpoint: string;
key: string;
secret: string;
Expand Down

0 comments on commit d170450

Please sign in to comment.