mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix object upload content-type header
This commit is contained in:
1 parent
87c8eb060c
commit
aa5df5346a
2 files changed
+11
-9
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "4.2.4",
|
"version": "4.2.5",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/plugin-api",
|
"main": "src/plugin-api",
|
||||||
"module": "src/plugin-api",
|
"module": "src/plugin-api",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { PassThrough, Readable } from 'stream';
|
|||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import {
|
import {
|
||||||
CopyObjectCommand, DeleteObjectCommand, DeleteObjectsCommand,
|
CopyObjectCommand, DeleteObjectCommand, DeleteObjectsCommand,
|
||||||
GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client,
|
GetObjectCommand, HeadObjectCommand, PutObjectCommand, PutObjectCommandInput, S3Client,
|
||||||
} from '@aws-sdk/client-s3';
|
} from '@aws-sdk/client-s3';
|
||||||
import { Upload } from '@aws-sdk/lib-storage';
|
import { Upload } from '@aws-sdk/lib-storage';
|
||||||
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
|
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
|
||||||
@@ -115,17 +115,19 @@ class RemoteStorageService {
|
|||||||
async put(target: string, file: string | Buffer | Readable, meta: Record<string, string> = {}) {
|
async put(target: string, file: string | Buffer | Readable, meta: Record<string, string> = {}) {
|
||||||
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
|
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
|
||||||
if (typeof file === 'string') file = createReadStream(file);
|
if (typeof file === 'string') file = createReadStream(file);
|
||||||
|
const params: PutObjectCommandInput = {
|
||||||
|
Bucket: this.opts.bucket,
|
||||||
|
Key: target,
|
||||||
|
Body: file,
|
||||||
|
Metadata: meta,
|
||||||
|
ContentType: meta['Content-Type'] || 'application/octet-stream',
|
||||||
|
};
|
||||||
if (file instanceof Buffer && file.byteLength <= 5 * 1024 * 1024) {
|
if (file instanceof Buffer && file.byteLength <= 5 * 1024 * 1024) {
|
||||||
await this.client.send(new PutObjectCommand({
|
await this.client.send(new PutObjectCommand(params));
|
||||||
Bucket: this.opts.bucket,
|
|
||||||
Body: file,
|
|
||||||
Key: target,
|
|
||||||
Metadata: meta,
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
const upload = new Upload({
|
const upload = new Upload({
|
||||||
client: this.client,
|
client: this.client,
|
||||||
params: { Bucket: this.opts.bucket, Key: target, Body: file },
|
params,
|
||||||
tags: [],
|
tags: [],
|
||||||
queueSize: 4,
|
queueSize: 4,
|
||||||
partSize: 1024 * 1024 * 5,
|
partSize: 1024 * 1024 * 5,
|
||||||
|
|||||||
Reference in new issue
Block a user