Browse Source

feat(nocodb): move generate temp file path logic to a function

pull/4359/head
Wing-Kam Wong 2 years ago
parent
commit
6ff37a84a9
  1. 9
      packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts
  2. 9
      packages/nocodb/src/lib/plugins/gcs/Gcs.ts
  3. 9
      packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts
  4. 9
      packages/nocodb/src/lib/plugins/mino/Minio.ts
  5. 9
      packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts
  6. 9
      packages/nocodb/src/lib/plugins/s3/S3.ts
  7. 9
      packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts
  8. 9
      packages/nocodb/src/lib/plugins/spaces/Spaces.ts
  9. 9
      packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts
  10. 9
      packages/nocodb/src/lib/plugins/vultr/Vultr.ts
  11. 6
      packages/nocodb/src/lib/utils/pluginUtils.ts

9
packages/nocodb/src/lib/plugins/backblaze/Backblaze.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class Backblaze implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -120,7 +121,7 @@ export default class Backblaze implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/gcs/Gcs.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import { Storage, StorageOptions } from '@google-cloud/storage';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class Gcs implements IStorageAdapterV2 {
private storageClient: Storage;
@ -86,7 +87,7 @@ export default class Gcs implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/linode/LinodeObjectStorage.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class LinodeObjectStorage implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -110,7 +111,7 @@ export default class LinodeObjectStorage implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/mino/Minio.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import { Client as MinioClient } from 'minio';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class Minio implements IStorageAdapterV2 {
private minioClient: MinioClient;
@ -74,7 +75,7 @@ export default class Minio implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/ovhCloud/OvhCloud.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class OvhCloud implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -110,7 +111,7 @@ export default class OvhCloud implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/s3/S3.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class S3 implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -113,7 +114,7 @@ export default class S3 implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/scaleway/ScalewayObjectStorage.ts

@ -1,10 +1,11 @@
import path from 'path';
import fs from 'fs';
import os from 'os';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import AWS from 'aws-sdk';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class ScalewayObjectStorage implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -30,7 +31,7 @@ export default class ScalewayObjectStorage implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/spaces/Spaces.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class Spaces implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -118,7 +119,7 @@ export default class Spaces implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/upcloud/UpoCloud.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class UpoCloud implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -108,7 +109,7 @@ export default class UpoCloud implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

9
packages/nocodb/src/lib/plugins/vultr/Vultr.ts

@ -1,10 +1,11 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import AWS from 'aws-sdk';
import { IStorageAdapterV2, XcFile } from 'nc-plugin';
import request from 'request';
import { waitForStreamClose } from '../../utils/pluginUtils';
import {
waitForStreamClose,
generateTempFilePath,
} from '../../utils/pluginUtils';
export default class Vultr implements IStorageAdapterV2 {
private s3Client: AWS.S3;
@ -110,7 +111,7 @@ export default class Vultr implements IStorageAdapterV2 {
public async test(): Promise<boolean> {
try {
const tempFile = path.join(os.tmpdir(), 'temp.txt');
const tempFile = generateTempFilePath();
const createStream = fs.createWriteStream(tempFile);
await waitForStreamClose(createStream);
await this.fileCreate('nc-test-file.txt', {

6
packages/nocodb/src/lib/utils/pluginUtils.ts

@ -1,4 +1,10 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
export function generateTempFilePath() {
return path.join(os.tmpdir(), 'temp.txt');
}
export async function waitForStreamClose(
stream: fs.WriteStream

Loading…
Cancel
Save