@@ -10,26 +10,26 @@ 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 } from '../utils/interfaces '
13
+ import { IHelper , IImgInfo , IConfig , IPicGo , IStringKeyMap } from 'src/types '
14
14
import getClipboardImage from '../utils/getClipboardImage'
15
15
import Request from '../lib/Request'
16
16
import DB from '../utils/db'
17
17
import PluginHandler from '../lib/PluginHandler'
18
18
19
- class PicGo extends EventEmitter {
20
- private config : IConfig
21
- private lifecycle : Lifecycle
22
- private db : DB
19
+ class PicGo extends EventEmitter implements IPicGo {
20
+ private config ! : IConfig
21
+ private lifecycle ! : Lifecycle
22
+ private db ! : DB
23
23
configPath : string
24
- baseDir : string
25
- helper : IHelper
24
+ baseDir ! : string
25
+ helper ! : IHelper
26
26
log : Logger
27
27
cmd : Commander
28
28
output : IImgInfo [ ]
29
29
input : any [ ]
30
- pluginLoader : PluginLoader
30
+ pluginLoader ! : PluginLoader
31
31
pluginHandler : PluginHandler
32
- Request : Request
32
+ Request ! : Request
33
33
34
34
constructor ( configPath : string = '' ) {
35
35
super ( )
@@ -127,7 +127,7 @@ class PicGo extends EventEmitter {
127
127
128
128
// set config for ctx but will not be saved to db
129
129
// it's more lightweight
130
- setConfig ( config : object ) : void {
130
+ setConfig ( config : IStringKeyMap < any > ) : void {
131
131
Object . keys ( config ) . forEach ( ( name : string ) => {
132
132
set ( this . config , name , config [ name ] )
133
133
} )
@@ -139,10 +139,10 @@ class PicGo extends EventEmitter {
139
139
unset ( this . getConfig ( key ) , propName )
140
140
}
141
141
142
- async upload ( input ?: any [ ] ) : Promise < string | Error > {
142
+ async upload ( input ?: any [ ] ) : Promise < IImgInfo [ ] | Error > {
143
143
if ( this . configPath === '' ) {
144
144
this . log . error ( 'The configuration file only supports JSON format.' )
145
- return ''
145
+ return [ ]
146
146
}
147
147
// upload from clipboard
148
148
if ( input === undefined || input . length === 0 ) {
@@ -163,17 +163,17 @@ class PicGo extends EventEmitter {
163
163
}
164
164
} )
165
165
await this . lifecycle . start ( [ imgPath ] )
166
+ return this . output
166
167
}
167
168
} catch ( e ) {
168
169
this . log . error ( e )
169
170
this . emit ( 'failed' , e )
170
171
throw e
171
172
}
172
- return ''
173
173
} else {
174
174
// upload from path
175
175
await this . lifecycle . start ( input )
176
- return ''
176
+ return this . output
177
177
}
178
178
}
179
179
}
0 commit comments