summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/index.js b/index.js
index b02aedb..46fd1fc 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
import lodash from "lodash";
import { parse } from "flags/mod.ts";
+import { dirname, fromFileUrl, SEP } from "path/mod.ts";
import { networkInterfaces } from "node:os";
const REFERER = "https://w.seu.edu.cn/";
@@ -7,13 +8,17 @@ const EPORTAL_API = "https://w.seu.edu.cn:802/eportal";
const headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0",
};
+const PROG_PATH = Deno.args.includes("--is_compiled_binary")
+ ? Deno.execPath()
+ : fromFileUrl(Deno.mainModule);
+const CONFIG_FILE = `${dirname(PROG_PATH)}${SEP}credentials.json`;
(async () => {
const flags = parse(Deno.args, {
boolean: ["login", "logout"],
string: ["config"],
- default: { login: true, config: "./credentials.json" }
+ default: { login: true, config: CONFIG_FILE }
});
try {
@@ -37,7 +42,7 @@ const headers = {
if (err instanceof SyntaxError) {
exitWithError("Parse json failed!");
} else if (err instanceof Deno.errors.NotFound) {
- exitWithError("credentials.json not found!")
+ exitWithError(`${CONFIG_FILE} not found!`)
}
else {
console.error(`[ERROR]: ${err.toString()}`);