Task: Add config access type with free by default and updated the prgram cli for http tunnel client

This commit is contained in:
Sambo Chea 2022-06-26 00:32:09 +07:00
parent 4e6158df7e
commit e876cc7d72

View File

@ -14,6 +14,7 @@ const sdk = require("./sdk");
const PROFILE_DEFAULT = "default";
const PROFILE_PATH = ".hlt";
const SERVER_DEFAULT_URL = "https://lt.ctdn.net";
const TOKEN_FREE = "FREE";
// create socket instance
let socket = null;
@ -177,6 +178,7 @@ program
"setting token (default generate FREE access token)",
""
)
.option("-a --access <string>", "setting token access type", TOKEN_FREE)
.option("-c --client <string>", "setting client (auto generate uuid)", "")
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
.action(async (options) => {
@ -203,6 +205,10 @@ program
config.token = options.token;
}
if (options.access) {
config.access = options.access;
}
if (options.client) {
config.clientId = options.clientId;
}
@ -215,6 +221,10 @@ program
config.clientId = generateUUID();
}
if (!config.access) {
config.access = TOKEN_FREE;
}
if (!config.token) {
console.log("Generating token...");
await sdk
@ -247,7 +257,7 @@ program
}
return port;
})
.option("-a, --access <string>", "setting access type (FREE)", "FREE")
.option("-a, --access <string>", "setting access type (FREE)", TOKEN_FREE)
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
.option("-h, --host <string>", "local host value", "localhost")
.option("-o, --origin <string>", "change request origin")
@ -350,10 +360,10 @@ program
} else if (type === "apiKey" || type === "key") {
config.apiKey = value;
} else if (type === "access") {
config.access = (value && value.toUpperCase().trim()) || "FREE";
config.access = (value && value.toUpperCase().trim()) || TOKEN_FREE;
// FREE
if (config.access === "FREE") {
if (config.access === TOKEN_FREE) {
await sdk
.getTokenFree(config.server)
.then((resp) => {