mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-03-26 17:52:28 +01:00
upgrad aws sdk to v3
This commit is contained in:
parent
71238070cd
commit
6dc05b33c1
1618
app/package-lock.json
generated
1618
app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "opensaas",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.523.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.523.0",
|
||||
"@faker-js/faker": "8.3.1",
|
||||
"@google-analytics/data": "4.1.0",
|
||||
"@headlessui/react": "1.7.13",
|
||||
"@tailwindcss/forms": "^0.5.3",
|
||||
"@tailwindcss/typography": "^0.5.7",
|
||||
"apexcharts": "^3.41.0",
|
||||
"aws-sdk": "^2.1551.0",
|
||||
"headlessui": "^0.0.0",
|
||||
"node-fetch": "3.3.0",
|
||||
"openai": "^4.24.1",
|
||||
|
@ -309,7 +309,7 @@ export const createFile: CreateFile<fileArgs, File> = async ({ fileType, name },
|
||||
|
||||
const userInfo = context.user.id.toString();
|
||||
|
||||
const { uploadUrl, key } = getUploadFileSignedURLFromS3({ fileType, userInfo });
|
||||
const { uploadUrl, key } = await getUploadFileSignedURLFromS3({ fileType, userInfo });
|
||||
|
||||
return await context.entities.File.create({
|
||||
data: {
|
||||
|
@ -1,12 +1,14 @@
|
||||
import S3 from 'aws-sdk/clients/s3.js';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { S3Client } from '@aws-sdk/client-s3';
|
||||
import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
|
||||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
||||
|
||||
const s3Client = new S3({
|
||||
apiVersion: '2006-03-01',
|
||||
accessKeyId: process.env.AWS_S3_IAM_ACCESS_KEY,
|
||||
secretAccessKey: process.env.AWS_S3_IAM_SECRET_KEY,
|
||||
const s3Client = new S3Client({
|
||||
region: process.env.AWS_S3_REGION,
|
||||
signatureVersion: 'v4',
|
||||
credentials: {
|
||||
accessKeyId: process.env.AWS_S3_IAM_ACCESS_KEY!,
|
||||
secretAccessKey: process.env.AWS_S3_IAM_SECRET_KEY!,
|
||||
},
|
||||
});
|
||||
|
||||
type S3Upload = {
|
||||
@ -14,26 +16,24 @@ type S3Upload = {
|
||||
userInfo: string;
|
||||
}
|
||||
|
||||
export const getUploadFileSignedURLFromS3 = ({fileType, userInfo}: S3Upload) => {
|
||||
|
||||
export const getUploadFileSignedURLFromS3 = async ({fileType, userInfo}: S3Upload) => {
|
||||
const ex = fileType.split('/')[1];
|
||||
|
||||
const Key = `${userInfo}/${randomUUID()}.${ex}`;
|
||||
const s3Params = {
|
||||
Bucket: process.env.AWS_S3_FILES_BUCKET,
|
||||
Key,
|
||||
Expires: 30,
|
||||
ContentType: `${fileType}`,
|
||||
};
|
||||
const uploadUrl = s3Client.getSignedUrl("putObject", s3Params);
|
||||
const command = new PutObjectCommand(s3Params);
|
||||
const uploadUrl = await getSignedUrl(s3Client, command, { expiresIn: 3600,});
|
||||
return { uploadUrl, key: Key };
|
||||
}
|
||||
|
||||
export const getDownloadFileSignedURLFromS3 = ({ key }: { key: string }) => {
|
||||
export const getDownloadFileSignedURLFromS3 = async ({ key }: { key: string }) => {
|
||||
const s3Params = {
|
||||
Bucket: process.env.AWS_S3_FILES_BUCKET,
|
||||
Key: key,
|
||||
Expires: 30,
|
||||
};
|
||||
return s3Client.getSignedUrl("getObject", s3Params);
|
||||
const command = new GetObjectCommand(s3Params);
|
||||
return await getSignedUrl(s3Client, command, { expiresIn: 3600 });
|
||||
}
|
@ -68,7 +68,7 @@ export const getDownloadFileSignedURL: GetDownloadFileSignedURL<{ key: string },
|
||||
{ key },
|
||||
_context
|
||||
) => {
|
||||
return getDownloadFileSignedURLFromS3({ key });
|
||||
return await getDownloadFileSignedURLFromS3({ key });
|
||||
};
|
||||
|
||||
export const getDailyStats: GetDailyStats<void, DailyStatsValues> = async (_args, context) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user