anywork-library-plugin 0.0.0-stage → 0.2.0

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/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # anywork-library-plugin
2
+
3
+ 资料库是单独的 DSH Web 插件,不并进门户插件。侧栏「资料库」,槽位 id 是 `ziliaoku`。
4
+
5
+ 打开后是一块黑板:把文件拖进去,或写一句回车。文件和句子写在这个工作台自己的目录 `~/.dsh/anywork-library-plugin`(设置了 `DSH_HOME` 就写在那里)。不调用门户的 `/portal/api/drive` 或 `/portal/api/kb`。
6
+
7
+ ## 安装和卸下
8
+
9
+ ```sh
10
+ npm pack anywork-library-plugin --registry https://registry.npmjs.org
11
+ dsh plugin --profile web add ./anywork-library-plugin-0.2.0.tgz
12
+ ```
13
+
14
+ `--profile` 写在子命令前面。`add` 会把本包写进该 profile 的 `dsh.profile.bundles`。浏览器入口是导出的 `./client`(`dsh.client.platform` 为 `web`,并依赖 `@deepseek-ai/dsh-client-ui-slots` 和 `@deepseek-ai/dsh-client-ui-sidebar`)。
15
+
16
+ 卸下:
17
+
18
+ ```sh
19
+ dsh plugin --profile web remove anywork-library-plugin
20
+ ```
21
+
22
+ 装上或卸下之后重启那个实例。`file:` 或 tgz 装进去的是副本,改源码不会自动更新。
23
+
24
+ ## 开发
25
+
26
+ ```sh
27
+ npm test
28
+ ```
29
+
30
+ 改 `lib/api.js` 或 `lib/panel.js` 之后执行 `npm run assemble`,再提交生成的 `lib/client.js`。
@@ -0,0 +1,7 @@
1
+ # 资料库:向 Web profile 插入侧栏面板(客户端插件,不改 dsh 源码)。
2
+ # 行 id 用 ziliaoku,避开工作台 desk-panel 自带的侧栏 id desk-hub。
3
+ # 安装:dsh plugin --profile web add ./anywork-library-plugin-0.1.0.tgz
4
+ # `--profile` 写在子命令前面。
5
+ - insert:
6
+ - id: ziliaoku
7
+ name: 'anywork-library-plugin'
package/icon.svg ADDED
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round">
2
+ <path d="M3.5 7.5A1.5 1.5 0 0 1 5 6h4l2 2h8a1.5 1.5 0 0 1 1.5 1.5v8A1.5 1.5 0 0 1 19 19H5a1.5 1.5 0 0 1-1.5-1.5v-10z"/>
3
+ </svg>
package/lib/api.js ADDED
@@ -0,0 +1,111 @@
1
+ // Client for the library shelf. Files and notes stay on this plugin.
2
+
3
+ export const MAX_UPLOAD = 50 * 1024 * 1024;
4
+
5
+ export function canDeleteNote(role) {
6
+ return role === "admin";
7
+ }
8
+
9
+ export function portalErrorText(err) {
10
+ var msg = err && err.message ? String(err.message) : String(err || "");
11
+ var status = err && err.status;
12
+ if (status === 404) return "资料库还没挂到这个工作台。装上插件后重启一次再打开。";
13
+ if (status === 401 || /login required/i.test(msg)) {
14
+ return "读不到资料库。请先登录这个工作台再试。";
15
+ }
16
+ return msg || "读取失败";
17
+ }
18
+
19
+ function readBody(response) {
20
+ return response.text().then(function (text) {
21
+ var data = null;
22
+ if (text) {
23
+ try { data = JSON.parse(text); } catch (e) { data = null; }
24
+ }
25
+ if (!response.ok) {
26
+ var err = new Error((data && data.error) || text || ("HTTP " + response.status));
27
+ err.status = response.status;
28
+ throw err;
29
+ }
30
+ return data == null ? {} : data;
31
+ });
32
+ }
33
+
34
+ export function createPortalApi(getFetch) {
35
+ function doFetch(url, options) {
36
+ var fetchImpl = typeof getFetch === "function" ? getFetch() : getFetch;
37
+ if (typeof fetchImpl !== "function") {
38
+ var err = new Error("fetch 不可用");
39
+ err.status = 0;
40
+ return Promise.reject(err);
41
+ }
42
+ var opts = options || {};
43
+ opts.credentials = opts.credentials || "same-origin";
44
+ return Promise.resolve(fetchImpl(url, opts)).then(readBody);
45
+ }
46
+
47
+ return {
48
+ listDrive: function (path) {
49
+ return doFetch("/plugins/anywork-library-plugin/drive/list?path=" + encodeURIComponent(path || ""), {
50
+ headers: { accept: "application/json" },
51
+ });
52
+ },
53
+ upload: function (path, file) {
54
+ return doFetch(
55
+ "/plugins/anywork-library-plugin/drive/upload?path=" + encodeURIComponent(path || "") + "&name=" + encodeURIComponent(file.name),
56
+ { method: "POST", body: file, headers: { accept: "application/json" } }
57
+ );
58
+ },
59
+ mkdir: function (path, name) {
60
+ return doFetch("/plugins/anywork-library-plugin/drive/mkdir", {
61
+ method: "POST",
62
+ headers: { "content-type": "application/json", accept: "application/json" },
63
+ body: JSON.stringify({ path: path || "", name: name }),
64
+ });
65
+ },
66
+ rm: function (path) {
67
+ return doFetch("/plugins/anywork-library-plugin/drive/rm", {
68
+ method: "POST",
69
+ headers: { "content-type": "application/json", accept: "application/json" },
70
+ body: JSON.stringify({ path: path }),
71
+ });
72
+ },
73
+ mv: function (from, to) {
74
+ return doFetch("/plugins/anywork-library-plugin/drive/mv", {
75
+ method: "POST",
76
+ headers: { "content-type": "application/json", accept: "application/json" },
77
+ body: JSON.stringify({ from: from, to: to || "" }),
78
+ });
79
+ },
80
+ downloadUrl: function (path) {
81
+ return "/plugins/anywork-library-plugin/drive/download?path=" + encodeURIComponent(path);
82
+ },
83
+ listNotes: function () {
84
+ return doFetch("/plugins/anywork-library-plugin/kb/list", { headers: { accept: "application/json" } });
85
+ },
86
+ searchNotes: function (q) {
87
+ return doFetch("/plugins/anywork-library-plugin/kb/search?q=" + encodeURIComponent(q), { headers: { accept: "application/json" } });
88
+ },
89
+ readNote: function (name) {
90
+ return doFetch("/plugins/anywork-library-plugin/kb/note?name=" + encodeURIComponent(name), { headers: { accept: "application/json" } });
91
+ },
92
+ saveNote: function (input, lang) {
93
+ return doFetch("/plugins/anywork-library-plugin/kb/save?lang=" + encodeURIComponent(lang || "zh"), {
94
+ method: "POST",
95
+ headers: { "content-type": "application/json", accept: "application/json" },
96
+ body: JSON.stringify({
97
+ title: input.title || "",
98
+ tags: input.tags || "",
99
+ content: input.content || "",
100
+ }),
101
+ });
102
+ },
103
+ removeNote: function (name, lang) {
104
+ return doFetch("/plugins/anywork-library-plugin/kb/rm?lang=" + encodeURIComponent(lang || "zh"), {
105
+ method: "POST",
106
+ headers: { "content-type": "application/json", accept: "application/json" },
107
+ body: JSON.stringify({ name: name }),
108
+ });
109
+ },
110
+ };
111
+ }