diff --git a/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts b/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts index 90938d59d1..ad6ab55f7f 100644 --- a/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts +++ b/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class Backblaze implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -121,7 +121,7 @@ export default class Backblaze implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/gcs/Gcs.ts b/packages/nocodb/src/lib/plugins/gcs/Gcs.ts index 404cb3b875..7a696e84d9 100644 --- a/packages/nocodb/src/lib/plugins/gcs/Gcs.ts +++ b/packages/nocodb/src/lib/plugins/gcs/Gcs.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import { Storage, StorageOptions } from '@google-cloud/storage'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class Gcs implements IStorageAdapterV2 { private storageClient: Storage; @@ -87,7 +87,7 @@ export default class Gcs implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts b/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts index 9bd9ffea30..a2d6b5a1b9 100644 --- a/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts +++ b/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class LinodeObjectStorage implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -111,7 +111,7 @@ export default class LinodeObjectStorage implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/mino/Minio.ts b/packages/nocodb/src/lib/plugins/mino/Minio.ts index 49c0a1b107..101547a0c5 100644 --- a/packages/nocodb/src/lib/plugins/mino/Minio.ts +++ b/packages/nocodb/src/lib/plugins/mino/Minio.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import { Client as MinioClient } from 'minio'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class Minio implements IStorageAdapterV2 { private minioClient: MinioClient; @@ -75,7 +75,7 @@ export default class Minio implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts b/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts index 8c5a8ed83d..fc075b40a7 100644 --- a/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts +++ b/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class OvhCloud implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -111,7 +111,7 @@ export default class OvhCloud implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/s3/S3.ts b/packages/nocodb/src/lib/plugins/s3/S3.ts index 39218b5f91..3d6a44721d 100644 --- a/packages/nocodb/src/lib/plugins/s3/S3.ts +++ b/packages/nocodb/src/lib/plugins/s3/S3.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class S3 implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -114,7 +114,7 @@ export default class S3 implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts b/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts index 79803afc75..4b21d5c1c3 100644 --- a/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts +++ b/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts @@ -3,6 +3,7 @@ import fs from 'fs'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import AWS from 'aws-sdk'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class ScalewayObjectStorage implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -30,7 +31,7 @@ export default class ScalewayObjectStorage implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/spaces/Spaces.ts b/packages/nocodb/src/lib/plugins/spaces/Spaces.ts index 1b89c9b997..025a859029 100644 --- a/packages/nocodb/src/lib/plugins/spaces/Spaces.ts +++ b/packages/nocodb/src/lib/plugins/spaces/Spaces.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class Spaces implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -119,7 +119,7 @@ export default class Spaces implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts b/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts index fc1b6489b3..cda09a9be7 100644 --- a/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts +++ b/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class UpoCloud implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -109,7 +109,7 @@ export default class UpoCloud implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/plugins/vultr/Vultr.ts b/packages/nocodb/src/lib/plugins/vultr/Vultr.ts index f3ea9c2058..8729703161 100644 --- a/packages/nocodb/src/lib/plugins/vultr/Vultr.ts +++ b/packages/nocodb/src/lib/plugins/vultr/Vultr.ts @@ -1,9 +1,9 @@ import fs from 'fs'; import path from 'path'; - import AWS from 'aws-sdk'; import { IStorageAdapterV2, XcFile } from 'nc-plugin'; import request from 'request'; +import { waitForStreamClose } from '../../utils/pluginUtils'; export default class Vultr implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -111,7 +111,7 @@ export default class Vultr implements IStorageAdapterV2 { try { const tempFile = path.join(process.cwd(), 'temp.txt'); const createStream = fs.createWriteStream(tempFile); - createStream.end(); + await waitForStreamClose(createStream); await this.fileCreate('nc-test-file.txt', { path: tempFile, mimetype: '', diff --git a/packages/nocodb/src/lib/utils/pluginUtils.ts b/packages/nocodb/src/lib/utils/pluginUtils.ts new file mode 100644 index 0000000000..e329b628e7 --- /dev/null +++ b/packages/nocodb/src/lib/utils/pluginUtils.ts @@ -0,0 +1,16 @@ +import fs from 'fs'; + +export async function waitForStreamClose( + stream: fs.WriteStream +): Promise { + return new Promise((resolve, reject) => { + stream + .once('finish', () => { + resolve(); + }) + .once('error', (err) => { + reject(err); + }); + stream.end(); + }); +}