🎨 Simplify usage
This commit is contained in:
21
bin/utils/info.ts
vendored
21
bin/utils/info.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import crypto from 'crypto';
|
||||
import prompts from "prompts";
|
||||
import ora from "ora";
|
||||
|
||||
// Generates an identifier based on the given URL.
|
||||
export function getIdentifier(url: string) {
|
||||
@@ -19,3 +20,23 @@ export async function promptText(message: string, initial?: string): Promise<str
|
||||
});
|
||||
return response.content;
|
||||
}
|
||||
|
||||
export function capitalizeFirstLetter(string: string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
export function getSpinner(text: string) {
|
||||
const loadingType = {
|
||||
"interval": 100,
|
||||
"frames": [
|
||||
"✶",
|
||||
"✵",
|
||||
"✸",
|
||||
"✹",
|
||||
"✺",
|
||||
"✹",
|
||||
"✷",
|
||||
]
|
||||
}
|
||||
return ora({ text: `${text}\n`, spinner: loadingType }).start();
|
||||
}
|
||||
|
||||
8
bin/utils/ip.ts
vendored
8
bin/utils/ip.ts
vendored
@@ -27,7 +27,7 @@ const ping = async (host: string) => {
|
||||
const timeoutPromise = new Promise<number>((_, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(new Error('Request timed out after 3 seconds'));
|
||||
}, 3000);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
return Promise.race([requestPromise, timeoutPromise]);
|
||||
@@ -40,7 +40,7 @@ async function isChinaDomain(domain: string): Promise<boolean> {
|
||||
return await isChinaIP(ip, domain);
|
||||
} catch (error) {
|
||||
logger.debug(`${domain} can't be parse!`);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ async function isChinaIP(ip: string, domain: string): Promise<boolean> {
|
||||
try {
|
||||
const delay = await ping(ip);
|
||||
logger.debug(`${domain} latency is ${delay} ms`);
|
||||
return delay > 500;
|
||||
return delay > 1000;
|
||||
} catch (error) {
|
||||
logger.debug(`ping ${domain} failed!`);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user