koishi-plugin-terminal 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +15 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -37,6 +37,8 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_koishi = require("koishi");
|
|
39
39
|
var pty = __toESM(require("node-pty"));
|
|
40
|
+
var import_node_fs = require("node:fs");
|
|
41
|
+
var import_node_path = require("node:path");
|
|
40
42
|
var import_node_timers = require("node:timers");
|
|
41
43
|
var name = "terminal";
|
|
42
44
|
var Config = import_koishi.Schema.object({
|
|
@@ -75,6 +77,17 @@ function getKey(session) {
|
|
|
75
77
|
return `${session.platform}:${session.userId}`;
|
|
76
78
|
}
|
|
77
79
|
__name(getKey, "getKey");
|
|
80
|
+
function fixNodePtyHelper() {
|
|
81
|
+
if (process.platform !== "darwin") return;
|
|
82
|
+
try {
|
|
83
|
+
const root = (0, import_node_path.dirname)(require.resolve("node-pty/package.json"));
|
|
84
|
+
const helper = (0, import_node_path.join)(root, "prebuilds", `darwin-${process.arch}`, "spawn-helper");
|
|
85
|
+
const mode = (0, import_node_fs.statSync)(helper).mode;
|
|
86
|
+
if (!(mode & 73)) (0, import_node_fs.chmodSync)(helper, mode | 493);
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
__name(fixNodePtyHelper, "fixNodePtyHelper");
|
|
78
91
|
function isInteractiveCommand(command) {
|
|
79
92
|
const trimmed = command.trim();
|
|
80
93
|
if (!trimmed) return false;
|
|
@@ -83,7 +96,7 @@ function isInteractiveCommand(command) {
|
|
|
83
96
|
if (/^(less|more|man)$/.test(name2)) return true;
|
|
84
97
|
if (/^(top|htop|btop|watch)$/.test(name2)) return true;
|
|
85
98
|
if (/^(tmux|screen)$/.test(name2)) return true;
|
|
86
|
-
if (/^(
|
|
99
|
+
if (/^(sftp|ftp|telnet)$/.test(name2)) return true;
|
|
87
100
|
if (/^(mysql|psql|sqlite3|redis-cli|mongosh)$/.test(name2)) return true;
|
|
88
101
|
if (/^(node|python|python3|ipython|ruby|irb|php|lua|R)$/.test(name2) && !args.length) return true;
|
|
89
102
|
if (name2 === "tail" && args.includes("-f")) return true;
|
|
@@ -94,6 +107,7 @@ function isInteractiveCommand(command) {
|
|
|
94
107
|
__name(isInteractiveCommand, "isInteractiveCommand");
|
|
95
108
|
var map = /* @__PURE__ */ new Map();
|
|
96
109
|
function apply(ctx, config) {
|
|
110
|
+
fixNodePtyHelper();
|
|
97
111
|
const allowedUsers = config.admin;
|
|
98
112
|
function refreshTimeout(shellSession, key, session) {
|
|
99
113
|
if (!config.timeout) return;
|