diff --git a/packages/nc-plugin/src/lib/IStorageAdapterV2.ts b/packages/nc-plugin/src/lib/IStorageAdapterV2.ts index c8563bc5c5..990afe01ec 100644 --- a/packages/nc-plugin/src/lib/IStorageAdapterV2.ts +++ b/packages/nc-plugin/src/lib/IStorageAdapterV2.ts @@ -1,4 +1,5 @@ import IStorageAdapter from './IStorageAdapter'; +import { Readable } from 'stream'; export default interface IStorageAdapterV2 extends IStorageAdapter { fileCreateByUrl( @@ -6,6 +7,9 @@ export default interface IStorageAdapterV2 extends IStorageAdapter { url: string, fileMeta?: FileMeta ): Promise; + fileCreateByStream(destPath: string, readStream: Readable): Promise; + fileReadByStream(key: string): Promise; + getDirectoryList(path: string): Promise; } interface FileMeta { diff --git a/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts b/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts index 4198c6b005..4912a39cc9 100644 --- a/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts +++ b/packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class Backblaze implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,21 @@ export default class Backblaze implements IStorageAdapterV2 { }); } + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + patchRegion(region: string): string { // in v0.0.1, we constructed the endpoint with `region = s3.us-west-001` // in v0.0.2, `region` would be `us-west-001` diff --git a/packages/nocodb/src/lib/plugins/gcs/Gcs.ts b/packages/nocodb/src/lib/plugins/gcs/Gcs.ts index cf20ba7737..5191ce80db 100644 --- a/packages/nocodb/src/lib/plugins/gcs/Gcs.ts +++ b/packages/nocodb/src/lib/plugins/gcs/Gcs.ts @@ -8,6 +8,7 @@ import { } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; import type { StorageOptions } from '@google-cloud/storage'; +import { Readable } from 'stream'; export default class Gcs implements IStorageAdapterV2 { private storageClient: Storage; @@ -126,4 +127,19 @@ export default class Gcs implements IStorageAdapterV2 { ); }); } + + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } } diff --git a/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts b/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts index fdaaa36556..0849b74503 100644 --- a/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts +++ b/packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class LinodeObjectStorage implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,21 @@ export default class LinodeObjectStorage implements IStorageAdapterV2 { }); } + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + public async fileDelete(_path: string): Promise { return Promise.resolve(undefined); } diff --git a/packages/nocodb/src/lib/plugins/mino/Minio.ts b/packages/nocodb/src/lib/plugins/mino/Minio.ts index 5534ce5cfe..7c36ce16b6 100644 --- a/packages/nocodb/src/lib/plugins/mino/Minio.ts +++ b/packages/nocodb/src/lib/plugins/mino/Minio.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class Minio implements IStorageAdapterV2 { private minioClient: MinioClient; @@ -131,4 +132,19 @@ export default class Minio implements IStorageAdapterV2 { ); }); } + + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } } diff --git a/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts b/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts index 704f43551b..3e571c67af 100644 --- a/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts +++ b/packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class OvhCloud implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,20 @@ export default class OvhCloud implements IStorageAdapterV2 { }); } + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + public async fileDelete(_path: string): Promise { return Promise.resolve(undefined); } diff --git a/packages/nocodb/src/lib/plugins/s3/S3.ts b/packages/nocodb/src/lib/plugins/s3/S3.ts index 1b5beb4ab7..57ead50098 100644 --- a/packages/nocodb/src/lib/plugins/s3/S3.ts +++ b/packages/nocodb/src/lib/plugins/s3/S3.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class S3 implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -77,6 +78,21 @@ export default class S3 implements IStorageAdapterV2 { }); } + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + public async fileDelete(_path: string): Promise { return Promise.resolve(undefined); } diff --git a/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts b/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts index 4eb851e0e4..7ef55cbe5d 100644 --- a/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts +++ b/packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class ScalewayObjectStorage implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -127,4 +128,19 @@ export default class ScalewayObjectStorage implements IStorageAdapterV2 { ); }); } + + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } } diff --git a/packages/nocodb/src/lib/plugins/spaces/Spaces.ts b/packages/nocodb/src/lib/plugins/spaces/Spaces.ts index 9c2deead66..73850d00b7 100644 --- a/packages/nocodb/src/lib/plugins/spaces/Spaces.ts +++ b/packages/nocodb/src/lib/plugins/spaces/Spaces.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class Spaces implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,21 @@ export default class Spaces implements IStorageAdapterV2 { }); } + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + public async fileDelete(_path: string): Promise { return Promise.resolve(undefined); } diff --git a/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts b/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts index 2de79207ea..1c9cc3d104 100644 --- a/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts +++ b/packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class UpoCloud implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,21 @@ export default class UpoCloud implements IStorageAdapterV2 { }); } + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + public async fileDelete(_path: string): Promise { return Promise.resolve(undefined); } diff --git a/packages/nocodb/src/lib/plugins/vultr/Vultr.ts b/packages/nocodb/src/lib/plugins/vultr/Vultr.ts index dcc166bf64..99bebb98dc 100644 --- a/packages/nocodb/src/lib/plugins/vultr/Vultr.ts +++ b/packages/nocodb/src/lib/plugins/vultr/Vultr.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import { Readable } from 'stream'; export default class Vultr implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,21 @@ export default class Vultr implements IStorageAdapterV2 { }); } + // TODO - implement + fileCreateByStream(_key: string, _stream: Readable): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + fileReadByStream(_key: string): Promise { + return Promise.resolve(undefined); + } + + // TODO - implement + getDirectoryList(_path: string): Promise { + return Promise.resolve(undefined); + } + public async fileDelete(_path: string): Promise { return Promise.resolve(undefined); } diff --git a/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts b/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts index 6819c5a0cf..f11fe6c10b 100644 --- a/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts +++ b/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts @@ -4,6 +4,7 @@ import { promisify } from 'util'; import mkdirp from 'mkdirp'; import axios from 'axios'; import NcConfigFactory from '../../../../utils/NcConfigFactory'; +import type { Readable } from 'stream'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; export default class Local implements IStorageAdapterV2 { @@ -65,6 +66,32 @@ export default class Local implements IStorageAdapterV2 { }); } + public async fileCreateByStream(key: string, stream: Readable): Promise { + return new Promise(async (resolve, reject) => { + const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/')); + try { + await mkdirp(path.dirname(destPath)); + const writableStream = fs.createWriteStream(destPath); + writableStream.on('finish', () => resolve()); + writableStream.on('error', (err) => reject(err)); + stream.pipe(writableStream); + } catch (e) { + throw e; + } + }); + } + + public async fileReadByStream(key: string): Promise { + const srcPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/')); + return fs.createReadStream(srcPath, { encoding: 'utf8' }); + } + + public async getDirectoryList(key: string): Promise { + const destDir = path.join(NcConfigFactory.getToolDir(), ...key.split('/')); + return fs.promises.readdir(destDir); + } + + // todo: implement fileDelete(_path: string): Promise { return Promise.resolve(undefined);