Browse Source

fix: plugin test implementation

re #307

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/341/head
Pranav C 3 years ago
parent
commit
cea77f292d
  1. 25
      packages/nc-gui/components/project/appStore/appInstall.vue
  2. 6
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  3. 15
      packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts
  4. 2
      packages/nocodb/src/plugins/backblaze/Backblaze.ts
  5. 2
      packages/nocodb/src/plugins/gcs/Gcs.ts
  6. 2
      packages/nocodb/src/plugins/linode/LinodeObjectStorage.ts
  7. 2
      packages/nocodb/src/plugins/mino/Minio.ts
  8. 2
      packages/nocodb/src/plugins/ovhCloud/OvhCloud.ts
  9. 2
      packages/nocodb/src/plugins/s3/S3.ts
  10. 2
      packages/nocodb/src/plugins/scaleway/ScalewayObjectStorage.ts
  11. 2
      packages/nocodb/src/plugins/spaces/Spaces.ts
  12. 2
      packages/nocodb/src/plugins/upcloud/UpoCloud.ts
  13. 2
      packages/nocodb/src/plugins/vultr/Vultr.ts

25
packages/nc-gui/components/project/appStore/appInstall.vue

@ -66,10 +66,12 @@
<div class="d-flex mb-4 mt-7 justify-center">
<v-btn small
:outlined="action.key !== 'save'"
v-for="action in formDetails.actions" @click="doAction(action)"
v-for="action in formDetails.actions"
@click="doAction(action)"
:key="action.key"
:color="action.key === 'save' ? 'primary' : '' "
:disabled="action.key === 'save' && !valid"
:disabled="(action.key === 'save' && !valid) || (action.key === 'test' && testing)"
:loading="action.key === 'test' && testing"
>{{ action.label }}
</v-btn>
</div>
@ -91,7 +93,8 @@ export default {
settings: null,
pluginId: null,
title: null,
valid: null
valid: null,
testing: false
}),
methods: {
simpleAnim() {
@ -146,17 +149,23 @@ export default {
},
async testSettings() {
this.testing = true;
try {
await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginTest', {
const res = await this.$store.dispatch('sqlMgr/ActSqlOp', [null, 'xcPluginTest', {
input: this.settings,
id: this.pluginId,
category: this.plugin.category,
title: this.plugin.title
}]);
this.$toast.success('Successfully tested plugin settings').goAway(3000)
if (res) {
this.$toast.success('Successfully tested plugin settings').goAway(3000)
} else {
this.$toast.info('Invalid credentials').goAway(3000)
}
} catch (e) {
this.$toast.error(e.message).goAway(3000);
this.$toast[e.message === 'Not implemented' ? 'info' : 'error'](e.message).goAway(3000);
}
this.testing = false;
},
async doAction(action) {
switch (action.key) {
@ -246,7 +255,5 @@ tbody tr:nth-of-type(odd) {
background-color: transparent;
}
.form-input-label {
padding-bottom: 16px;
}
</style>

6
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -2854,17 +2854,13 @@ export default class NcMetaMgr {
protected async xcPluginTest(req, args): Promise<any> {
try {
switch (args.args.category) {
// case 'Storage':
// const storageIns = StorageFactory.createNewInstance(args.args, args.args.input);
// await storageIns.init();
// await storageIns?.test();
// break;
case 'Email':
const emailIns = EmailFactory.createNewInstance(args.args, args.args.input)
await emailIns.init();
await emailIns?.test(req.user?.email)
break;
default:
return this.pluginMgr.test(args.args)
break;
}
return true;

15
packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts

@ -99,7 +99,7 @@ class NcPluginMgr {
try {
await tempPlugin.init(pluginConfig?.input);
}catch (e){
} catch (e) {
console.log(`Plugin(${plugin?.title}) initialization failed : ${e.message}`)
}
}
@ -132,6 +132,19 @@ class NcPluginMgr {
}
public async test(args: any): Promise<boolean> {
switch (args.category) {
case 'Storage':
const plugin = defaultPlugins.find(pluginConfig => pluginConfig?.title === args.title);
const tempPlugin = new plugin.builder(this.app, plugin);
await tempPlugin.init(args?.input);
return tempPlugin?.getAdapter()?.test?.();
break;
default:
throw new Error('Not implemented');
}
}
}
export default NcPluginMgr;

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

@ -81,7 +81,7 @@ export default class Backblaze implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -82,7 +82,7 @@ export default class Gcs implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -79,7 +79,7 @@ export default class LinodeObjectStorage implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -71,7 +71,7 @@ export default class Minio implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -81,7 +81,7 @@ export default class OvhCloud implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -87,7 +87,7 @@ export default class S3 implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -79,7 +79,7 @@ export default class ScalewayObjectStorage implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -88,7 +88,7 @@ export default class Spaces implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -81,7 +81,7 @@ export default class UpoCloud implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

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

@ -81,7 +81,7 @@ export default class Vultr implements IStorageAdapter {
const tempFile = path.join(process.cwd(), 'temp.txt');
const createStream = fs.createWriteStream(tempFile);
createStream.end();
await this.fileCreate('/test.txt', {
await this.fileCreate('/nc-test-file.txt', {
path: tempFile,
mimetype: '',
originalname: 'temp.txt',

Loading…
Cancel
Save