feat: update kpxcenv.ts
This commit is contained in:
@@ -6,7 +6,11 @@
|
||||
// - https://docs.deno.com/api/deno/~/Deno.CommandOptions
|
||||
// - https://github.com/aliyun/aliyun-cli
|
||||
|
||||
import {compareVersion, isEnvOn,} from "https://hatter.ink/script/fetch/library/deno-commons-mod.ts";
|
||||
import {
|
||||
compareVersion,
|
||||
isEnvOn,
|
||||
log,
|
||||
} from "https://hatter.ink/script/fetch/library/deno-commons-mod.ts?202501191623";
|
||||
|
||||
const args = Deno.args;
|
||||
if (args.length == 0) {
|
||||
@@ -32,11 +36,11 @@ const xdrRuntimeDir = Deno.env.get("XDG_RUNTIME_DIR");
|
||||
if (xdrRuntimeDir == null) {
|
||||
const tmpdir = Deno.env.get("TMPDIR");
|
||||
if (tmpdir == null) {
|
||||
console.error("[ERROR] Environment XDG_RUNTIME_DIR is not set.");
|
||||
log.error("Environment XDG_RUNTIME_DIR is not set.");
|
||||
Deno.exit(1);
|
||||
}
|
||||
if (isDebug) {
|
||||
console.debug("[DEBUG] Set env XDG_RUNTIME_DIR=" + tmpdir);
|
||||
log.debug("Set env XDG_RUNTIME_DIR=" + tmpdir);
|
||||
}
|
||||
Deno.env.set("XDG_RUNTIME_DIR", tmpdir);
|
||||
}
|
||||
@@ -44,7 +48,7 @@ const shellCommand = Deno.env.get("KPXC_SHELL") || "bash";
|
||||
const region = Deno.env.get("KPXC_REGION") || "cn-hangzhou";
|
||||
|
||||
if (compareVersion(Deno.version.deno, "1.18.0") < 0) {
|
||||
console.error("[ERROR] Require deno version >= 1.18.0 .");
|
||||
log.error("Require deno version >= 1.18.0 .");
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
@@ -61,8 +65,8 @@ async function commandExists(cmd: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
if (!await commandExists(KEEPASSXC_PROXY_COMMAND)) {
|
||||
console.error(
|
||||
"[ERROR] Command kpxcpc is not installed, please install from: https://github.com/nwwdles/kpxcpc",
|
||||
log.error(
|
||||
"Command kpxcpc is not installed, please install from: https://github.com/nwwdles/kpxcpc",
|
||||
);
|
||||
Deno.exit(1);
|
||||
}
|
||||
@@ -86,14 +90,14 @@ const kpxcpcCmdStdoutString = new TextDecoder().decode(kpxcpcCmdStdout);
|
||||
const kpxcpcCmdJsonObjects = JSON.parse(kpxcpcCmdStdoutString);
|
||||
|
||||
if (kpxcpcCmdJsonObjects.length == 0) {
|
||||
console.error(
|
||||
"[ERROR] Should not happen, since KeepassXC return JSON array is empty.",
|
||||
log.error(
|
||||
"Should not happen, since KeepassXC return JSON array is empty.",
|
||||
);
|
||||
Deno.exit(1);
|
||||
}
|
||||
if (kpxcpcCmdJsonObjects.length > 1) {
|
||||
console.warn(
|
||||
"[WARN] Get more than one vaule from KeepassXC, default use the first.",
|
||||
log.warn(
|
||||
"Get more than one vaule from KeepassXC, default use the first.",
|
||||
);
|
||||
}
|
||||
const kpxcpcCmdJsonObject = kpxcpcCmdJsonObjects[0];
|
||||
@@ -103,7 +107,7 @@ const accessKeyId = kpxcpcCmdJsonObject.login;
|
||||
const accessKeySecret = kpxcpcCmdJsonObject.password;
|
||||
|
||||
if (isDebug) {
|
||||
console.debug("[DEBUG] Found object: ", kpxcpcCmdJsonObject);
|
||||
log.debug("Found object: ", kpxcpcCmdJsonObject);
|
||||
}
|
||||
|
||||
const command = new Deno.Command(shellCommand, {
|
||||
|
||||
Reference in New Issue
Block a user