mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
core: s3: use lib-storage
This commit is contained in:
1 parent
52422c33b3
commit
0593d4d86a
2 files changed
+21
-7
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "4.0.12",
|
||||
"version": "4.0.13",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/plugin-api",
|
||||
"module": "src/plugin-api",
|
||||
@@ -13,6 +13,7 @@
|
||||
"preferUnplugged": true,
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.186.0",
|
||||
"@aws-sdk/lib-storage": "^3.186.0",
|
||||
"@aws-sdk/middleware-endpoint": "^3.186.0",
|
||||
"@aws-sdk/s3-presigned-post": "^3.186.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.186.0",
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
CopyObjectCommand, DeleteObjectCommand, DeleteObjectsCommand,
|
||||
GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client,
|
||||
} from '@aws-sdk/client-s3';
|
||||
import { Upload } from '@aws-sdk/lib-storage';
|
||||
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
|
||||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
||||
import {
|
||||
@@ -114,12 +115,24 @@ class RemoteStorageService {
|
||||
async put(target: string, file: string | Buffer | Readable, meta: Record<string, string> = {}) {
|
||||
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
|
||||
if (typeof file === 'string') file = createReadStream(file);
|
||||
await this.client.send(new PutObjectCommand({
|
||||
Bucket: this.opts.bucket,
|
||||
Body: file,
|
||||
Key: target,
|
||||
Metadata: meta,
|
||||
}));
|
||||
if (file instanceof Buffer && file.byteLength <= 5 * 1024 * 1024) {
|
||||
await this.client.send(new PutObjectCommand({
|
||||
Bucket: this.opts.bucket,
|
||||
Body: file,
|
||||
Key: target,
|
||||
Metadata: meta,
|
||||
}));
|
||||
} else {
|
||||
const upload = new Upload({
|
||||
client: this.client,
|
||||
params: { Bucket: this.opts.bucket, Key: target, Body: file },
|
||||
tags: [],
|
||||
queueSize: 4,
|
||||
partSize: 1024 * 1024 * 5,
|
||||
leavePartsOnError: false,
|
||||
});
|
||||
await upload.done();
|
||||
}
|
||||
}
|
||||
|
||||
async get(target: string, path?: string) {
|
||||
|
||||
Reference in new issue
Block a user