Mii uploads: use config for bucket name

This commit is contained in:
Billy 2025-01-18 17:52:58 +00:00
parent 04d206e3ed
commit 6d821d6af5
4 changed files with 12 additions and 4 deletions

View File

@ -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 <user@company.net>
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

View File

@ -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;

View File

@ -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() {

View File

@ -27,6 +27,7 @@ export interface Config {
from: string;
};
s3: {
bucket: string;
endpoint: string;
key: string;
secret: string;