Browse Source

refactor(nocodb): migrate request to axios

pull/6362/head
Wing-Kam Wong 1 year ago
parent
commit
22a8cb95ca
  1. 29
      packages/nocodb/src/plugins/backblaze/Backblaze.ts
  2. 22
      packages/nocodb/src/plugins/gcs/Gcs.ts
  3. 28
      packages/nocodb/src/plugins/linode/LinodeObjectStorage.ts
  4. 27
      packages/nocodb/src/plugins/mino/Minio.ts
  5. 28
      packages/nocodb/src/plugins/ovhCloud/OvhCloud.ts
  6. 28
      packages/nocodb/src/plugins/s3/S3.ts
  7. 28
      packages/nocodb/src/plugins/scaleway/ScalewayObjectStorage.ts
  8. 28
      packages/nocodb/src/plugins/spaces/Spaces.ts
  9. 28
      packages/nocodb/src/plugins/upcloud/UpoCloud.ts
  10. 28
      packages/nocodb/src/plugins/vultr/Vultr.ts

29
packages/nocodb/src/plugins/backblaze/Backblaze.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -47,32 +47,29 @@ export default class Backblaze implements IStorageAdapterV2 {
const uploadParams: any = {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

22
packages/nocodb/src/plugins/gcs/Gcs.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import { Storage } from '@google-cloud/storage';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import type { StorageOptions } from '@google-cloud/storage';
@ -105,23 +105,19 @@ export default class Gcs implements IStorageAdapterV2 {
fileCreateByUrl(destPath: string, url: string): Promise<any> {
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, _, body) => {
if (err) return reject(err);
axios
.get(url)
.then((response) => {
this.storageClient
.bucket(this.bucketName)
.file(destPath)
.save(body)
.save(response.data)
.then((res) => resolve(res))
.catch(reject);
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/linode/LinodeObjectStorage.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -48,31 +48,27 @@ export default class LinodeObjectStorage implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

27
packages/nocodb/src/plugins/mino/Minio.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import { Client as MinioClient } from 'minio';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -95,20 +95,13 @@ export default class Minio implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, _, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = response.headers['content-type'];
// uploadParams.Body = fileStream;
// uploadParams.Key = key;
const metaData = {
// 'Content-Type': file.mimetype
// 'X-Amz-Meta-Testing': 1234,
@ -116,7 +109,7 @@ export default class Minio implements IStorageAdapterV2 {
};
// call S3 to retrieve upload file to specified bucket
this.minioClient
.putObject(this.input?.bucket, key, body, metaData)
.putObject(this.input?.bucket, key, response.data, metaData)
.then(() => {
resolve(
`http${this.input.useSSL ? 's' : ''}://${this.input.endPoint}:${
@ -125,8 +118,10 @@ export default class Minio implements IStorageAdapterV2 {
);
})
.catch(reject);
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/ovhCloud/OvhCloud.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -48,31 +48,27 @@ export default class OvhCloud implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/s3/S3.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -47,31 +47,27 @@ export default class S3 implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/scaleway/ScalewayObjectStorage.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -98,31 +98,27 @@ export default class ScalewayObjectStorage implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/spaces/Spaces.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -48,31 +48,27 @@ export default class Spaces implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/upcloud/UpoCloud.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -48,31 +48,27 @@ export default class UpoCloud implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

28
packages/nocodb/src/plugins/vultr/Vultr.ts

@ -1,7 +1,7 @@
import fs from 'fs';
import { promisify } from 'util';
import AWS from 'aws-sdk';
import request from 'request';
import axios from 'axios';
import type { IStorageAdapterV2, XcFile } from 'nc-plugin';
import type { Readable } from 'stream';
import { generateTempFilePath, waitForStreamClose } from '~/utils/pluginUtils';
@ -48,31 +48,27 @@ export default class Vultr implements IStorageAdapterV2 {
ACL: 'public-read',
};
return new Promise((resolve, reject) => {
// Configure the file stream and obtain the upload parameters
request(
{
url: url,
encoding: null,
},
(err, httpResponse, body) => {
if (err) return reject(err);
uploadParams.Body = body;
axios
.get(url)
.then((response) => {
uploadParams.Body = response.data;
uploadParams.Key = key;
uploadParams.ContentType = httpResponse.headers['content-type'];
uploadParams.ContentType = response.headers['content-type'];
// call S3 to retrieve upload file to specified bucket
this.s3Client.upload(uploadParams, (err1, data) => {
if (err) {
console.log('Error', err);
if (err1) {
console.log('Error', err1);
reject(err1);
}
if (data) {
resolve(data.Location);
}
});
},
);
})
.catch((error) => {
reject(error);
});
});
}

Loading…
Cancel
Save