Implement necessary APIs
This commit is contained in:
parent
53915aad25
commit
5147163aa1
@ -7,8 +7,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { createClient, upload } from './dist/s3simp.js';
|
import s3simp from './dist/s3simp.js';
|
||||||
const client = createClient('default');
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
2139
package-lock.json
generated
2139
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,14 +3,15 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild s3simp.js --bundle --minify --format=esm --outdir=dist",
|
"build": "esbuild s3simp.js --bundle --minify --format=esm --define:global=window --outdir=dist",
|
||||||
|
"build:dev": "esbuild s3simp.js --bundle --minify --sourcemap --define:global=window --format=esm --outdir=dist",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.758.0"
|
"aws-sdk": "^2.1692.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "0.25.1"
|
"esbuild": "0.25.1"
|
||||||
|
32
s3simp.js
32
s3simp.js
@ -1,7 +1,14 @@
|
|||||||
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
const S3 = require('aws-sdk/clients/s3.js');
|
||||||
|
|
||||||
export function createClient(region, maxAttempts) {
|
export function createClient({
|
||||||
return new S3Client({ region, maxAttempts });
|
endpoint,
|
||||||
|
accessKeyId,
|
||||||
|
secretAccessKey,
|
||||||
|
maxRetries = 3,
|
||||||
|
signatureVersion = 'v4',
|
||||||
|
region = 'auto',
|
||||||
|
}) {
|
||||||
|
return new S3({ endpoint, accessKeyId, secretAccessKey, maxRetries, signatureVersion, region });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function upload({
|
export async function upload({
|
||||||
@ -9,17 +16,12 @@ export async function upload({
|
|||||||
Bucket,
|
Bucket,
|
||||||
Key,
|
Key,
|
||||||
Body,
|
Body,
|
||||||
ContentMD5,
|
|
||||||
ContentType,
|
|
||||||
...rest
|
...rest
|
||||||
}) {
|
}) {
|
||||||
const command = new PutObjectCommand({
|
return await client.upload({ Bucket, Key, Body, ...rest }).promise();
|
||||||
Bucket,
|
}
|
||||||
Key,
|
|
||||||
Body,
|
export default {
|
||||||
ContentMD5,
|
createClient,
|
||||||
ContentType,
|
upload,
|
||||||
...rest
|
};
|
||||||
});
|
|
||||||
return await client.send(command);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user