@koishi-ce/plugin-explorer 1.0.0 → 1.0.1

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.
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
3
7
 
package/lib/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { Schema } from "@koishi-ce/koishi";
5
5
  import * as anymatchModule from "anymatch";
6
6
  import { detect } from "chardet";
7
7
  import { fileTypeFromBuffer } from "file-type";
8
- import zhCN from "./assets/zh-CN-ZoUUQH0N.yml";
8
+ import zhCN from "./assets/zh-CN-X-yi2Y2F.yml";
9
9
  //#region src/index.ts
10
10
  /**
11
11
  * explorer 插件(服务端):网页文件管理器的 node 侧实现。
package/locales/de-DE.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
3
7
 
package/locales/en-US.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: Files or directories to ignore. Supports [Glob Patterns](https://github.com/micromatch/micromatch) syntax.
3
7
 
package/locales/fr-FR.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
3
7
 
package/locales/ja-JP.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
3
7
 
package/locales/ru-RU.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
3
7
 
package/locales/zh-CN.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 资源管理器的根目录,默认为当前工作路径。
2
6
  ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。
3
7
 
package/locales/zh-TW.yml CHANGED
@@ -1,3 +1,7 @@
1
+ # SPDX-License-Identifier: AGPL-3.0-only
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ # Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  root: 資源管理器的根目錄,默認為當前工作路徑。
2
6
  ignored: 要忽略的文件或目錄。支援 [Glob Patterns](https://github.com/micromatch/micromatch) 語法。
3
7
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koishi-ce/plugin-explorer",
3
3
  "description": "File explorer and editor for Koishi",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "type": "module",
6
6
  "main": "lib/index.mjs",
7
7
  "types": "lib/index.d.ts",
@@ -59,15 +59,17 @@
59
59
  }
60
60
  },
61
61
  "peerDependencies": {
62
- "@koishijs/plugin-console": "^5.30.11",
63
- "koishi": "^4.18.11"
62
+ "@koishi-ce/plugin-console": "^1.0.0",
63
+ "@koishi-ce/koishi": "^1.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@koishi-ce/client": "^1.0.0",
67
- "@koishi-ce/plugin-console": "^1.0.0",
68
- "@types/throttle-debounce": "^2.1.0",
69
- "@koishi-ce/koishi": "^1.0.0",
70
- "monaco-editor": "~0.56.0"
66
+ "@koishi-ce/client": "^1.0.3",
67
+ "@koishi-ce/plugin-console": "^1.0.3",
68
+ "@koishi-ce/koishi": "^1.0.4",
69
+ "@vueuse/core": "^14.4.0",
70
+ "monaco-editor": "~0.56.0",
71
+ "vue": "^3.5.12",
72
+ "vue-router": "^5.2.0"
71
73
  },
72
74
  "dependencies": {
73
75
  "@koishi-ce/console": "^1.0.0",
@@ -0,0 +1,148 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ // Copyright (c) 2026-present Koishi-CE contributors.
4
+
5
+ import { afterAll, beforeAll, describe, expect, it } from "bun:test";
6
+ import { existsSync, mkdtempSync, rmSync } from "node:fs";
7
+ import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ import { Console, type Entry } from "@koishi-ce/console";
11
+ import { App, type Plugin } from "@koishi-ce/koishi";
12
+ import explorer, { type Entry as TreeEntry } from "./index.ts";
13
+
14
+ /** 控制台服务桩:仅实现入口登记所需的最小面。 */
15
+ class FakeConsole extends Console {
16
+ protected resolveEntry(_files: Entry.Files, _key: string): string[] {
17
+ return [];
18
+ }
19
+ }
20
+
21
+ /** 在系统临时目录构造文件管理场景(含被忽略的隐藏文件与 node_modules)。 */
22
+ async function createScenario() {
23
+ const root = mkdtempSync(join(tmpdir(), "explorer-test-"));
24
+ await writeFile(join(root, "b.txt"), "hello world", "utf8");
25
+ // PNG 魔数 + IHDR chunk 头(file-type 依此识别 MIME)
26
+ await writeFile(
27
+ join(root, "a.png"),
28
+ Buffer.from([
29
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
30
+ 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
31
+ 0x08, 0x06, 0x00, 0x00, 0x00,
32
+ ]),
33
+ );
34
+ await mkdir(join(root, "sub"));
35
+ await writeFile(join(root, "sub", "c.txt"), "nested", "utf8");
36
+ await mkdir(join(root, "node_modules"));
37
+ await writeFile(join(root, "node_modules", "x.txt"), "ignored");
38
+ await writeFile(join(root, ".hidden"), "ignored");
39
+ // win32 无特权环境下用 junction 目录链接充当符号链接
40
+ await symlink(join(root, "sub"), join(root, "link"), "junction");
41
+ return root;
42
+ }
43
+
44
+ const root = await createScenario();
45
+
46
+ const app = new App();
47
+
48
+ app.plugin(FakeConsole as unknown as Plugin.Constructor<App>);
49
+ app.plugin(explorer, { root });
50
+
51
+ /** 以假客户端身份调用指定 RPC 监听器。 */
52
+ async function call<K extends keyof Console["listeners"]>(
53
+ event: K,
54
+ ...args: unknown[]
55
+ ) {
56
+ const listener = app.console.listeners[event];
57
+ if (!listener) throw new Error(`listener ${String(event)} not found`);
58
+ return listener.callback.call({} as never, ...(args as never[]));
59
+ }
60
+
61
+ const service = () => app.get("console.services.explorer");
62
+
63
+ beforeAll(() => app.start());
64
+
65
+ afterAll(async () => {
66
+ await app.stop();
67
+ rmSync(root, { recursive: true, force: true });
68
+ });
69
+
70
+ describe("explorer 文件管理服务", () => {
71
+ it("文件树遍历:目录优先、按名排序、忽略隐藏与 node_modules", async () => {
72
+ const entries = (await service()?.get()) as TreeEntry[];
73
+ const names = entries.map((entry) => entry.name);
74
+ // 目录排最前,其余按字母序;ignored 项不出现
75
+ expect(names).toEqual(["sub", "a.png", "b.txt", "link"]);
76
+ const sub = entries[0];
77
+ expect(sub?.type).toBe("directory");
78
+ expect(sub?.children?.map((child) => child.name)).toEqual(["c.txt"]);
79
+ // junction 链接识别为符号链接并给出目标
80
+ const link = entries[3];
81
+ expect(link?.type).toBe("symlink");
82
+ expect(link?.target).toContain("sub");
83
+ });
84
+
85
+ it("read 返回文本文件的 base64 与编码探测", async () => {
86
+ const file = (await call("explorer/read", "b.txt")) as {
87
+ base64: string;
88
+ encoding?: string;
89
+ mime?: string;
90
+ };
91
+ expect(Buffer.from(file.base64, "base64").toString("utf8")).toBe(
92
+ "hello world",
93
+ );
94
+ expect(file.encoding).toBeTruthy();
95
+ // 文本文件不携带 mime
96
+ expect(file.mime).toBeUndefined();
97
+ });
98
+
99
+ it("read 返回二进制文件的 MIME 探测", async () => {
100
+ const file = (await call("explorer/read", "a.png")) as {
101
+ base64: string;
102
+ mime?: string;
103
+ };
104
+ expect(file.mime).toBe("image/png");
105
+ });
106
+
107
+ it("write 支持文本与 base64 二进制写入", async () => {
108
+ await call("explorer/write", "sub/new.txt", "新内容");
109
+ expect(await readFile(join(root, "sub", "new.txt"), "utf8")).toBe("新内容");
110
+
111
+ const buffer = Buffer.from([1, 2, 3, 4]);
112
+ await call(
113
+ "explorer/write",
114
+ "sub/new.bin",
115
+ buffer.toString("base64"),
116
+ true,
117
+ );
118
+ expect(await readFile(join(root, "sub", "new.bin"))).toEqual(buffer);
119
+ });
120
+
121
+ it("mkdir / rename / remove 执行实际文件操作", async () => {
122
+ await call("explorer/mkdir", "made");
123
+ expect(existsSync(join(root, "made"))).toBe(true);
124
+
125
+ await call("explorer/rename", "made", "renamed");
126
+ expect(existsSync(join(root, "renamed"))).toBe(true);
127
+
128
+ await call("explorer/remove", "renamed");
129
+ expect(existsSync(join(root, "renamed"))).toBe(false);
130
+ });
131
+
132
+ it("explorer/refresh 与 get 的缓存复用语义", async () => {
133
+ const svc = service();
134
+ // 非强制调用复用进行中的遍历任务(task 字段不更换)
135
+ await svc?.get();
136
+ const before = svc?.task;
137
+ await svc?.get();
138
+ expect(svc?.task).toBe(before);
139
+ // 文件变动后强制刷新得到新树
140
+ await writeFile(join(root, "z.txt"), "tail");
141
+ const fresh = (await svc?.get(true)) as TreeEntry[];
142
+ expect(fresh.map((entry) => entry.name)).toContain("z.txt");
143
+ });
144
+
145
+ it("read 不存在的文件时抛错", async () => {
146
+ expect(call("explorer/read", "not-exist.txt")).rejects.toThrow();
147
+ });
148
+ });
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ // Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  /**
2
6
  * explorer 插件(服务端):网页文件管理器的 node 侧实现。
3
7
  *