Upgrade to AWS SDK v3

This commit is contained in:
William Oldham
2024-09-23 21:42:35 +01:00
parent 7a0c2e4231
commit fc6ff262da
3 changed files with 2777 additions and 251 deletions

3007
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -24,9 +24,9 @@
},
"homepage": "https://github.com/PretendoNetwork/account#readme",
"dependencies": {
"@aws-sdk/client-s3": "^3.657.0",
"@aws-sdk/client-ses": "^3.515.0",
"@pretendonetwork/grpc": "^1.0.5",
"aws-sdk": "^2.978.0",
"bcrypt": "^5.0.0",
"buffer-crc32": "^0.2.13",
"colors": "^1.4.0",

View File

@@ -1,7 +1,7 @@
import crypto from 'node:crypto';
import path from 'node:path';
import { IncomingHttpHeaders } from 'node:http';
import aws from 'aws-sdk';
import { ObjectCannedACL, S3 } from '@aws-sdk/client-s3';
import fs from 'fs-extra';
import express from 'express';
import mongoose from 'mongoose';
@@ -15,13 +15,16 @@ import { Token } from '@/types/common/token';
import { IPNID, IPNIDMethods } from '@/types/mongoose/pnid';
import { SafeQs } from '@/types/common/safe-qs';
let s3: aws.S3;
let s3: S3;
if (!disabledFeatures.s3) {
s3 = new aws.S3({
endpoint: new aws.Endpoint(config.s3.endpoint),
accessKeyId: config.s3.key,
secretAccessKey: config.s3.secret
s3 = new S3({
endpoint: config.s3.endpoint,
credentials: {
accessKeyId: config.s3.key,
secretAccessKey: config.s3.secret,
},
});
}
@@ -150,7 +153,7 @@ export function fullUrl(request: express.Request): string {
return `${protocol}://${host}${opath}`;
}
export async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: string): Promise<void> {
export async function uploadCDNAsset(bucket: string, key: string, data: Buffer, acl: ObjectCannedACL): Promise<void> {
if (disabledFeatures.s3) {
await writeLocalCDNFile(key, data);
} else {
@@ -159,7 +162,7 @@ export async function uploadCDNAsset(bucket: string, key: string, data: Buffer,
Key: key,
Bucket: bucket,
ACL: acl
}).promise();
});
}
}