dsh-message-gateway 0.1.15 → 0.1.16
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.en.md +4 -0
- package/README.es.md +4 -0
- package/README.md +4 -0
- package/lib/client.js +18 -0
- package/lib/client.js.map +2 -2
- package/lib/index.js +248 -24
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/host/gateway-store.ts
|
|
12
|
+
var gateway_store_exports = {};
|
|
13
|
+
__export(gateway_store_exports, {
|
|
14
|
+
loadStore: () => loadStore,
|
|
15
|
+
saveStore: () => saveStore
|
|
16
|
+
});
|
|
17
|
+
import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
async function loadStore() {
|
|
21
|
+
try {
|
|
22
|
+
const text = await readFile(FILE, "utf8");
|
|
23
|
+
const parsed = JSON.parse(text);
|
|
24
|
+
return {
|
|
25
|
+
platforms: parsed.platforms ?? {},
|
|
26
|
+
statuses: parsed.statuses ?? {}
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return { platforms: {}, statuses: {} };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function saveStore(data) {
|
|
33
|
+
await mkdir(join(homedir(), ".dsh"), { recursive: true });
|
|
34
|
+
const tmp = `${FILE}.tmp`;
|
|
35
|
+
await writeFile(tmp, JSON.stringify(data, null, 2), { mode: 384 });
|
|
36
|
+
await chmod(tmp, 384);
|
|
37
|
+
await rename(tmp, FILE);
|
|
38
|
+
}
|
|
39
|
+
var FILE;
|
|
40
|
+
var init_gateway_store = __esm({
|
|
41
|
+
"src/host/gateway-store.ts"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
FILE = join(homedir(), ".dsh", "gateway.json");
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
1
47
|
// node_modules/@deepseek-ai/dsh-tools/lib/index.js
|
|
2
48
|
import { Service } from "@deepseek-ai/cordis";
|
|
3
49
|
import z from "@deepseek-ai/schemastery";
|
|
@@ -5057,6 +5103,86 @@ ${content}` : content;
|
|
|
5057
5103
|
const sent = await this.email.send(target, subject, content);
|
|
5058
5104
|
return sent ? { ok: true, detail: "sent" } : { ok: false, detail: "email send failed" };
|
|
5059
5105
|
}
|
|
5106
|
+
case "dingtalk": {
|
|
5107
|
+
const rawUrl = target.startsWith("http") ? target : `https://oapi.dingtalk.com/robot/send?access_token=${encodeURIComponent(target)}`;
|
|
5108
|
+
let targetUrl = rawUrl;
|
|
5109
|
+
const { loadStore: loadStore2 } = await Promise.resolve().then(() => (init_gateway_store(), gateway_store_exports));
|
|
5110
|
+
const store = await loadStore2();
|
|
5111
|
+
const secret = store.platforms.dingtalk?.secret;
|
|
5112
|
+
if (secret) {
|
|
5113
|
+
const { createHmac: createHmac2 } = await import("node:crypto");
|
|
5114
|
+
const timestamp = Date.now();
|
|
5115
|
+
const stringToSign = `${timestamp}
|
|
5116
|
+
${secret}`;
|
|
5117
|
+
const sign2 = encodeURIComponent(createHmac2("sha256", secret).update(stringToSign, "utf8").digest("base64"));
|
|
5118
|
+
targetUrl += `${rawUrl.includes("?") ? "&" : "?"}timestamp=${timestamp}&sign=${sign2}`;
|
|
5119
|
+
}
|
|
5120
|
+
const resp = await fetch(targetUrl, {
|
|
5121
|
+
method: "POST",
|
|
5122
|
+
headers: { "content-type": "application/json" },
|
|
5123
|
+
body: JSON.stringify({
|
|
5124
|
+
msgtype: "markdown",
|
|
5125
|
+
markdown: { title: opts.title ?? "DSH \u901A\u77E5", text }
|
|
5126
|
+
})
|
|
5127
|
+
});
|
|
5128
|
+
const r = await resp.json().catch(() => ({}));
|
|
5129
|
+
return r.errcode === 0 ? { ok: true, detail: "sent" } : { ok: false, detail: r.errmsg ?? "dingtalk send failed" };
|
|
5130
|
+
}
|
|
5131
|
+
case "feishu": {
|
|
5132
|
+
const rawUrl = target.startsWith("http") ? target : `https://open.feishu.cn/open-apis/bot/v2/hook/${encodeURIComponent(target)}`;
|
|
5133
|
+
const payload = {
|
|
5134
|
+
msg_type: "text",
|
|
5135
|
+
content: { text }
|
|
5136
|
+
};
|
|
5137
|
+
const { loadStore: loadStore2 } = await Promise.resolve().then(() => (init_gateway_store(), gateway_store_exports));
|
|
5138
|
+
const store = await loadStore2();
|
|
5139
|
+
const secret = store.platforms.feishu?.secret;
|
|
5140
|
+
if (secret) {
|
|
5141
|
+
const { createHmac: createHmac2 } = await import("node:crypto");
|
|
5142
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
5143
|
+
const stringToSign = `${timestamp}
|
|
5144
|
+
${secret}`;
|
|
5145
|
+
const sign2 = createHmac2("sha256", stringToSign).digest("base64");
|
|
5146
|
+
payload.timestamp = String(timestamp);
|
|
5147
|
+
payload.sign = sign2;
|
|
5148
|
+
}
|
|
5149
|
+
const resp = await fetch(rawUrl, {
|
|
5150
|
+
method: "POST",
|
|
5151
|
+
headers: { "content-type": "application/json" },
|
|
5152
|
+
body: JSON.stringify(payload)
|
|
5153
|
+
});
|
|
5154
|
+
const r = await resp.json().catch(() => ({}));
|
|
5155
|
+
return r.code === 0 || r.StatusCode === 0 ? { ok: true, detail: "sent" } : { ok: false, detail: r.msg ?? "feishu send failed" };
|
|
5156
|
+
}
|
|
5157
|
+
case "bark": {
|
|
5158
|
+
const { loadStore: loadStore2 } = await Promise.resolve().then(() => (init_gateway_store(), gateway_store_exports));
|
|
5159
|
+
const store = await loadStore2();
|
|
5160
|
+
const server = (store.platforms.bark?.serverUrl || "https://api.day.app").replace(/\/+$/, "");
|
|
5161
|
+
const deviceKey = target || store.platforms.bark?.deviceKey;
|
|
5162
|
+
if (!deviceKey) return { ok: false, detail: "missing bark device key" };
|
|
5163
|
+
const url = `${server}/${encodeURIComponent(deviceKey)}/`;
|
|
5164
|
+
const resp = await fetch(url, {
|
|
5165
|
+
method: "POST",
|
|
5166
|
+
headers: { "content-type": "application/json" },
|
|
5167
|
+
body: JSON.stringify({ title: opts.title ?? "DSH \u901A\u77E5", body: content, group: "DSH" })
|
|
5168
|
+
});
|
|
5169
|
+
const r = await resp.json().catch(() => ({}));
|
|
5170
|
+
return r.code === 200 || resp.status === 200 ? { ok: true, detail: "sent" } : { ok: false, detail: r.message ?? "bark send failed" };
|
|
5171
|
+
}
|
|
5172
|
+
case "serverchan": {
|
|
5173
|
+
const { loadStore: loadStore2 } = await Promise.resolve().then(() => (init_gateway_store(), gateway_store_exports));
|
|
5174
|
+
const store = await loadStore2();
|
|
5175
|
+
const sendKey = target || store.platforms.serverchan?.sendKey;
|
|
5176
|
+
if (!sendKey) return { ok: false, detail: "missing serverchan sendkey" };
|
|
5177
|
+
const url = `https://sctapi.ftqq.com/${encodeURIComponent(sendKey)}.send`;
|
|
5178
|
+
const resp = await fetch(url, {
|
|
5179
|
+
method: "POST",
|
|
5180
|
+
headers: { "content-type": "application/json" },
|
|
5181
|
+
body: JSON.stringify({ title: (opts.title ?? "DSH \u901A\u77E5").slice(0, 32), desp: content })
|
|
5182
|
+
});
|
|
5183
|
+
const r = await resp.json().catch(() => ({}));
|
|
5184
|
+
return r.code === 0 ? { ok: true, detail: "sent" } : { ok: false, detail: r.message ?? "serverchan send failed" };
|
|
5185
|
+
}
|
|
5060
5186
|
case "qq":
|
|
5061
5187
|
return { ok: false, detail: "QQ \u5E73\u53F0\u81EA 2025-04-21 \u8D77\u4E0D\u652F\u6301\u4E3B\u52A8\u63A8\u9001\uFF08\u4EC5\u88AB\u52A8\u56DE\u590D\uFF09\uFF0C\u65E0\u6CD5\u53D1\u9001\u4E3B\u52A8\u6D88\u606F" };
|
|
5062
5188
|
default:
|
|
@@ -5279,32 +5405,11 @@ function nowInShanghai() {
|
|
|
5279
5405
|
}).format(/* @__PURE__ */ new Date());
|
|
5280
5406
|
}
|
|
5281
5407
|
|
|
5282
|
-
// src/
|
|
5283
|
-
|
|
5284
|
-
import { homedir } from "node:os";
|
|
5285
|
-
import { join } from "node:path";
|
|
5286
|
-
var FILE = join(homedir(), ".dsh", "gateway.json");
|
|
5287
|
-
async function loadStore() {
|
|
5288
|
-
try {
|
|
5289
|
-
const text = await readFile(FILE, "utf8");
|
|
5290
|
-
const parsed = JSON.parse(text);
|
|
5291
|
-
return {
|
|
5292
|
-
platforms: parsed.platforms ?? {},
|
|
5293
|
-
statuses: parsed.statuses ?? {}
|
|
5294
|
-
};
|
|
5295
|
-
} catch {
|
|
5296
|
-
return { platforms: {}, statuses: {} };
|
|
5297
|
-
}
|
|
5298
|
-
}
|
|
5299
|
-
async function saveStore(data) {
|
|
5300
|
-
await mkdir(join(homedir(), ".dsh"), { recursive: true });
|
|
5301
|
-
const tmp = `${FILE}.tmp`;
|
|
5302
|
-
await writeFile(tmp, JSON.stringify(data, null, 2), { mode: 384 });
|
|
5303
|
-
await chmod(tmp, 384);
|
|
5304
|
-
await rename(tmp, FILE);
|
|
5305
|
-
}
|
|
5408
|
+
// src/index.ts
|
|
5409
|
+
init_gateway_store();
|
|
5306
5410
|
|
|
5307
5411
|
// src/host/routes.ts
|
|
5412
|
+
init_gateway_store();
|
|
5308
5413
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
5309
5414
|
|
|
5310
5415
|
// src/host/platforms.ts
|
|
@@ -5413,6 +5518,49 @@ var PLATFORMS = [
|
|
|
5413
5518
|
{ key: "smtpPass", labelKey: "field.smtpPass", placeholderKey: "field.secret.ph", kind: "secret" }
|
|
5414
5519
|
]
|
|
5415
5520
|
},
|
|
5521
|
+
{
|
|
5522
|
+
id: "dingtalk",
|
|
5523
|
+
nameKey: "platform.dingtalk",
|
|
5524
|
+
icon: "\u{1F4CC}",
|
|
5525
|
+
testable: true,
|
|
5526
|
+
hintKey: "platform.dingtalk.hint",
|
|
5527
|
+
fields: [
|
|
5528
|
+
{ key: "webhookUrl", labelKey: "field.webhookUrl", placeholderKey: "field.dingtalkWebhook.ph", kind: "text" },
|
|
5529
|
+
{ key: "secret", labelKey: "field.dingtalkSecret", placeholderKey: "field.secret.ph", kind: "secret" }
|
|
5530
|
+
]
|
|
5531
|
+
},
|
|
5532
|
+
{
|
|
5533
|
+
id: "feishu",
|
|
5534
|
+
nameKey: "platform.feishu",
|
|
5535
|
+
icon: "\u{1F54A}\uFE0F",
|
|
5536
|
+
testable: true,
|
|
5537
|
+
hintKey: "platform.feishu.hint",
|
|
5538
|
+
fields: [
|
|
5539
|
+
{ key: "webhookUrl", labelKey: "field.webhookUrl", placeholderKey: "field.feishuWebhook.ph", kind: "text" },
|
|
5540
|
+
{ key: "secret", labelKey: "field.feishuSecret", placeholderKey: "field.secret.ph", kind: "secret" }
|
|
5541
|
+
]
|
|
5542
|
+
},
|
|
5543
|
+
{
|
|
5544
|
+
id: "bark",
|
|
5545
|
+
nameKey: "platform.bark",
|
|
5546
|
+
icon: "\u{1F514}",
|
|
5547
|
+
testable: true,
|
|
5548
|
+
hintKey: "platform.bark.hint",
|
|
5549
|
+
fields: [
|
|
5550
|
+
{ key: "serverUrl", labelKey: "field.barkServer", placeholderKey: "field.barkServer.ph", kind: "text" },
|
|
5551
|
+
{ key: "deviceKey", labelKey: "field.barkKey", placeholderKey: "field.barkKey.ph", kind: "secret" }
|
|
5552
|
+
]
|
|
5553
|
+
},
|
|
5554
|
+
{
|
|
5555
|
+
id: "serverchan",
|
|
5556
|
+
nameKey: "platform.serverchan",
|
|
5557
|
+
icon: "\u{1F680}",
|
|
5558
|
+
testable: true,
|
|
5559
|
+
hintKey: "platform.serverchan.hint",
|
|
5560
|
+
fields: [
|
|
5561
|
+
{ key: "sendKey", labelKey: "field.serverchanKey", placeholderKey: "field.serverchanKey.ph", kind: "secret" }
|
|
5562
|
+
]
|
|
5563
|
+
},
|
|
5416
5564
|
{
|
|
5417
5565
|
id: "webhooks",
|
|
5418
5566
|
nameKey: "platform.webhooks",
|
|
@@ -5538,6 +5686,82 @@ async function testPlatform(id, cred) {
|
|
|
5538
5686
|
}
|
|
5539
5687
|
return { ok: false, detail: banner === "" ? `\u65E0\u6CD5\u8FDE\u63A5 ${cred.imapHost}:${port}` : banner };
|
|
5540
5688
|
}
|
|
5689
|
+
case "dingtalk": {
|
|
5690
|
+
const rawUrl = cred.webhookUrl ?? "";
|
|
5691
|
+
if (!rawUrl.startsWith("http")) return { ok: false, detail: "\u65E0\u6548\u7684 Webhook URL" };
|
|
5692
|
+
let targetUrl = rawUrl;
|
|
5693
|
+
if (cred.secret) {
|
|
5694
|
+
const { createHmac: createHmac2 } = await import("node:crypto");
|
|
5695
|
+
const timestamp = Date.now();
|
|
5696
|
+
const stringToSign = `${timestamp}
|
|
5697
|
+
${cred.secret}`;
|
|
5698
|
+
const sign2 = encodeURIComponent(createHmac2("sha256", cred.secret).update(stringToSign, "utf8").digest("base64"));
|
|
5699
|
+
targetUrl += `${rawUrl.includes("?") ? "&" : "?"}timestamp=${timestamp}&sign=${sign2}`;
|
|
5700
|
+
}
|
|
5701
|
+
const { status, body } = await httpJson(targetUrl, {
|
|
5702
|
+
method: "POST",
|
|
5703
|
+
headers: { "content-type": "application/json" },
|
|
5704
|
+
body: JSON.stringify({
|
|
5705
|
+
msgtype: "markdown",
|
|
5706
|
+
markdown: { title: "DSH \u8FDE\u63A5\u6D4B\u8BD5", text: "### \u{1F50C} DSH Message Gateway\n\u9489\u9489\u81EA\u5B9A\u4E49\u673A\u5668\u4EBA\u8FDE\u63A5\u6D4B\u8BD5\u6210\u529F\uFF01" }
|
|
5707
|
+
})
|
|
5708
|
+
});
|
|
5709
|
+
const r = body;
|
|
5710
|
+
if (r.errcode === 0) return { ok: true, detail: "\u9489\u9489\u673A\u5668\u4EBA\u8FDE\u63A5\u6210\u529F" };
|
|
5711
|
+
return { ok: false, detail: r.errmsg ?? `HTTP ${status}` };
|
|
5712
|
+
}
|
|
5713
|
+
case "feishu": {
|
|
5714
|
+
const rawUrl = cred.webhookUrl ?? "";
|
|
5715
|
+
if (!rawUrl.startsWith("http")) return { ok: false, detail: "\u65E0\u6548\u7684 Webhook URL" };
|
|
5716
|
+
const payload = {
|
|
5717
|
+
msg_type: "text",
|
|
5718
|
+
content: { text: "\u{1F50C} [DSH Message Gateway] \u98DE\u4E66\u81EA\u5B9A\u4E49\u673A\u5668\u4EBA\u8FDE\u63A5\u6D4B\u8BD5\u6210\u529F\uFF01" }
|
|
5719
|
+
};
|
|
5720
|
+
if (cred.secret) {
|
|
5721
|
+
const { createHmac: createHmac2 } = await import("node:crypto");
|
|
5722
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
5723
|
+
const stringToSign = `${timestamp}
|
|
5724
|
+
${cred.secret}`;
|
|
5725
|
+
const sign2 = createHmac2("sha256", stringToSign).digest("base64");
|
|
5726
|
+
payload.timestamp = String(timestamp);
|
|
5727
|
+
payload.sign = sign2;
|
|
5728
|
+
}
|
|
5729
|
+
const { status, body } = await httpJson(rawUrl, {
|
|
5730
|
+
method: "POST",
|
|
5731
|
+
headers: { "content-type": "application/json" },
|
|
5732
|
+
body: JSON.stringify(payload)
|
|
5733
|
+
});
|
|
5734
|
+
const r = body;
|
|
5735
|
+
if (r.code === 0 || r.StatusCode === 0) return { ok: true, detail: "\u98DE\u4E66\u673A\u5668\u4EBA\u8FDE\u63A5\u6210\u529F" };
|
|
5736
|
+
return { ok: false, detail: r.msg ?? `HTTP ${status}` };
|
|
5737
|
+
}
|
|
5738
|
+
case "bark": {
|
|
5739
|
+
const server = (cred.serverUrl || "https://api.day.app").replace(/\/+$/, "");
|
|
5740
|
+
const key = cred.deviceKey ?? "";
|
|
5741
|
+
if (!key) return { ok: false, detail: "\u8BF7\u586B\u5199 Device Key" };
|
|
5742
|
+
const url = `${server}/${encodeURIComponent(key)}/`;
|
|
5743
|
+
const { status, body } = await httpJson(url, {
|
|
5744
|
+
method: "POST",
|
|
5745
|
+
headers: { "content-type": "application/json" },
|
|
5746
|
+
body: JSON.stringify({ title: "DSH \u8FDE\u63A5\u6D4B\u8BD5", body: "Bark \u624B\u673A\u63A8\u9001\u901A\u9053\u5DF2\u8FDE\u901A", group: "DSH" })
|
|
5747
|
+
});
|
|
5748
|
+
const r = body;
|
|
5749
|
+
if (r.code === 200 || status === 200) return { ok: true, detail: "Bark \u63A8\u9001\u6D4B\u8BD5\u6210\u529F" };
|
|
5750
|
+
return { ok: false, detail: r.message ?? `HTTP ${status}` };
|
|
5751
|
+
}
|
|
5752
|
+
case "serverchan": {
|
|
5753
|
+
const key = cred.sendKey ?? "";
|
|
5754
|
+
if (!key) return { ok: false, detail: "\u8BF7\u586B\u5199 SendKey" };
|
|
5755
|
+
const url = `https://sctapi.ftqq.com/${encodeURIComponent(key)}.send`;
|
|
5756
|
+
const { status, body } = await httpJson(url, {
|
|
5757
|
+
method: "POST",
|
|
5758
|
+
headers: { "content-type": "application/json" },
|
|
5759
|
+
body: JSON.stringify({ title: "DSH\u8FDE\u63A5\u6D4B\u8BD5", desp: "Server\u9171\u6D88\u606F\u901A\u9053\u6D4B\u8BD5\u6210\u529F" })
|
|
5760
|
+
});
|
|
5761
|
+
const r = body;
|
|
5762
|
+
if (r.code === 0) return { ok: true, detail: "Server\u9171\u63A8\u9001\u6D4B\u8BD5\u6210\u529F" };
|
|
5763
|
+
return { ok: false, detail: r.message ?? `HTTP ${status}` };
|
|
5764
|
+
}
|
|
5541
5765
|
default:
|
|
5542
5766
|
return { ok: true, detail: "configured" };
|
|
5543
5767
|
}
|