1
1
require ( "dotenv" ) . config ( ) ;
2
- const VERSION = "1.4.5 " ;
2
+ const VERSION = "1.4.6 " ;
3
3
4
4
const express = require ( "express" ) ;
5
5
const schedule = require ( "node-schedule" ) ;
@@ -185,15 +185,6 @@ if (
185
185
}
186
186
187
187
function cacheimg ( ) {
188
- if ( typeof hbwgConfig . refreshtask === "function" ) {
189
- try {
190
- logwarn ( "task is running..." ) ;
191
- hbwgConfig . refreshtask ( ) ;
192
- logwarn ( "task is finish." ) ;
193
- } catch ( e ) {
194
- logerr ( `refreshtask: ${ e } ` ) ;
195
- }
196
- }
197
188
if ( hbwgConfig . getupdate !== false ) {
198
189
const requestOptions = {
199
190
method : "GET" ,
@@ -206,22 +197,22 @@ function cacheimg() {
206
197
}
207
198
fetch ( hbwgConfig . packageurl , requestOptions )
208
199
. then ( ( response ) => response . json ( ) )
209
- . then ( ( result ) => AfterGetVersion ( result ) )
200
+ . then ( async ( result ) => await AfterGetVersion ( result ) )
210
201
. catch ( ( error ) => logerr ( `getupdate: ${ error } ` ) ) ;
211
202
}
212
203
fetch ( hbwgConfig . api , {
213
204
method : "GET" ,
214
205
redirect : "follow" ,
215
206
} )
216
207
. then ( ( response ) => response . json ( ) )
217
- . then ( ( result ) => {
208
+ . then ( async ( result ) => {
218
209
hbwgConfig . bingsrc = result ;
219
210
const url = hbwgConfig . host + result . images [ 0 ] . url ;
220
- fetch ( url , {
211
+ await fetch ( url , {
221
212
method : "GET" ,
222
213
} )
223
- . then ( ( response ) => {
224
- response . arrayBuffer ( ) . then ( async ( buffer ) => {
214
+ . then ( async ( response ) => {
215
+ await response . arrayBuffer ( ) . then ( async ( buffer ) => {
225
216
await ( hbwgConfig . image = Buffer . from ( buffer ) ) ;
226
217
} ) ;
227
218
} )
@@ -230,8 +221,21 @@ function cacheimg() {
230
221
hbwgConfig . copyrightlink = String ( result . images [ 0 ] . copyrightlink ) ;
231
222
hbwgConfig . title = String ( result . images [ 0 ] . title ) ;
232
223
} )
233
- . catch ( ( error ) => logerr ( `source.bingsrc: ${ error } ` ) ) ;
234
-
224
+ . catch ( ( error ) => {
225
+ logerr ( `source.bingsrc: ${ error } ` ) ;
226
+ if ( hbwgConfig . image == undefined ) {
227
+ process . exit ( 1 ) ;
228
+ }
229
+ } ) ;
230
+ if ( typeof hbwgConfig . refreshtask === "function" ) {
231
+ try {
232
+ logwarn ( "task is running..." ) ;
233
+ hbwgConfig . refreshtask ( ) ;
234
+ logwarn ( "task is finish." ) ;
235
+ } catch ( e ) {
236
+ logerr ( `refreshtask: ${ e } ` ) ;
237
+ }
238
+ }
235
239
logback ( "Refresh Successfully!" ) ;
236
240
}
237
241
0 commit comments