mirror of
https://github.com/PretendoNetwork/miiverse-api.git
synced 2026-07-12 22:41:18 -05:00
feat: update config to support new CDN and prep for move to AWS SDK v3
This commit is contained in:
parent
28ef808178
commit
0cd9b63041
|
|
@ -28,7 +28,9 @@ export const config: Config = {
|
|||
s3: {
|
||||
endpoint: process.env.PN_MIIVERSE_API_CONFIG_S3_ENDPOINT || '',
|
||||
key: process.env.PN_MIIVERSE_API_CONFIG_S3_ACCESS_KEY || '',
|
||||
secret: process.env.PN_MIIVERSE_API_CONFIG_S3_ACCESS_SECRET || ''
|
||||
secret: process.env.PN_MIIVERSE_API_CONFIG_S3_ACCESS_SECRET || '',
|
||||
bucket: process.env.PN_MIIVERSE_API_CONFIG_S3_BUCKET || '',
|
||||
region: process.env.PN_MIIVERSE_API_CONFIG_S3_REGION || ''
|
||||
},
|
||||
grpc: {
|
||||
friends: {
|
||||
|
|
@ -77,6 +79,16 @@ if (!config.s3.secret) {
|
|||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!config.s3.bucket) {
|
||||
LOG_ERROR('Failed to find s3 bucket. Set the PN_MIIVERSE_API_CONFIG_S3_BUCKET environment variable');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!config.s3.region) {
|
||||
LOG_ERROR('Failed to find s3 region. Set the PN_MIIVERSE_API_CONFIG_S3_REGION environment variable');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!config.grpc.friends.ip) {
|
||||
LOG_ERROR('Failed to find NEX Friends gRPC ip. Set the PN_MIIVERSE_API_CONFIG_GRPC_FRIENDS_IP environment variable');
|
||||
process.exit(0);
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ router.post('/', upload.none(), async function (request: express.Request, respon
|
|||
const paintingBuffer = await processPainting(painting);
|
||||
|
||||
if (paintingBuffer) {
|
||||
await uploadCDNAsset('pn-cdn', `paintings/${request.pid}/${post.id}.png`, paintingBuffer, 'public-read');
|
||||
await uploadCDNAsset(`paintings/${request.pid}/${post.id}.png`, paintingBuffer, 'public-read');
|
||||
} else {
|
||||
LOG_WARN(`PAINTING FOR POST ${post.id} FAILED TO PROCESS`);
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ router.post('/', upload.none(), async function (request: express.Request, respon
|
|||
if (screenshot) {
|
||||
const screenshotBuffer = Buffer.from(screenshot, 'base64');
|
||||
|
||||
await uploadCDNAsset('pn-cdn', `screenshots/${request.pid}/${post.id}.jpg`, screenshotBuffer, 'public-read');
|
||||
await uploadCDNAsset(`screenshots/${request.pid}/${post.id}.jpg`, screenshotBuffer, 'public-read');
|
||||
|
||||
post.screenshot = `/screenshots/${request.pid}/${post.id}.jpg`;
|
||||
post.screenshot_length = screenshot.length;
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ async function newPost(request: express.Request, response: express.Response): Pr
|
|||
const paintingBuffer = await processPainting(painting);
|
||||
|
||||
if (paintingBuffer) {
|
||||
await uploadCDNAsset('pn-cdn', `paintings/${request.pid}/${post.id}.png`, paintingBuffer, 'public-read');
|
||||
await uploadCDNAsset(`paintings/${request.pid}/${post.id}.png`, paintingBuffer, 'public-read');
|
||||
} else {
|
||||
LOG_WARN(`PAINTING FOR POST ${post.id} FAILED TO PROCESS`);
|
||||
}
|
||||
|
|
@ -404,7 +404,7 @@ async function newPost(request: express.Request, response: express.Response): Pr
|
|||
if (screenshot) {
|
||||
const screenshotBuffer = Buffer.from(screenshot, 'base64');
|
||||
|
||||
await uploadCDNAsset('pn-cdn', `screenshots/${request.pid}/${post.id}.jpg`, screenshotBuffer, 'public-read');
|
||||
await uploadCDNAsset(`screenshots/${request.pid}/${post.id}.jpg`, screenshotBuffer, 'public-read');
|
||||
|
||||
post.screenshot = `/screenshots/${request.pid}/${post.id}.jpg`;
|
||||
post.screenshot_length = screenshot.length;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ export interface Config {
|
|||
endpoint: string;
|
||||
key: string;
|
||||
secret: string;
|
||||
bucket: string;
|
||||
region: string;
|
||||
};
|
||||
grpc: {
|
||||
friends: {
|
||||
|
|
|
|||
|
|
@ -146,11 +146,11 @@ export function processPainting(painting: string): Buffer | null {
|
|||
}
|
||||
}
|
||||
|
||||
export async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: string): Promise<void> {
|
||||
export async function uploadCDNAsset(key: string, data: Buffer, acl: string): Promise<void> {
|
||||
const awsPutParams = {
|
||||
Body: data,
|
||||
Key: key,
|
||||
Bucket: bucket,
|
||||
Bucket: config.s3.bucket,
|
||||
ACL: acl
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user