feat: finalize first modular pack

This commit is contained in:
divocat
2025-10-04 01:15:12 +03:00
parent eb52d52eb4
commit d9a4f50f62
15 changed files with 241 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
// This file is autogenerated, please don't change manually
"use strict";
"require baseclass";
"require fs";
// src/validators/validateIp.ts
function validateIPV4(ip) {
@@ -54,7 +55,7 @@ function validateUrl(url, protocols = ["http:", "https:"]) {
};
}
return { valid: true, message: "Valid" };
} catch (e) {
} catch (_e) {
return { valid: false, message: "Invalid URL format" };
}
}
@@ -143,7 +144,7 @@ function validateShadowsocksUrl(url) {
message: "Invalid Shadowsocks URL: decoded credentials must contain method:password"
};
}
} catch (e) {
} catch (_e) {
if (!encryptedPart.includes(":") && !encryptedPart.includes("-")) {
return {
valid: false,
@@ -176,7 +177,7 @@ function validateShadowsocksUrl(url) {
message: "Invalid port number. Must be between 1 and 65535"
};
}
} catch (e) {
} catch (_e) {
return { valid: false, message: "Invalid Shadowsocks URL: parsing failed" };
}
return { valid: true, message: "Valid" };
@@ -255,7 +256,7 @@ function validateVlessUrl(url) {
};
}
}
} catch (e) {
} catch (_e) {
return { valid: false, message: "Invalid VLESS URL: parsing failed" };
}
return { valid: true, message: "Valid" };
@@ -293,7 +294,7 @@ function validateTrojanUrl(url) {
message: "Invalid Trojan URL: must contain username, hostname and port"
};
}
} catch (e) {
} catch (_e) {
return { valid: false, message: "Invalid Trojan URL: parsing failed" };
}
return { valid: true, message: "Valid" };
@@ -366,6 +367,22 @@ function injectGlobalStyles() {
);
}
// src/helpers/withTimeout.ts
async function withTimeout(promise, timeoutMs, operationName, timeoutMessage = "Operation timed out") {
let timeoutId;
const start = performance.now();
const timeoutPromise = new Promise((_, reject) => {
timeoutId = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
});
try {
return await Promise.race([promise, timeoutPromise]);
} finally {
clearTimeout(timeoutId);
const elapsed = performance.now() - start;
console.log(`[${operationName}] Execution time: ${elapsed.toFixed(2)} ms`);
}
}
// src/constants.ts
var STATUS_COLORS = {
SUCCESS: "#4caf50",
@@ -475,6 +492,53 @@ var COMMAND_SCHEDULING = {
P10_PRIORITY: 1900
// Lowest priority
};
// src/helpers/executeShellCommand.ts
async function executeShellCommand({
command,
args,
timeout = COMMAND_TIMEOUT
}) {
try {
return withTimeout(
fs.exec(command, args),
timeout,
[command, ...args].join(" ")
);
} catch (err) {
const error = err;
return { stdout: "", stderr: error?.message, code: 0 };
}
}
// src/helpers/copyToClipboard.ts
function copyToClipboard(text) {
const textarea = document.createElement("textarea");
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand("copy");
return {
success: true,
message: "Copied!"
};
} catch (err) {
const error = err;
return {
success: false,
message: `Failed to copy: ${error.message}`
};
} finally {
document.body.removeChild(textarea);
}
}
// src/helpers/maskIP.ts
function maskIP(ip = "") {
const ipv4Regex = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
return ip.replace(ipv4Regex, (_match, _p1, _p2, _p3, p4) => `XX.XX.XX.${p4}`);
}
return baseclass.extend({
ALLOWED_WITH_RUSSIA_INSIDE,
BOOTSTRAP_DNS_SERVER_OPTIONS,
@@ -494,8 +558,11 @@ return baseclass.extend({
STATUS_COLORS,
UPDATE_INTERVAL_OPTIONS,
bulkValidate,
copyToClipboard,
executeShellCommand,
getBaseUrl,
injectGlobalStyles,
maskIP,
parseValueList,
validateDNS,
validateDomain,
@@ -507,5 +574,6 @@ return baseclass.extend({
validateSubnet,
validateTrojanUrl,
validateUrl,
validateVlessUrl
validateVlessUrl,
withTimeout
});