Skip to content

Commit 05892b6

Browse files
committed
pr fixes
1 parent 5c4a79b commit 05892b6

File tree

6 files changed

+54
-63
lines changed

6 files changed

+54
-63
lines changed

.prettierignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
node_modules/
33
dist/
44
static/
5-
packages/server/assets/homepage.js
6-
packages/server/assets/homepage.min.css
5+
packages/server/assets/*

packages/common/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,4 @@ export * from './utils/sleep';
66
export * from './utils/config';
77
export * from './utils/unzip';
88
export * from './utils/directories';
9-
10-
export const JsonSaveParse = (str: string, errorReturn: any) => {
11-
try {
12-
return JSON.parse(str);
13-
} catch (e) {
14-
return errorReturn;
15-
}
16-
};
9+
export * from './utils/json';

packages/common/utils/json.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const JsonSaveParse = (str: string, errorReturn: any) => {
2+
try {
3+
return JSON.parse(str);
4+
} catch (e) {
5+
return errorReturn;
6+
}
7+
};

packages/server/utils/counters.ts

+16-47
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import path from 'path';
1010
import semver from 'semver';
1111

1212
import { getContentType } from '../utils';
13+
import { ICounter, ISettings } from './counters.types';
1314
import {
1415
authorHTML,
1516
authorLinksHTML,
@@ -95,8 +96,12 @@ export function parseTXT(filePath: string) {
9596
: [];
9697

9798
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+
];
99103
else object.resolution = ['Any', 'Any'];
104+
100105
if (object.authorlinks) object.authorlinks = object.authorlinks.split(',');
101106

102107
object.settings = Array.isArray(settings) ? settings : [];
@@ -112,20 +117,7 @@ export function parseSettings(
112117
settingsValuesPath: string,
113118
folderName: string
114119
): 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(
129121
fs.readFileSync(settingsPath, 'utf8'),
130122
new Error('nothing')
131123
);
@@ -262,15 +254,7 @@ export function saveSettings(
262254
value: any;
263255
}[]
264256
) {
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(
274258
fs.readFileSync(settingsPath, 'utf8'),
275259
new Error('nothing')
276260
);
@@ -289,8 +273,8 @@ export function saveSettings(
289273
if (find === -1) continue;
290274

291275
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;
294278
break;
295279
}
296280

@@ -319,22 +303,7 @@ function rebuildJSON({
319303
external,
320304
query
321305
}: {
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[];
338307
external?: boolean;
339308
query?: string;
340309
}) {
@@ -404,25 +373,25 @@ function rebuildJSON({
404373
'{COPY_X}',
405374
item.resolution[0] === -1 || item.resolution[0] === -2
406375
? 'ANY'
407-
: item.resolution?.[0]?.toString()
376+
: item.resolution[0].toString()
408377
)
409378
.replace(
410379
'{X}',
411380
item.resolution[0] === -1 || item.resolution[0] === -2
412381
? 'ANY'
413-
: item.resolution?.[0]?.toString()
382+
: item.resolution[0].toString()
414383
)
415384
.replace(
416385
'{COPY_Y}',
417386
item.resolution[1] === -1 || item.resolution[1] === -2
418387
? 'ANY'
419-
: item.resolution?.[1]?.toString()
388+
: item.resolution[1].toString()
420389
)
421390
.replace(
422391
'{Y}',
423392
item.resolution[1] === -1 || item.resolution[1] === -2
424393
? 'ANY'
425-
: item.resolution?.[1]?.toString()
394+
: item.resolution[1].toString()
426395
);
427396

428397
const settingsBtn =
@@ -518,7 +487,7 @@ function getLocalCounters() {
518487
resolution: [-2, '400'],
519488
authorlinks: [],
520489
settings: Array.isArray(settings) ? settings : []
521-
};
490+
} as ICounter;
522491
});
523492

524493
const array = countersListTXT.map((r) => parseTXT(r));
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export interface ISettings {
2+
uniqueID?: number;
3+
type: 'text' | 'number' | 'checkbox' | 'options' | 'color' | 'note';
4+
title: string;
5+
description: string;
6+
value: any;
7+
}
8+
9+
export interface ICounter {
10+
folderName: string;
11+
name: string;
12+
author: string;
13+
resolution: number[];
14+
authorlinks: string[];
15+
settings: ISettings[];
16+
17+
usecase?: string;
18+
compatiblewith?: string;
19+
assets?: {
20+
type: string;
21+
url: string;
22+
}[];
23+
downloadLink?: string;
24+
}

packages/tosu/src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import { InstanceManager } from './objects/instanceManager/instanceManager';
1111
const httpServer = new Server({ instanceManager });
1212

1313
const { update } = argumetsParser(process.argv);
14-
if (
15-
process.env.NODE_ENV !== 'development' &&
16-
((update !== null && update === true) ||
17-
update === null ||
18-
config.enableAutoUpdate === true)
19-
) {
14+
15+
const isDev = process.env.NODE_ENV !== 'development';
16+
const isUpdateArg = (update !== null && update === true) || update === null;
17+
const isConfigUpdate = config.enableAutoUpdate === true;
18+
if (isDev && isUpdateArg && isConfigUpdate) {
2019
await autoUpdater();
2120
} else {
2221
await checkUpdates();

0 commit comments

Comments
 (0)