@@ -10,7 +10,7 @@ import uploaders from '../plugins/uploader'
10
10
import transformers from '../plugins/transformer'
11
11
import PluginLoader from '../lib/PluginLoader'
12
12
import { get , set , unset } from 'lodash'
13
- import { IHelper , IImgInfo , IConfig , IPicGo , IStringKeyMap } from 'src /types'
13
+ import { IHelper , IImgInfo , IConfig , IPicGo , IStringKeyMap , IPicGoPlugin } from '.. /types'
14
14
import getClipboardImage from '../utils/getClipboardImage'
15
15
import Request from '../lib/Request'
16
16
import DB from '../utils/db'
@@ -139,6 +139,22 @@ class PicGo extends EventEmitter implements IPicGo {
139
139
unset ( this . getConfig ( key ) , propName )
140
140
}
141
141
142
+ /**
143
+ * for node project adding a plugin by a simple way
144
+ */
145
+ addPlugin ( name : string , plugin : IPicGoPlugin ) : void {
146
+ if ( ! name || ! plugin || ( typeof plugin !== 'function' ) ) {
147
+ this . log . warn ( 'Please provide valid plugin' )
148
+ return
149
+ }
150
+ try {
151
+ plugin ( this ) . register ( )
152
+ } catch ( e ) {
153
+ this . log . warn ( 'Please provide valid plugin' )
154
+ this . log . error ( e )
155
+ }
156
+ }
157
+
142
158
async upload ( input ?: any [ ] ) : Promise < IImgInfo [ ] | Error > {
143
159
if ( this . configPath === '' ) {
144
160
this . log . error ( 'The configuration file only supports JSON format.' )
0 commit comments