From ca742727d562e47a16c5f27f1afae4e0f7aeb1b7 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 18 Apr 2023 17:19:41 +0300 Subject: [PATCH] feat: migrate plugin functions to nest Signed-off-by: mertmit --- .../src/plugins/backblaze/Backblaze.ts | 16 +++++++++ packages/nocodb-nest/src/plugins/gcs/Gcs.ts | 16 +++++++++ .../src/plugins/linode/LinodeObjectStorage.ts | 16 +++++++++ .../nocodb-nest/src/plugins/mino/Minio.ts | 16 +++++++++ .../src/plugins/ovhCloud/OvhCloud.ts | 16 +++++++++ packages/nocodb-nest/src/plugins/s3/S3.ts | 16 +++++++++ .../plugins/scaleway/ScalewayObjectStorage.ts | 16 +++++++++ .../nocodb-nest/src/plugins/spaces/Spaces.ts | 16 +++++++++ .../nocodb-nest/src/plugins/storage/Local.ts | 33 +++++++++++++++++++ .../src/plugins/upcloud/UpoCloud.ts | 16 +++++++++ .../nocodb-nest/src/plugins/vultr/Vultr.ts | 16 +++++++++ 11 files changed, 193 insertions(+) diff --git a/packages/nocodb-nest/src/plugins/backblaze/Backblaze.ts b/packages/nocodb-nest/src/plugins/backblaze/Backblaze.ts index 888bb6ecab..85cf074132 100644 --- a/packages/nocodb-nest/src/plugins/backblaze/Backblaze.ts +++ b/packages/nocodb-nest/src/plugins/backblaze/Backblaze.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/gcs/Gcs.ts b/packages/nocodb-nest/src/plugins/gcs/Gcs.ts index 91644584cc..387ffd78b9 100644 --- a/packages/nocodb-nest/src/plugins/gcs/Gcs.ts +++ b/packages/nocodb-nest/src/plugins/gcs/Gcs.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { Readable } from 'stream'; import type { StorageOptions } from '@google-cloud/storage'; export default class Gcs implements IStorageAdapterV2 { @@ -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-nest/src/plugins/linode/LinodeObjectStorage.ts b/packages/nocodb-nest/src/plugins/linode/LinodeObjectStorage.ts index bff3580e9e..d02a879a78 100644 --- a/packages/nocodb-nest/src/plugins/linode/LinodeObjectStorage.ts +++ b/packages/nocodb-nest/src/plugins/linode/LinodeObjectStorage.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/mino/Minio.ts b/packages/nocodb-nest/src/plugins/mino/Minio.ts index 9737542485..11c8d900e1 100644 --- a/packages/nocodb-nest/src/plugins/mino/Minio.ts +++ b/packages/nocodb-nest/src/plugins/mino/Minio.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/ovhCloud/OvhCloud.ts b/packages/nocodb-nest/src/plugins/ovhCloud/OvhCloud.ts index c0671c9dc1..df220cefab 100644 --- a/packages/nocodb-nest/src/plugins/ovhCloud/OvhCloud.ts +++ b/packages/nocodb-nest/src/plugins/ovhCloud/OvhCloud.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { Readable } from 'stream'; export default class OvhCloud implements IStorageAdapterV2 { private s3Client: AWS.S3; @@ -78,6 +79,21 @@ export default class OvhCloud 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-nest/src/plugins/s3/S3.ts b/packages/nocodb-nest/src/plugins/s3/S3.ts index f5abab81ca..3a722f9e6c 100644 --- a/packages/nocodb-nest/src/plugins/s3/S3.ts +++ b/packages/nocodb-nest/src/plugins/s3/S3.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/scaleway/ScalewayObjectStorage.ts b/packages/nocodb-nest/src/plugins/scaleway/ScalewayObjectStorage.ts index be76c80a7b..d94c956c6e 100644 --- a/packages/nocodb-nest/src/plugins/scaleway/ScalewayObjectStorage.ts +++ b/packages/nocodb-nest/src/plugins/scaleway/ScalewayObjectStorage.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/spaces/Spaces.ts b/packages/nocodb-nest/src/plugins/spaces/Spaces.ts index 9a3248a783..5985d1d1f8 100644 --- a/packages/nocodb-nest/src/plugins/spaces/Spaces.ts +++ b/packages/nocodb-nest/src/plugins/spaces/Spaces.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/storage/Local.ts b/packages/nocodb-nest/src/plugins/storage/Local.ts index 0028430ed5..26740839b9 100644 --- a/packages/nocodb-nest/src/plugins/storage/Local.ts +++ b/packages/nocodb-nest/src/plugins/storage/Local.ts @@ -5,6 +5,7 @@ import mkdirp from 'mkdirp'; import axios from 'axios'; import NcConfigFactory from '../../utils/NcConfigFactory'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { Readable } from 'stream'; export default class Local implements IStorageAdapterV2 { constructor() {} @@ -65,6 +66,38 @@ export default class Local implements IStorageAdapterV2 { }); } + public async fileCreateByStream( + key: string, + stream: Readable, + ): Promise { + return new Promise((resolve, reject) => { + const destPath = path.join( + NcConfigFactory.getToolDir(), + ...key.split('/'), + ); + try { + mkdirp(path.dirname(destPath)).then(() => { + 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); diff --git a/packages/nocodb-nest/src/plugins/upcloud/UpoCloud.ts b/packages/nocodb-nest/src/plugins/upcloud/UpoCloud.ts index 221b1f1fa0..8a6c3762fe 100644 --- a/packages/nocodb-nest/src/plugins/upcloud/UpoCloud.ts +++ b/packages/nocodb-nest/src/plugins/upcloud/UpoCloud.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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-nest/src/plugins/vultr/Vultr.ts b/packages/nocodb-nest/src/plugins/vultr/Vultr.ts index 4083b3a783..1cfaa2b9f5 100644 --- a/packages/nocodb-nest/src/plugins/vultr/Vultr.ts +++ b/packages/nocodb-nest/src/plugins/vultr/Vultr.ts @@ -7,6 +7,7 @@ import { waitForStreamClose, } from '../../utils/pluginUtils'; import type { IStorageAdapterV2, XcFile } from 'nc-plugin'; +import type { 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); }