Implement necessary APIs

This commit is contained in:
HoshinoKoji 2025-03-10 21:50:23 +08:00
parent 53915aad25
commit 5147163aa1
4 changed files with 559 additions and 1620 deletions

View File

@ -7,8 +7,7 @@
</head>
<body>
<script type="module">
import { createClient, upload } from './dist/s3simp.js';
const client = createClient('default');
import s3simp from './dist/s3simp.js';
</script>
</body>
</html>

2139
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,14 +3,15 @@
"version": "1.0.0",
"type": "module",
"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"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@aws-sdk/client-s3": "^3.758.0"
"aws-sdk": "^2.1692.0"
},
"devDependencies": {
"esbuild": "0.25.1"

View File

@ -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) {
return new S3Client({ region, maxAttempts });
export function createClient({
endpoint,
accessKeyId,
secretAccessKey,
maxRetries = 3,
signatureVersion = 'v4',
region = 'auto',
}) {
return new S3({ endpoint, accessKeyId, secretAccessKey, maxRetries, signatureVersion, region });
}
export async function upload({
@ -9,17 +16,12 @@ export async function upload({
Bucket,
Key,
Body,
ContentMD5,
ContentType,
...rest
}) {
const command = new PutObjectCommand({
Bucket,
Key,
Body,
ContentMD5,
ContentType,
...rest
});
return await client.send(command);
return await client.upload({ Bucket, Key, Body, ...rest }).promise();
}
export default {
createClient,
upload,
};