fix(server): avoid get object content when syncing (#9402)

This commit is contained in:
liuyi
2024-12-28 00:25:15 +08:00
committed by GitHub
parent 6ebefbbf2b
commit 378db1054b
5 changed files with 75 additions and 37 deletions

View File

@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* oxlint-disable @typescript-eslint/no-non-null-assertion */
import { Readable } from 'node:stream';
import {
DeleteObjectCommand,
GetObjectCommand,
HeadObjectCommand,
ListObjectsV2Command,
NoSuchKey,
PutObjectCommand,
@@ -75,6 +76,34 @@ export class S3StorageProvider implements StorageProvider {
}
}
async head(key: string) {
try {
const obj = await this.client.send(
new HeadObjectCommand({
Bucket: this.bucket,
Key: key,
})
);
return {
contentType: obj.ContentType!,
contentLength: obj.ContentLength!,
lastModified: obj.LastModified!,
checksumCRC32: obj.ChecksumCRC32,
};
} catch (e) {
// 404
if (e instanceof NoSuchKey) {
this.logger.verbose(`Object \`${key}\` not found`);
return undefined;
} else {
throw new Error(`Failed to head object \`${key}\``, {
cause: e,
});
}
}
}
async get(key: string): Promise<{
body?: Readable;
metadata?: GetObjectMetadata;