This commit is contained in:
jack
2026-08-29 20:49:27 +01:00
parent 4eab14d4d6
commit 04d3409297
2 changed files with 46 additions and 16 deletions
+26 -5
View File
@@ -9,8 +9,14 @@ const PORT = process.env.PORT || 3000;
// Where the model files actually live. Set S3_BUCKET to index a bucket;
// otherwise the local models/ folder is used, which is what development does.
const S3_BUCKET = process.env.S3_BUCKET || '';
const S3_PREFIX = normalisePrefix(process.env.S3_PREFIX || 'skins/');
// MODEL_S3_* names match the other projects; the plain names are accepted too.
const S3_BUCKET = process.env.MODEL_S3_BUCKET || process.env.S3_BUCKET || '';
const S3_PREFIX = normalisePrefix(
process.env.MODEL_S3_KEY_PREFIX || process.env.S3_PREFIX || 'skins/'
);
const S3_REGION = process.env.MODEL_S3_REGION || process.env.AWS_REGION;
const S3_ACCESS_KEY = process.env.MODEL_S3_ACCESS_KEY_ID || '';
const S3_SECRET_KEY = process.env.MODEL_S3_SECRET_ACCESS_KEY || '';
const MODEL_ROOT = process.env.MODEL_ROOT || path.join(__dirname, 'models');
// Where the browser fetches model files from. The default keeps them on this
@@ -46,10 +52,25 @@ function buildIndex(keys, prefix) {
return out;
}
async function listBucketKeys() {
let s3Client = null;
function getS3Client() {
if (s3Client) return s3Client;
// Required lazily so local development needs no AWS dependency installed.
const { S3Client, ListObjectsV2Command } = require('@aws-sdk/client-s3');
const client = new S3Client({ region: process.env.AWS_REGION });
const { S3Client } = require('@aws-sdk/client-s3');
// Explicit credentials only when given; otherwise fall back to the default
// chain, which picks up an EC2 instance role or ~/.aws/credentials.
const credentials =
S3_ACCESS_KEY && S3_SECRET_KEY
? { accessKeyId: S3_ACCESS_KEY, secretAccessKey: S3_SECRET_KEY }
: undefined;
s3Client = new S3Client({ region: S3_REGION, credentials });
return s3Client;
}
async function listBucketKeys() {
const { ListObjectsV2Command } = require('@aws-sdk/client-s3');
const client = getS3Client();
const keys = [];
let token;