mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-02 22:26:57 -05:00
Update to the new AWS API
This commit is contained in:
parent
7c064b1a75
commit
b2cf401b10
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
import { PassThrough } from "stream";
|
||||
|
||||
import AWS from "aws-sdk";
|
||||
import type AWS from "aws-sdk";
|
||||
import { Upload } from "@aws-sdk/lib-storage";
|
||||
import {
|
||||
type CompleteMultipartUploadCommandOutput,
|
||||
S3,
|
||||
} from "@aws-sdk/client-s3";
|
||||
import type { UploadHandler } from "@remix-run/node";
|
||||
import { writeAsyncIterableToWritable } from "@remix-run/node";
|
||||
import { nanoid } from "nanoid";
|
||||
|
|
@ -47,9 +52,9 @@ const uploadStream = ({ Key }: Pick<AWS.S3.Types.PutObjectRequest, "Key">) => {
|
|||
STORAGE_BUCKET,
|
||||
} = envVars();
|
||||
|
||||
const s3 = new AWS.S3({
|
||||
const s3 = new S3({
|
||||
endpoint: STORAGE_END_POINT,
|
||||
s3ForcePathStyle: false,
|
||||
forcePathStyle: false,
|
||||
credentials: {
|
||||
accessKeyId: STORAGE_ACCESS_KEY,
|
||||
secretAccessKey: STORAGE_SECRET,
|
||||
|
|
@ -59,9 +64,10 @@ const uploadStream = ({ Key }: Pick<AWS.S3.Types.PutObjectRequest, "Key">) => {
|
|||
const pass = new PassThrough();
|
||||
return {
|
||||
writeStream: pass,
|
||||
promise: s3
|
||||
.upload({ Bucket: STORAGE_BUCKET, Key, Body: pass, ACL: "public-read" })
|
||||
.promise(),
|
||||
promise: new Upload({
|
||||
client: s3,
|
||||
params: { Bucket: STORAGE_BUCKET, Key, Body: pass, ACL: "public-read" },
|
||||
}).done(),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -71,7 +77,7 @@ export async function uploadStreamToS3(data: any, filename: string) {
|
|||
});
|
||||
await writeAsyncIterableToWritable(data, stream.writeStream);
|
||||
const file = await stream.promise;
|
||||
return file.Location;
|
||||
return (file as CompleteMultipartUploadCommandOutput).Location;
|
||||
}
|
||||
|
||||
// predeciding file name is useful when you are uploading more than one asset
|
||||
|
|
|
|||
2636
package-lock.json
generated
2636
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
|
@ -41,6 +41,8 @@
|
|||
"cf:noe2e": "npm run test:unit && npm run check-translation-jsons && npm run lint:css -- --fix && npm run lint:ts -- --fix && npm run prettier:write && npm run typecheck"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.428.0",
|
||||
"@aws-sdk/lib-storage": "^3.428.0",
|
||||
"@dnd-kit/core": "^6.0.8",
|
||||
"@dnd-kit/sortable": "^7.0.2",
|
||||
"@dnd-kit/utilities": "^3.2.1",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user