dsh-reminder-notify 0.12.0 → 0.12.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.
- package/client.js +32 -5
- package/docs/PUBLISH.md +1 -1
- package/docs/detail.en.md +2 -0
- package/docs/detail.zh.md +2 -0
- package/index.js +13 -0
- package/package.json +1 -1
- package/publish/index.json +2 -2
package/client.js
CHANGED
|
@@ -900,11 +900,38 @@ window.__ModuleLoader__.load({
|
|
|
900
900
|
}
|
|
901
901
|
|
|
902
902
|
function sendDigest() {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
903
|
+
const label = typeof t === 'function' ? t : (key) => key
|
|
904
|
+
setMessage(null)
|
|
905
|
+
setDigestBusy(true)
|
|
906
|
+
Promise.resolve()
|
|
907
|
+
.then(() =>
|
|
908
|
+
fetch(DIGEST_ROUTE, {
|
|
909
|
+
method: 'POST',
|
|
910
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
911
|
+
body: JSON.stringify({ mode: 'send' }),
|
|
912
|
+
}),
|
|
913
|
+
)
|
|
914
|
+
.then((response) => (response && typeof response.json === 'function' ? response.json() : Promise.reject(new Error('HTTP ' + (response ? response.status : '?')))))
|
|
915
|
+
.then((data) => {
|
|
916
|
+
setDigestBusy(false)
|
|
917
|
+
if (!data || data.ok === false) throw new Error((data && data.error) || 'send rejected')
|
|
918
|
+
setDigest(data)
|
|
919
|
+
const push = data.push
|
|
920
|
+
if (!push) {
|
|
921
|
+
setMessage({ ok: true, text: label('digestSentNoPush') })
|
|
922
|
+
return
|
|
923
|
+
}
|
|
924
|
+
if (push.ok) {
|
|
925
|
+
setMessage({ ok: true, text: label('digestPushOkPrefix') + String(push.status === undefined ? '200' : push.status) + ')' })
|
|
926
|
+
return
|
|
927
|
+
}
|
|
928
|
+
const reason = push.reason || push.error || push.body || String(push.status || '')
|
|
929
|
+
setMessage({ ok: false, text: label('digestPushFailedPrefix') + String(reason) })
|
|
930
|
+
})
|
|
931
|
+
.catch((error) => {
|
|
932
|
+
setDigestBusy(false)
|
|
933
|
+
setMessage({ ok: false, text: label('digestSendFailedPrefix') + String((error && error.message) || error) })
|
|
934
|
+
})
|
|
908
935
|
}
|
|
909
936
|
|
|
910
937
|
function digestText() {
|
package/docs/PUBLISH.md
CHANGED
|
@@ -12,7 +12,7 @@ DSH 的「插件市场 → 发现」页读的是**索引 URL**:一份 JSON(
|
|
|
12
12
|
| 索引地址(他人添加这个) | `https://jiangshuaiye1203.github.io/dsh-reminder-notify/publish/index.json` |
|
|
13
13
|
| 站点首页 | https://jiangshuaiye1203.github.io/dsh-reminder-notify/ |
|
|
14
14
|
| npm 包 | https://www.npmjs.com/package/dsh-reminder-notify |
|
|
15
|
-
| 当前版本 | **0.
|
|
15
|
+
| 当前版本 | **0.12.0**,装源为 **npm**(`dsh-reminder-notify@0.12.0`),不再是 git 固定提交 |
|
|
16
16
|
| Pages | Deploy from a branch,`main` / `(root)` |
|
|
17
17
|
|
|
18
18
|
发新版(npm 源):改代码 → 升 `package.json` 版本 → `scripts\publish-npm.cmd` 发布到 npm →
|
package/docs/detail.en.md
CHANGED
|
@@ -30,6 +30,8 @@ Changes apply on "Save" — no restart needed.
|
|
|
30
30
|
- **Phone push**: `pushEnabled` + `pushUrl` + `pushFormat` — `wecom` (WeCom bot), `serverchan` (ServerChan),
|
|
31
31
|
`json` (generic webhook), `text` (plain text). `pushDecide` and `pushDigest` decide whether decisions and the
|
|
32
32
|
digest are pushed. Delivery is fire-and-forget: 8s timeout, failures only show up in the return value.
|
|
33
|
+
Since 0.12.1 the `errcode` / `code` in the response is parsed, so a WeCom "invalid webhook url" (HTTP 200)
|
|
34
|
+
counts as a failure, and "Send one now" reports the result or the reason in the panel.
|
|
33
35
|
|
|
34
36
|
## Card behaviour (0.11+)
|
|
35
37
|
|
package/docs/detail.zh.md
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
`json`(`{"title","message","kind","time"}`)、`text`(`标题\n正文` 纯文本)。
|
|
32
32
|
`pushDecide` 控制「需要你来决定」是否推送,`pushDigest` 控制日报是否推送。
|
|
33
33
|
推送是 fire-and-forget:超时 8 秒、失败只记在返回值里,不影响卡片,也不阻塞 `notify_user`。
|
|
34
|
+
0.12.1 起会解析对方返回的 `errcode` / `code`:企业微信「webhook 地址不对」这类 HTTP 200 的失败也算失败,
|
|
35
|
+
面板上「现在发一条」会直接写出发送结果或失败原因。
|
|
34
36
|
|
|
35
37
|
## 提醒的行为(0.11 起)
|
|
36
38
|
|
package/index.js
CHANGED
|
@@ -1387,6 +1387,19 @@ export async function pushOut(settings, title, message, extra = {}) {
|
|
|
1387
1387
|
signal: typeof AbortSignal?.timeout === 'function' ? AbortSignal.timeout(8000) : undefined,
|
|
1388
1388
|
})
|
|
1389
1389
|
const text = await response.text().catch(() => '')
|
|
1390
|
+
let parsed = null
|
|
1391
|
+
try {
|
|
1392
|
+
parsed = text === '' ? null : JSON.parse(text)
|
|
1393
|
+
} catch {
|
|
1394
|
+
parsed = null
|
|
1395
|
+
}
|
|
1396
|
+
// 企业微信/Server 酱都是 HTTP 200 + 报文里的错误码:
|
|
1397
|
+
// 只看 response.ok 会把「webhook 地址不对」当成发送成功。
|
|
1398
|
+
const code = parsed && typeof parsed === 'object' ? parsed.errcode ?? parsed.code : undefined
|
|
1399
|
+
if (code !== undefined && code !== null && Number(code) !== 0) {
|
|
1400
|
+
const reason = String(parsed.errmsg ?? parsed.message ?? code)
|
|
1401
|
+
return { ok: false, status: response.status, error: 'webhook-rejected', reason, body: text.slice(0, 200) }
|
|
1402
|
+
}
|
|
1390
1403
|
return { ok: response.ok, status: response.status, body: text.slice(0, 200) }
|
|
1391
1404
|
} catch (error) {
|
|
1392
1405
|
return { ok: false, error: String(error?.message ?? error) }
|
package/package.json
CHANGED