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> </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

File diff suppressed because it is too large Load Diff

View File

@ -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"

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) { 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,
ContentMD5,
ContentType,
...rest
});
return await client.send(command);
} }
export default {
createClient,
upload,
};