@@ -10,6 +10,7 @@ import path from 'path';
10
10
import semver from 'semver' ;
11
11
12
12
import { getContentType } from '../utils' ;
13
+ import { ICounter , ISettings } from './counters.types' ;
13
14
import {
14
15
authorHTML ,
15
16
authorLinksHTML ,
@@ -95,8 +96,12 @@ export function parseTXT(filePath: string) {
95
96
: [ ] ;
96
97
97
98
if ( object . resolution )
98
- object . resolution = object . resolution . map ( ( r ) => r . trim ( ) ) ;
99
+ object . resolution = object . resolution . map ( ( r ) => r . trim ( ) ) || [
100
+ 'Any' ,
101
+ 'Any'
102
+ ] ;
99
103
else object . resolution = [ 'Any' , 'Any' ] ;
104
+
100
105
if ( object . authorlinks ) object . authorlinks = object . authorlinks . split ( ',' ) ;
101
106
102
107
object . settings = Array . isArray ( settings ) ? settings : [ ] ;
@@ -112,20 +117,7 @@ export function parseSettings(
112
117
settingsValuesPath : string ,
113
118
folderName : string
114
119
) : string | Error {
115
- const array :
116
- | {
117
- type :
118
- | 'text'
119
- | 'number'
120
- | 'checkbox'
121
- | 'options'
122
- | 'color'
123
- | 'note' ;
124
- title : string ;
125
- description : string ;
126
- value : any ;
127
- } [ ]
128
- | Error = JsonSaveParse (
120
+ const array : ISettings [ ] | Error = JsonSaveParse (
129
121
fs . readFileSync ( settingsPath , 'utf8' ) ,
130
122
new Error ( 'nothing' )
131
123
) ;
@@ -262,15 +254,7 @@ export function saveSettings(
262
254
value : any ;
263
255
} [ ]
264
256
) {
265
- const array :
266
- | {
267
- uniqueID : number ;
268
- type : 'input' | 'checkbox' | 'options' | 'note' ;
269
- title : string ;
270
- description : string ;
271
- value : any ;
272
- } [ ]
273
- | Error = JsonSaveParse (
257
+ const array : ISettings [ ] | Error = JsonSaveParse (
274
258
fs . readFileSync ( settingsPath , 'utf8' ) ,
275
259
new Error ( 'nothing' )
276
260
) ;
@@ -289,8 +273,8 @@ export function saveSettings(
289
273
if ( find === - 1 ) continue ;
290
274
291
275
switch ( array [ find ] . type ) {
292
- case 'input ' : {
293
- array [ find ] . value = setting . value ;
276
+ case 'number ' : {
277
+ array [ find ] . value = isNaN ( setting . value ) ? 0 : + setting . value ;
294
278
break ;
295
279
}
296
280
@@ -319,22 +303,7 @@ function rebuildJSON({
319
303
external,
320
304
query
321
305
} : {
322
- array : {
323
- folderName : string ;
324
- name : string ;
325
- author : string ;
326
- resolution : number [ ] ;
327
- authorlinks : string [ ] ;
328
- settings : [ ] ;
329
-
330
- usecase ?: string ;
331
- compatiblewith ?: string ;
332
- assets ?: {
333
- type : string ;
334
- url : string ;
335
- } [ ] ;
336
- downloadLink ?: string ;
337
- } [ ] ;
306
+ array : ICounter [ ] ;
338
307
external ?: boolean ;
339
308
query ?: string ;
340
309
} ) {
@@ -404,25 +373,25 @@ function rebuildJSON({
404
373
'{COPY_X}' ,
405
374
item . resolution [ 0 ] === - 1 || item . resolution [ 0 ] === - 2
406
375
? 'ANY'
407
- : item . resolution ?. [ 0 ] ? .toString ( )
376
+ : item . resolution [ 0 ] . toString ( )
408
377
)
409
378
. replace (
410
379
'{X}' ,
411
380
item . resolution [ 0 ] === - 1 || item . resolution [ 0 ] === - 2
412
381
? 'ANY'
413
- : item . resolution ?. [ 0 ] ? .toString ( )
382
+ : item . resolution [ 0 ] . toString ( )
414
383
)
415
384
. replace (
416
385
'{COPY_Y}' ,
417
386
item . resolution [ 1 ] === - 1 || item . resolution [ 1 ] === - 2
418
387
? 'ANY'
419
- : item . resolution ?. [ 1 ] ? .toString ( )
388
+ : item . resolution [ 1 ] . toString ( )
420
389
)
421
390
. replace (
422
391
'{Y}' ,
423
392
item . resolution [ 1 ] === - 1 || item . resolution [ 1 ] === - 2
424
393
? 'ANY'
425
- : item . resolution ?. [ 1 ] ? .toString ( )
394
+ : item . resolution [ 1 ] . toString ( )
426
395
) ;
427
396
428
397
const settingsBtn =
@@ -518,7 +487,7 @@ function getLocalCounters() {
518
487
resolution : [ - 2 , '400' ] ,
519
488
authorlinks : [ ] ,
520
489
settings : Array . isArray ( settings ) ? settings : [ ]
521
- } ;
490
+ } as ICounter ;
522
491
} ) ;
523
492
524
493
const array = countersListTXT . map ( ( r ) => parseTXT ( r ) ) ;
0 commit comments