mirror of
https://github.com/docmost/docmost.git
synced 2026-05-17 23:14:07 +08:00
- sync
- reinstantiate S3 client to fix file upload errors during import - delete import zip file after use
This commit is contained in:
@@ -28,7 +28,7 @@ export class LocalDriver implements StorageDriver {
|
||||
}
|
||||
}
|
||||
|
||||
async uploadStream(filePath: string, file: Readable): Promise<void> {
|
||||
async uploadStream(filePath: string, file: Readable, options?: { recreateClient?: boolean }): Promise<void> {
|
||||
try {
|
||||
const fullPath = this._fullPath(filePath);
|
||||
await fs.mkdir(dirname(fullPath), { recursive: true });
|
||||
|
||||
@@ -41,12 +41,26 @@ export class S3Driver implements StorageDriver {
|
||||
}
|
||||
}
|
||||
|
||||
async uploadStream(filePath: string, file: Readable): Promise<void> {
|
||||
async uploadStream(
|
||||
filePath: string,
|
||||
file: Readable,
|
||||
options?: { recreateClient?: boolean },
|
||||
): Promise<void> {
|
||||
let clientToUse = this.s3Client;
|
||||
let shouldDestroyClient = false;
|
||||
|
||||
// optionally recreate client to avoid socket hang errors
|
||||
// (during multi-attachments imports)
|
||||
if (options?.recreateClient) {
|
||||
clientToUse = new S3Client(this.config as any);
|
||||
shouldDestroyClient = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const contentType = getMimeType(filePath);
|
||||
|
||||
const upload = new Upload({
|
||||
client: this.s3Client,
|
||||
client: clientToUse,
|
||||
params: {
|
||||
Bucket: this.config.bucket,
|
||||
Key: filePath,
|
||||
@@ -58,6 +72,10 @@ export class S3Driver implements StorageDriver {
|
||||
await upload.done();
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to upload file: ${(err as Error).message}`);
|
||||
} finally {
|
||||
if (shouldDestroyClient && clientToUse) {
|
||||
clientToUse.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user