dsh-checkin-all 0.5.0 → 0.6.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 +48 -4
- package/bin/dsh-checkin-all.js +18 -1
- package/lib/checkin-secrets.js +159 -0
- package/lib/providers/astudio.js +21 -20
- package/lib/providers/browser-cookies.js +192 -0
- package/lib/providers/doubao.js +208 -0
- package/lib/providers/index.js +6 -0
- package/lib/providers/qoder.js +193 -0
- package/lib/providers/trae.js +269 -0
- package/package.json +1 -1
- package/web/panel.js +33 -13
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-checkin-all
|
|
2
2
|
|
|
3
|
-
每天自动给 **MiniMax Code**、**WPS 灵犀**、**百度 DuMate
|
|
3
|
+
每天自动给 **MiniMax Code**、**WPS 灵犀**、**百度 DuMate(搭子)**、**AStudio(星火)**、**Qoder**、**Trae** 和 **豆包** 签到领积分。装进 [DeepSeek Harness](https://github.com/deepseek-ai/dsh)(dsh)之后,
|
|
4
4
|
它会用本机 App 已经存好的登录凭据,每天到点调一次官方签到接口,签完记账,面板挂在对话页右侧栏,
|
|
5
5
|
**顶部按服务切换卡片**。
|
|
6
6
|
|
|
@@ -18,8 +18,11 @@
|
|
|
18
18
|
| WPS 灵犀 | 灵犀自己的 Cookies(`wps_sid`) | 智点 | **北京时间** |
|
|
19
19
|
| 百度 DuMate | `qianfan-desktop-app/auth.json`(加密 cookie) | 积分 | **北京时间** |
|
|
20
20
|
| AStudio | `~/.acode/acode/userdata/astron-session.json` | 积分 | **北京时间** |
|
|
21
|
+
| Qoder | 个人访问令牌(PAT,面板里填) | 积分 | **北京时间** |
|
|
22
|
+
| Trae | 本机 Trae App/CLI 登录(自动读) | 积分 | **北京时间** |
|
|
23
|
+
| 豆包 | 登录 Cookie(面板里填,或从本机浏览器读) | 额度 | **北京时间** |
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
签到窗口不一样:灵犀、搭子、AStudio、Qoder、Trae、豆包 按北京时间算日期,美西晚上 8 点之后就已经是北京的第二天了。
|
|
23
26
|
插件按各自的规则判断「今天」,互不干扰。
|
|
24
27
|
|
|
25
28
|
## 它做什么
|
|
@@ -56,7 +59,7 @@ dsh plugin --profile desktop add /path/to/dsh-checkin-all
|
|
|
56
59
|
```bash
|
|
57
60
|
node bin/dsh-checkin-all.js status # 每个服务:登录状态 + 本周签到表 + 连续天数
|
|
58
61
|
node bin/dsh-checkin-all.js checkin # 全部签到(--dry 只看不领)
|
|
59
|
-
node bin/dsh-checkin-all.js checkin lingxi # 只签灵犀(或 minimax / dumate / astudio)
|
|
62
|
+
node bin/dsh-checkin-all.js checkin lingxi # 只签灵犀(或 minimax / dumate / astudio / qoder / trae / doubao)
|
|
60
63
|
node bin/dsh-checkin-all.js login # 设备码登录 MiniMax Code
|
|
61
64
|
node bin/dsh-checkin-all.js time 08:30 # 改自动签到时间
|
|
62
65
|
node bin/dsh-checkin-all.js on | off # 开 / 关自动签到
|
|
@@ -81,7 +84,7 @@ node bin/dsh-checkin-all.js on | off # 开 / 关自动签到
|
|
|
81
84
|
|
|
82
85
|
命令:`/checkin 状态|签到 [服务]|时间 09:00|开启|关闭|登录`(`/minimax` 是别名)
|
|
83
86
|
|
|
84
|
-
服务名:`minimax`(MiniMax Code)/ `lingxi`(WPS 灵犀)/ `dumate`(百度 DuMate)/ `astudio`(AStudio
|
|
87
|
+
服务名:`minimax`(MiniMax Code)/ `lingxi`(WPS 灵犀)/ `dumate`(百度 DuMate)/ `astudio`(AStudio)/ `qoder`(Qoder)/ `trae`(Trae)/ `doubao`(豆包)
|
|
85
88
|
|
|
86
89
|
## 配置
|
|
87
90
|
|
|
@@ -227,6 +230,47 @@ POST client-popups/complete 领取(body: { popupId, instanceKey })
|
|
|
227
230
|
ssoSessionId=<ssoSessionId>; sso_sessionid=<ssoSessionId>; account_id=<accountId>; token=<token>
|
|
228
231
|
```
|
|
229
232
|
|
|
233
|
+
### Qoder
|
|
234
|
+
|
|
235
|
+
Qoder 的「签到」= **每日领取 CLAIM_BENEFIT 赠送积分**,与 Qoder 桌面端「用量面板」的领取链路一致
|
|
236
|
+
(`lib/providers/qoder.js`):
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
POST {openApi}/api/v1/jobToken/exchange PAT 换短期 jobToken
|
|
240
|
+
GET {openApi}/sash/api/v1/me/campaigns 找当天的 CLAIM_BENEFIT 活动
|
|
241
|
+
POST {openApi}/sash/api/v1/me/campaigns/{id}/claim 幂等领取(重复返回 replayed)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
- 国内版 `https://openapi.qoder.com.cn`,国际版 `https://openapi.qoder.sh`
|
|
245
|
+
- 凭据:**个人访问令牌(PAT)**,在面板里填,存 `~/.dsh/dsh-checkin-all/secrets.json`(0600)
|
|
246
|
+
- 「今天」按**北京时间**算
|
|
247
|
+
|
|
248
|
+
### Trae
|
|
249
|
+
|
|
250
|
+
Trae(国内版 / SOLO)的每日签到,读本机 Trae 桌面 App 或 CLI 的登录(`lib/providers/trae.js`):
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
POST https://api.trae.cn/trae/api/v2/ug/checkin_credits/status 今天签没签
|
|
254
|
+
POST https://api.trae.cn/trae/api/v2/ug/checkin_credits/claim 签到
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
- 凭据:本机 Trae 的登录(桌面 App 的 `storage.json` 加密信封,或 `~/.trae-cn/trae-jwt-token` / `~/.trae/trae-jwt-token`),只读不落盘
|
|
258
|
+
- 桌面 App 位置:`{TRAE SOLO CN | Trae CN | Trae | TRAE SOLO}/User/globalStorage/storage.json`
|
|
259
|
+
- 「今天」按**北京时间**算
|
|
260
|
+
|
|
261
|
+
### 豆包
|
|
262
|
+
|
|
263
|
+
豆包的「天天领额度」每日签到(`lib/providers/doubao.js` + `browser-cookies.js`):
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
POST https://www.doubao.com/alice/ug/campaign/v3/detail/ 任务面板
|
|
267
|
+
POST https://www.doubao.com/alice/ug/campaign/landing/checkin 领取(幂等,重复返回 idempotent:true)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
- 凭据:豆包登录 Cookie(`doubao.com`),在面板里手动粘贴,或从本机豆包电脑版/Chrome/Edge/Brave 自动读
|
|
271
|
+
- 只支持个人账号:飞书企业账号没有签到任务
|
|
272
|
+
- 「今天」按**北京时间**算
|
|
273
|
+
|
|
230
274
|
## 隐私
|
|
231
275
|
|
|
232
276
|
- 不保存账号密码,只用 App 已经存好的 OAuth 凭据
|
package/bin/dsh-checkin-all.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// dsh-checkin-all on | off 开 / 关自动签到
|
|
9
9
|
// dsh-checkin-all cron 给系统 crontab 用的静默签到
|
|
10
10
|
//
|
|
11
|
-
// 服务名:minimax(MiniMax Code)/ lingxi(WPS 灵犀)/ dumate(百度 DuMate)/ astudio(AStudio
|
|
11
|
+
// 服务名:minimax(MiniMax Code)/ lingxi(WPS 灵犀)/ dumate(百度 DuMate)/ astudio(AStudio)/ qoder(Qoder)/ trae(Trae)/ doubao(豆包)
|
|
12
12
|
//
|
|
13
13
|
// 系统 crontab 里可以这样挂(不想依赖 DSH 常驻时):
|
|
14
14
|
// 0 9 * * * /path/to/dsh-checkin-all cron >> ~/.dsh/dsh-checkin-all/cron.log 2>&1
|
|
@@ -28,6 +28,14 @@ const STATUS_TAG = { 1: '未到', 2: '可领', 3: '已领', 4: '未开放' }
|
|
|
28
28
|
|
|
29
29
|
function printPanel(panel, unit) {
|
|
30
30
|
if (!panel || !panel.days.length) return console.log(' 签到表读不出来')
|
|
31
|
+
// 「每日登录积分」型服务(AStudio):只显示今天一天,不显示「本周 7 天」
|
|
32
|
+
if (panel.style === 'daily') {
|
|
33
|
+
const day = panel.days[0]
|
|
34
|
+
const done = day.status === 3
|
|
35
|
+
console.log(` 今天 +${String(day.points).padStart(5)}${done ? ' 已到账' : ' 可领取'} ← 今天`)
|
|
36
|
+
if (panel.accountCredits) console.log(` 账户累计 ${panel.accountCredits} ${unit}`)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
31
39
|
for (const day of panel.days) {
|
|
32
40
|
const mark = day.isToday ? ' ← 今天' : ''
|
|
33
41
|
const bonus = day.bonusPoints ? ` +${day.bonusPoints}奖励` : ''
|
|
@@ -162,5 +170,14 @@ main().catch((error) => {
|
|
|
162
170
|
if (error.code === 'ASTUDIO_NOT_LOGGED_IN' || error.code === 'ASTUDIO_SESSION_EXPIRED') {
|
|
163
171
|
console.error('AStudio 没登录或登录失效:打开 AStudio App 登录一次')
|
|
164
172
|
}
|
|
173
|
+
if (error.code === 'QODER_NOT_CONFIGURED' || error.code === 'QODER_AUTH') {
|
|
174
|
+
console.error('Qoder 没配置:在面板里添加个人访问令牌(PAT)')
|
|
175
|
+
}
|
|
176
|
+
if (error.code === 'TRAE_NOT_LOGGED_IN') {
|
|
177
|
+
console.error('Trae 没登录:打开 Trae App 登录一次(要在装了 Trae 的电脑上签)')
|
|
178
|
+
}
|
|
179
|
+
if (error.code === 'DOUBAO_NOT_CONFIGURED') {
|
|
180
|
+
console.error('豆包没配置:在面板里添加 Cookie(手动粘贴或从浏览器读)')
|
|
181
|
+
}
|
|
165
182
|
process.exitCode = 1
|
|
166
183
|
})
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// lib/checkin-secrets.js — Qoder PAT / 豆包 Cookie 的凭据存储
|
|
2
|
+
//
|
|
3
|
+
// 这些是用户填写的签到凭据(Qoder 个人访问令牌、豆包登录 Cookie),和设置/历史
|
|
4
|
+
// 分开存,文件 0600。Trae 不在这里——它读本机 Trae App 的登录,不需要用户填。
|
|
5
|
+
//
|
|
6
|
+
// 结构(~/.dsh/dsh-checkin-all/secrets.json):
|
|
7
|
+
// { "qoders": [{ id, pat, region, name?, savedAt? }],
|
|
8
|
+
// "doubaos": [{ id, cookie, seed, name?, from?, savedAt? }] }
|
|
9
|
+
|
|
10
|
+
import { randomBytes } from 'node:crypto'
|
|
11
|
+
import { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'
|
|
12
|
+
import { dirname, join } from 'node:path'
|
|
13
|
+
import { pluginHome } from './paths.js'
|
|
14
|
+
|
|
15
|
+
export function secretsPath(env = process.env) {
|
|
16
|
+
return join(pluginHome(env), 'secrets.json')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function writeAtomicPrivate(file, text) {
|
|
20
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 })
|
|
21
|
+
const tmp = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`
|
|
22
|
+
await writeFile(tmp, text, { mode: 0o600 })
|
|
23
|
+
await chmod(tmp, 0o600).catch(() => {})
|
|
24
|
+
try {
|
|
25
|
+
await rename(tmp, file)
|
|
26
|
+
} catch (error) {
|
|
27
|
+
await rm(tmp, { force: true }).catch(() => {})
|
|
28
|
+
throw error
|
|
29
|
+
}
|
|
30
|
+
await chmod(file, 0o600).catch(() => {})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function readJson(file) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(await readFile(file, 'utf8'))
|
|
36
|
+
} catch {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function loadSecrets(env = process.env) {
|
|
42
|
+
const doc = await readJson(secretsPath(env))
|
|
43
|
+
return doc && typeof doc === 'object' ? doc : {}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function saveSecrets(secrets, env = process.env) {
|
|
47
|
+
await writeAtomicPrivate(secretsPath(env), `${JSON.stringify(secrets, null, 2)}\n`)
|
|
48
|
+
return secrets
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Cookie 串里某一项的值 */
|
|
52
|
+
export function cookieValue(cookie, name) {
|
|
53
|
+
for (const part of String(cookie || '').split(/;\s*/)) {
|
|
54
|
+
const i = part.indexOf('=')
|
|
55
|
+
if (i > 0 && part.slice(0, i).trim() === name) return part.slice(i + 1)
|
|
56
|
+
}
|
|
57
|
+
return undefined
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ── Qoder 令牌 ──
|
|
61
|
+
|
|
62
|
+
export async function loadQoders(env = process.env) {
|
|
63
|
+
const secrets = await loadSecrets(env)
|
|
64
|
+
const c = secrets.checkin
|
|
65
|
+
if (c?.qoders?.length) return c.qoders
|
|
66
|
+
// 旧版:只有一个令牌(qoder.pat),读出来当第一个
|
|
67
|
+
return c?.qoder?.pat
|
|
68
|
+
? [{ id: '1', pat: c.qoder.pat, region: c.qoder.region, ...(c.qoder.savedAt ? { savedAt: c.qoder.savedAt } : {}) }]
|
|
69
|
+
: []
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function saveQoders(list, env = process.env) {
|
|
73
|
+
const secrets = await loadSecrets(env)
|
|
74
|
+
const checkin = { ...(secrets.checkin || {}) }
|
|
75
|
+
delete checkin.qoder
|
|
76
|
+
if (list.length) checkin.qoders = list
|
|
77
|
+
else delete checkin.qoders
|
|
78
|
+
if (Object.keys(checkin).length) secrets.checkin = checkin
|
|
79
|
+
else delete secrets.checkin
|
|
80
|
+
await saveSecrets(secrets, env)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 加一个令牌:同一个令牌再加就是改名字 / 区域;返回 id */
|
|
84
|
+
export async function addQoder(entry, env = process.env) {
|
|
85
|
+
const list = await loadQoders(env)
|
|
86
|
+
const name = entry.name?.trim().slice(0, 20)
|
|
87
|
+
const same = list.find((q) => q.pat === entry.pat)
|
|
88
|
+
if (same) {
|
|
89
|
+
same.region = entry.region
|
|
90
|
+
if (name) same.name = name
|
|
91
|
+
await saveQoders(list, env)
|
|
92
|
+
return same.id
|
|
93
|
+
}
|
|
94
|
+
const used = new Set(list.map((q) => q.id))
|
|
95
|
+
let n = list.length + 1
|
|
96
|
+
while (used.has(String(n))) n++
|
|
97
|
+
const id = String(n)
|
|
98
|
+
list.push({ id, pat: entry.pat, region: entry.region, ...(name ? { name } : {}), savedAt: new Date().toISOString() })
|
|
99
|
+
await saveQoders(list, env)
|
|
100
|
+
return id
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function removeQoder(id, env = process.env) {
|
|
104
|
+
const list = await loadQoders(env)
|
|
105
|
+
const target = id ?? list[0]?.id
|
|
106
|
+
await saveQoders(list.filter((q) => q.id !== target), env)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── 豆包 Cookie ──
|
|
110
|
+
|
|
111
|
+
export async function loadDoubaos(env = process.env) {
|
|
112
|
+
const secrets = await loadSecrets(env)
|
|
113
|
+
return secrets.checkin?.doubaos ?? []
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function saveDoubaos(list, env = process.env) {
|
|
117
|
+
const secrets = await loadSecrets(env)
|
|
118
|
+
const checkin = { ...(secrets.checkin || {}) }
|
|
119
|
+
if (list.length) checkin.doubaos = list
|
|
120
|
+
else delete checkin.doubaos
|
|
121
|
+
if (Object.keys(checkin).length) secrets.checkin = checkin
|
|
122
|
+
else delete secrets.checkin
|
|
123
|
+
await saveSecrets(secrets, env)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 同一个豆包账号:uid_tt 一样(Cookie 里别的项每次都会变) */
|
|
127
|
+
function sameDoubaoAccount(a, b) {
|
|
128
|
+
const x = cookieValue(a, 'uid_tt')
|
|
129
|
+
return a === b || (Boolean(x) && x === cookieValue(b, 'uid_tt'))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 加一个豆包账号;同一个账号再加 = 换成新的 Cookie(和名字)。返回 id */
|
|
133
|
+
export async function addDoubao(entry, env = process.env) {
|
|
134
|
+
const list = await loadDoubaos(env)
|
|
135
|
+
const name = entry.name?.trim().slice(0, 20)
|
|
136
|
+
const same = list.find((d) => sameDoubaoAccount(d.cookie, entry.cookie))
|
|
137
|
+
if (same) {
|
|
138
|
+
same.cookie = entry.cookie
|
|
139
|
+
if (name) same.name = name
|
|
140
|
+
if (entry.from) same.from = entry.from
|
|
141
|
+
await saveDoubaos(list, env)
|
|
142
|
+
return same.id
|
|
143
|
+
}
|
|
144
|
+
const used = new Set(list.map((d) => d.id))
|
|
145
|
+
let n = list.length + 1
|
|
146
|
+
while (used.has(String(n))) n++
|
|
147
|
+
const id = String(n)
|
|
148
|
+
list.push({ id, cookie: entry.cookie, seed: entry.seed ?? randomBytes(16).toString('hex'), ...(name ? { name } : {}), ...(entry.from ? { from: entry.from } : {}), savedAt: new Date().toISOString() })
|
|
149
|
+
await saveDoubaos(list, env)
|
|
150
|
+
return id
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function removeDoubao(id, env = process.env) {
|
|
154
|
+
const list = await loadDoubaos(env)
|
|
155
|
+
const next = list.filter((d) => d.id !== id)
|
|
156
|
+
if (next.length === list.length) return false
|
|
157
|
+
await saveDoubaos(next, env)
|
|
158
|
+
return true
|
|
159
|
+
}
|
package/lib/providers/astudio.js
CHANGED
|
@@ -140,8 +140,12 @@ export function pickDailyPopup(items) {
|
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
142
|
* 把 AStudio 的积分数据归一化成面板认的签到表。
|
|
143
|
-
*
|
|
144
|
-
*
|
|
143
|
+
*
|
|
144
|
+
* AStudio 是「每日登录积分」自动到账,没有逐天的 7 天签到表,接口也不返回
|
|
145
|
+
* 历史逐天记录。所以这里**不伪造过去 6 天**,days 只放「今天」一天:
|
|
146
|
+
* - 今天有待领弹窗 → status=2(可领)
|
|
147
|
+
* - 今天已自动到账 → status=3(已领)
|
|
148
|
+
* 面板据此用「每日登录积分」的风格渲染,而不是「本周 7 天」。
|
|
145
149
|
*/
|
|
146
150
|
export function normalizeAstudioPanel({ balance, membership, planConfig, popups, now = new Date() }) {
|
|
147
151
|
const b = balance || {}
|
|
@@ -159,30 +163,27 @@ export function normalizeAstudioPanel({ balance, membership, planConfig, popups,
|
|
|
159
163
|
const dailyPopup = pickDailyPopup(popups)
|
|
160
164
|
const todayKey = beijingDayKey(now)
|
|
161
165
|
|
|
162
|
-
//
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
status: isToday ? (dailyPopup ? 2 : 3) : 3,
|
|
174
|
-
isToday,
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
const today = days.find(d => d.isToday) || null
|
|
166
|
+
// 只放今天一天:可领 / 已到账。不伪造过去 6 天。
|
|
167
|
+
const todayStatus = dailyPopup ? 2 : 3
|
|
168
|
+
const days = [{
|
|
169
|
+
dayNo: 1,
|
|
170
|
+
date: todayKey,
|
|
171
|
+
points: dailyPoints,
|
|
172
|
+
bonusPoints: 0,
|
|
173
|
+
status: todayStatus,
|
|
174
|
+
isToday: true,
|
|
175
|
+
}]
|
|
176
|
+
const today = days[0]
|
|
178
177
|
|
|
179
178
|
return {
|
|
180
179
|
scene: 0,
|
|
180
|
+
// 标记:这是「每日登录积分」型服务,不是「本周 7 天」型,面板按此改措辞
|
|
181
|
+
style: 'daily',
|
|
181
182
|
days,
|
|
182
183
|
today,
|
|
183
184
|
claimable: Boolean(dailyPopup),
|
|
184
|
-
claimedDays:
|
|
185
|
-
totalPoints:
|
|
185
|
+
claimedDays: todayStatus === 3 ? 1 : 0,
|
|
186
|
+
totalPoints: todayStatus === 3 ? dailyPoints : 0,
|
|
186
187
|
// 账户累计(通用积分)+ 星火积分
|
|
187
188
|
accountCredits: totalBalance,
|
|
188
189
|
sparkBalance,
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// lib/providers/browser-cookies.js — 从本机已登录的豆包电脑版 / 浏览器里读 doubao.com 的登录 Cookie
|
|
2
|
+
//
|
|
3
|
+
// 豆包电脑版(DoubaoWork)和 Chrome、Edge、Brave 都是 Chromium,Cookie 存在
|
|
4
|
+
// <用户数据>/<配置>/Cookies(新版在 Network/Cookies)这个 SQLite 里,值是加密的:
|
|
5
|
+
// macOS:v10 + AES-128-CBC,密钥 = PBKDF2(钥匙串里「<应用> Safe Storage」的密码, 'saltysalt', 1003, sha1)。
|
|
6
|
+
// 读钥匙串时 macOS 会弹窗问用户是否允许,用户点允许才读得到。
|
|
7
|
+
// Windows:v10 + AES-256-GCM,密钥在 Local State 的 os_crypt.encrypted_key 里,用当前用户的 DPAPI 解开。
|
|
8
|
+
// 新版 Chrome 的 v20(应用绑定加密)读不了,跳过。
|
|
9
|
+
// Linux:不读(VPS 上也没有这些应用)。
|
|
10
|
+
// Cookie 库版本 ≥ 24 时,解开的值前面多 32 字节(host 的 sha256),要去掉。
|
|
11
|
+
// 只读 doubao.com 的 Cookie,只在用户点「从本机找」时读;先只看有没有登录(不碰密钥),有才去解密。
|
|
12
|
+
|
|
13
|
+
import { createDecipheriv, pbkdf2Sync } from 'node:crypto'
|
|
14
|
+
import { copyFile, mkdtemp, readdir, readFile, rm, stat } from 'node:fs/promises'
|
|
15
|
+
import { homedir, tmpdir } from 'node:os'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
import { execFile } from 'node:child_process'
|
|
18
|
+
import { promisify } from 'node:util'
|
|
19
|
+
|
|
20
|
+
const runExec = promisify(execFile)
|
|
21
|
+
|
|
22
|
+
const HOSTS = ['doubao.com', '.doubao.com', 'www.doubao.com']
|
|
23
|
+
const SESSION_COOKIE = 'sessionid'
|
|
24
|
+
|
|
25
|
+
export class CookieAccessDenied extends Error {
|
|
26
|
+
constructor() { super('没有允许读取钥匙串') }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function cookieStores(home = homedir(), platform = process.platform, env = process.env) {
|
|
30
|
+
if (platform === 'darwin') {
|
|
31
|
+
const s = join(home, 'Library', 'Application Support')
|
|
32
|
+
return [
|
|
33
|
+
{ label: '豆包电脑版', root: join(s, 'DoubaoWork'), services: ['DoubaoWork Browser Safe Storage', 'DoubaoWork Safe Storage'] },
|
|
34
|
+
{ label: '豆包', root: join(s, 'Doubao'), services: ['Doubao Browser Safe Storage', 'Doubao Safe Storage'] },
|
|
35
|
+
{ label: 'Chrome', root: join(s, 'Google', 'Chrome'), services: ['Chrome Safe Storage'] },
|
|
36
|
+
{ label: 'Edge', root: join(s, 'Microsoft Edge'), services: ['Microsoft Edge Safe Storage'] },
|
|
37
|
+
{ label: 'Brave', root: join(s, 'BraveSoftware', 'Brave-Browser'), services: ['Brave Safe Storage'] },
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
if (platform === 'win32') {
|
|
41
|
+
const local = env.LOCALAPPDATA || join(home, 'AppData', 'Local')
|
|
42
|
+
const roaming = env.APPDATA || join(home, 'AppData', 'Roaming')
|
|
43
|
+
return [
|
|
44
|
+
{ label: '豆包电脑版', root: join(local, 'DoubaoWork', 'User Data'), services: [] },
|
|
45
|
+
{ label: '豆包电脑版', root: join(roaming, 'DoubaoWork'), services: [] },
|
|
46
|
+
{ label: '豆包', root: join(local, 'Doubao', 'User Data'), services: [] },
|
|
47
|
+
{ label: 'Chrome', root: join(local, 'Google', 'Chrome', 'User Data'), services: [] },
|
|
48
|
+
{ label: 'Edge', root: join(local, 'Microsoft', 'Edge', 'User Data'), services: [] },
|
|
49
|
+
{ label: 'Brave', root: join(local, 'BraveSoftware', 'Brave-Browser', 'User Data'), services: [] },
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
return []
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const exists = async (p) => stat(p).then(() => true, () => false)
|
|
56
|
+
|
|
57
|
+
async function cookieDbs(store) {
|
|
58
|
+
let names
|
|
59
|
+
try { names = await readdir(store.root) } catch { return [] }
|
|
60
|
+
const out = []
|
|
61
|
+
for (const profile of names.filter((n) => n === 'Default' || /^Profile \d+$/.test(n)).sort()) {
|
|
62
|
+
for (const rel of [['Network', 'Cookies'], ['Cookies']]) {
|
|
63
|
+
const file = join(store.root, profile, ...rel)
|
|
64
|
+
if (await exists(file)) { out.push({ store, profile, file }); break }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const chromeTimeToMs = (t) => (t ? t - 11_644_473_600_000 : 0)
|
|
71
|
+
|
|
72
|
+
export async function readCookieDb(file) {
|
|
73
|
+
const dir = await mkdtemp(join(tmpdir(), 'dshck-'))
|
|
74
|
+
try {
|
|
75
|
+
const copy = join(dir, 'Cookies')
|
|
76
|
+
await copyFile(file, copy)
|
|
77
|
+
for (const ext of ['-journal', '-wal']) await copyFile(file + ext, copy + ext).catch(() => {})
|
|
78
|
+
return await querySqlite(copy)
|
|
79
|
+
} finally {
|
|
80
|
+
await rm(dir, { recursive: true, force: true })
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const SQL_ROWS = `select host_key, name, value, hex(encrypted_value) as ev, expires_utc / 1000 as expires_utc from cookies where host_key in (${HOSTS.map((h) => `'${h}'`).join(',')})`
|
|
85
|
+
const SQL_VERSION = `select value from meta where key = 'version'`
|
|
86
|
+
|
|
87
|
+
async function querySqlite(file) {
|
|
88
|
+
let raw
|
|
89
|
+
let version
|
|
90
|
+
try {
|
|
91
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
92
|
+
const db = new DatabaseSync(file, { readOnly: true })
|
|
93
|
+
try {
|
|
94
|
+
raw = db.prepare(SQL_ROWS).all()
|
|
95
|
+
version = Number(db.prepare(SQL_VERSION).get()?.value) || 0
|
|
96
|
+
} finally {
|
|
97
|
+
db.close()
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error.code !== 'ERR_UNKNOWN_BUILTIN_MODULE' && !/node:sqlite/.test(String(error))) throw error
|
|
101
|
+
// 退回系统 sqlite3
|
|
102
|
+
const a = await runExec('sqlite3', ['-readonly', '-json', file, SQL_ROWS], { timeout: 20_000 }).catch((e) => ({ stdout: '', stderr: String(e), code: 1 }))
|
|
103
|
+
const b = await runExec('sqlite3', ['-readonly', file, SQL_VERSION], { timeout: 20_000 }).catch((e) => ({ stdout: '', stderr: String(e), code: 1 }))
|
|
104
|
+
if (a.code !== 0) throw new Error(`读 Cookie 库失败:${a.stderr.trim()}`)
|
|
105
|
+
raw = a.stdout.trim() ? JSON.parse(a.stdout) : []
|
|
106
|
+
version = Number(b.stdout.trim()) || 0
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
rows: raw.map((r) => ({ host_key: r.host_key, name: r.name, value: r.value ?? '', encrypted_value: Buffer.from(r.ev ?? '', 'hex'), expires_utc: Number(r.expires_utc) || 0 })),
|
|
110
|
+
version,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const alive = (r, now) => {
|
|
115
|
+
const ms = chromeTimeToMs(r.expires_utc)
|
|
116
|
+
return !ms || ms > now
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 只看哪些地方登录着豆包(不解密、不碰钥匙串,不会弹窗) */
|
|
120
|
+
export async function findDoubaoLogins(home = homedir(), platform = process.platform, now = Date.now()) {
|
|
121
|
+
const out = []
|
|
122
|
+
for (const store of cookieStores(home, platform)) {
|
|
123
|
+
const dbs = await cookieDbs(store)
|
|
124
|
+
for (const db of dbs) {
|
|
125
|
+
const { rows } = await readCookieDb(db.file).catch(() => ({ rows: [] }))
|
|
126
|
+
if (rows.some((r) => r.name === SESSION_COOKIE && alive(r, now))) {
|
|
127
|
+
out.push({ label: dbs.length > 1 && db.profile !== 'Default' ? `${store.label}(${db.profile})` : store.label, db })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return out
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function macKey(services) {
|
|
135
|
+
let last = ''
|
|
136
|
+
for (const s of services) {
|
|
137
|
+
const r = await runExec('/usr/bin/security', ['find-generic-password', '-w', '-s', s], { timeout: 120_000 }).catch((e) => ({ code: 1, stdout: '', stderr: String(e) }))
|
|
138
|
+
if (r.code === 0 && r.stdout.trim()) return pbkdf2Sync(r.stdout.trim(), 'saltysalt', 1003, 16, 'sha1')
|
|
139
|
+
last = r.stderr.trim()
|
|
140
|
+
if (/cancel|denied|拒绝|取消/i.test(last) || r.code === 128) throw new CookieAccessDenied()
|
|
141
|
+
}
|
|
142
|
+
throw new Error(`钥匙串里没找到它的 Cookie 密钥${last ? `(${last})` : ''}`)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function winKey(root) {
|
|
146
|
+
const state = JSON.parse(await readFile(join(root, 'Local State'), 'utf8'))
|
|
147
|
+
const enc = Buffer.from(state.os_crypt?.encrypted_key ?? '', 'base64')
|
|
148
|
+
if (enc.subarray(0, 5).toString() !== 'DPAPI') throw new Error('Local State 里没有能用的 Cookie 密钥')
|
|
149
|
+
const script = "Add-Type -AssemblyName System.Security; $b=[Convert]::FromBase64String($env:DSHM_BLOB); [Convert]::ToBase64String([Security.Cryptography.ProtectedData]::Unprotect($b,$null,'CurrentUser'))"
|
|
150
|
+
const r = await runExec('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], { env: { ...process.env, DSHM_BLOB: enc.subarray(5).toString('base64') }, timeout: 30_000 }).catch((e) => ({ code: 1, stdout: '', stderr: String(e) }))
|
|
151
|
+
if (r.code !== 0 || !r.stdout.trim()) throw new Error(`解不开 Cookie 密钥:${r.stderr.trim() || `退出码 ${r.code}`}`)
|
|
152
|
+
return Buffer.from(r.stdout.trim(), 'base64')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 解开一个 Cookie 值。读不了(如 v20)返回 null */
|
|
156
|
+
export function decryptCookie(enc, key, platform, dbVersion) {
|
|
157
|
+
const tag = enc.subarray(0, 3).toString()
|
|
158
|
+
if (tag !== 'v10' && tag !== 'v11') return null
|
|
159
|
+
let plain
|
|
160
|
+
if (platform === 'win32') {
|
|
161
|
+
const nonce = enc.subarray(3, 15)
|
|
162
|
+
const body = enc.subarray(15, enc.length - 16)
|
|
163
|
+
const d = createDecipheriv('aes-256-gcm', key, nonce)
|
|
164
|
+
d.setAuthTag(enc.subarray(enc.length - 16))
|
|
165
|
+
plain = Buffer.concat([d.update(body), d.final()])
|
|
166
|
+
} else {
|
|
167
|
+
const d = createDecipheriv('aes-128-cbc', key, Buffer.alloc(16, 0x20))
|
|
168
|
+
plain = Buffer.concat([d.update(enc.subarray(3)), d.final()])
|
|
169
|
+
}
|
|
170
|
+
return (dbVersion >= 24 ? plain.subarray(32) : plain).toString('utf8')
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** 读出一处登录的完整 Cookie 串(a=1; b=2)。macOS 会弹钥匙串授权 */
|
|
174
|
+
export async function readDoubaoCookie(login, platform = process.platform, now = Date.now(), testKey) {
|
|
175
|
+
const { rows, version } = await readCookieDb(login.db.file)
|
|
176
|
+
const key = testKey ?? (platform === 'darwin' ? await macKey(login.db.store.services) : await winKey(login.db.store.root))
|
|
177
|
+
const byName = new Map()
|
|
178
|
+
let unreadable = 0
|
|
179
|
+
for (const r of rows.filter((x) => alive(x, now))) {
|
|
180
|
+
let value = r.value
|
|
181
|
+
if (!value && r.encrypted_value.length) {
|
|
182
|
+
try { value = decryptCookie(r.encrypted_value, key, platform, version) } catch { value = null }
|
|
183
|
+
}
|
|
184
|
+
if (value === null) { unreadable++; continue }
|
|
185
|
+
const prev = byName.get(r.name)
|
|
186
|
+
if (!prev || r.host_key.length > prev.host.length) byName.set(r.name, { host: r.host_key, value })
|
|
187
|
+
}
|
|
188
|
+
if (!byName.get(SESSION_COOKIE)?.value) {
|
|
189
|
+
throw new Error(unreadable ? `${login.label} 用的是新的加密方式,读不了:请用「手动粘贴 Cookie」` : `${login.label} 里的豆包登录不完整`)
|
|
190
|
+
}
|
|
191
|
+
return [...byName].map(([n, v]) => `${n}=${v.value}`).join('; ')
|
|
192
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// lib/providers/doubao.js — 豆包每日签到(「天天领额度」,每天 +200 体验额度)
|
|
2
|
+
//
|
|
3
|
+
// 协议照 dsh-model 的 src/checkin/doubao.ts(原自 techysy/CreditDaddy,MIT):
|
|
4
|
+
// POST https://www.doubao.com/alice/ug/campaign/v3/detail/ 任务面板(含今天签没签)
|
|
5
|
+
// POST https://www.doubao.com/alice/ug/campaign/landing/checkin 领取;服务端幂等,重复领返回 idempotent:true
|
|
6
|
+
// 鉴权只要 doubao.com 的登录 Cookie。请求带豆包电脑版网页的平台参数。
|
|
7
|
+
// 只支持个人账号:飞书企业账号的任务面板里没有签到任务。
|
|
8
|
+
// Cookie 由用户从浏览器复制一次(存 secrets.json,0600),或从本机浏览器自动读。
|
|
9
|
+
|
|
10
|
+
import { createHash } from 'node:crypto'
|
|
11
|
+
import { loadDoubaos } from '../checkin-secrets.js'
|
|
12
|
+
import { findDoubaoLogins, readDoubaoCookie } from './browser-cookies.js'
|
|
13
|
+
import { OUTCOME } from './base.js'
|
|
14
|
+
|
|
15
|
+
const DETAIL_URL = 'https://www.doubao.com/alice/ug/campaign/v3/detail/'
|
|
16
|
+
const CHECKIN_URL = 'https://www.doubao.com/alice/ug/campaign/landing/checkin'
|
|
17
|
+
const CAMPAIGN_GROUP = 'pc_incentive_task_mvp_v3'
|
|
18
|
+
const LOGIN_INVALID = 710012001
|
|
19
|
+
const TIMEOUT_MS = 20_000
|
|
20
|
+
const DOUBAO_TZ = 'Asia/Shanghai'
|
|
21
|
+
|
|
22
|
+
const CLIENT_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) DoubaoDesktop/2.32.6 Chrome/147.0.7727.149 Safari/537.36'
|
|
23
|
+
const COMMON_PARAMS = {
|
|
24
|
+
version_code: '20800',
|
|
25
|
+
language: 'zh',
|
|
26
|
+
device_platform: 'web',
|
|
27
|
+
doubao_device_platform: 'web',
|
|
28
|
+
aid: '497858',
|
|
29
|
+
real_aid: '497858',
|
|
30
|
+
pkg_type: 'release_version',
|
|
31
|
+
pc_version: '2.32.6',
|
|
32
|
+
doubao_pc_version: '5.72.66',
|
|
33
|
+
samantha_web: '1',
|
|
34
|
+
web_platform: 'desktop',
|
|
35
|
+
'use-olympus-account': '1',
|
|
36
|
+
web_tab_id: '0',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class DoubaoAuthError extends Error {}
|
|
40
|
+
|
|
41
|
+
/** 每个账号一组稳定的网页标识(由这个账号自己的随机种子派生,账号之间不同) */
|
|
42
|
+
export function deviceIdsFor(seed) {
|
|
43
|
+
const h = createHash('sha256').update(`doubao-dev:${seed}`).digest()
|
|
44
|
+
return {
|
|
45
|
+
web_id: '76' + [...h.subarray(0, 8)].map((b) => b % 10).join(''),
|
|
46
|
+
tea_uuid: [...h.subarray(8, 16)].map((b) => b % 10).join('').padEnd(16, '7'),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function apiUrl(base, seed) {
|
|
51
|
+
return `${base}?${new URLSearchParams({ ...COMMON_PARAMS, ...deviceIdsFor(seed), device_id: '', region: '', sys_region: '' })}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 用户粘贴的可能是整行 "Cookie: a=b; c=d",也可能带换行:规整成 "a=b; c=d" */
|
|
55
|
+
export function normalizeCookie(raw) {
|
|
56
|
+
return String(raw || '').replace(/^\s*cookie\s*:\s*/i, '').replace(/[\r\n]+/g, ' ').replace(/\s*;\s*/g, '; ').replace(/;\s*$/, '').trim()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function post(url, cookie, body) {
|
|
60
|
+
const res = await fetch(url, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: {
|
|
63
|
+
Cookie: cookie,
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
Accept: 'application/json, text/plain, */*',
|
|
66
|
+
Referer: 'https://www.doubao.com/pc/agent-explore',
|
|
67
|
+
Origin: 'https://www.doubao.com',
|
|
68
|
+
'User-Agent': CLIENT_UA,
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify(body),
|
|
71
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
72
|
+
})
|
|
73
|
+
const text = await res.text()
|
|
74
|
+
try {
|
|
75
|
+
const json = JSON.parse(text)
|
|
76
|
+
if (json && typeof json === 'object') return json
|
|
77
|
+
} catch {
|
|
78
|
+
// 非 JSON
|
|
79
|
+
}
|
|
80
|
+
throw new Error(`豆包接口返回无法解析(HTTP ${res.status})`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 签到状态(detail 接口)。Cookie 不对抛 DoubaoAuthError */
|
|
84
|
+
export async function doubaoStatus(cookie, seed) {
|
|
85
|
+
const body = await post(apiUrl(DETAIL_URL, seed), cookie, { campaign_group_code: CAMPAIGN_GROUP })
|
|
86
|
+
const code = Number(body.code)
|
|
87
|
+
if (code === LOGIN_INVALID) throw new DoubaoAuthError('豆包登录已过期(Cookie 失效)')
|
|
88
|
+
if (code !== 0) throw new Error(`豆包任务面板返回异常:${String(body.msg ?? body.message ?? '')}(code ${code})`)
|
|
89
|
+
const data = body.data ?? {}
|
|
90
|
+
const task = Array.isArray(data.tasks) ? data.tasks.find((t) => t?.task_kind === 'daily_signin') : undefined
|
|
91
|
+
const c = task?.daily_checkin ?? {}
|
|
92
|
+
return {
|
|
93
|
+
checkedIn: task ? c.checked_in_today === true : null,
|
|
94
|
+
continuousDays: Number(c.continuous_days) || 0,
|
|
95
|
+
rewardAmount: Number(c.reward?.reward_amount) || 0,
|
|
96
|
+
totalAmount: Number(data.progress?.total_amount) || 0,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 签到:先看今天签没签,没签才领 */
|
|
101
|
+
export async function doubaoCheckin(cookie, seed) {
|
|
102
|
+
const st = await doubaoStatus(cookie, seed)
|
|
103
|
+
if (st.checkedIn === null) throw new Error('这个豆包账号的任务面板里没有「每日签到」(飞书企业账号、或豆包没给这个账号开签到时都是这样)')
|
|
104
|
+
if (st.checkedIn) return { state: 'already' }
|
|
105
|
+
const body = await post(apiUrl(CHECKIN_URL, seed), cookie, { scene: CAMPAIGN_GROUP })
|
|
106
|
+
const code = Number(body.code)
|
|
107
|
+
if (code === LOGIN_INVALID) throw new DoubaoAuthError('豆包登录已过期(Cookie 失效)')
|
|
108
|
+
if (code !== 0) throw new Error(`豆包签到失败:${String(body.msg ?? body.message ?? '')}(code ${code})`)
|
|
109
|
+
const d = body.data ?? {}
|
|
110
|
+
if (d.idempotent === true) return { state: 'already' }
|
|
111
|
+
const credit = Number(d.reward_amount) || st.rewardAmount || undefined
|
|
112
|
+
return { state: 'signed', ...(credit ? { credit } : {}) }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function createDoubaoProvider({ log = () => {}, env = process.env } = {}) {
|
|
116
|
+
const platform = env.DOUBAO_PLATFORM || process.platform
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
id: 'doubao',
|
|
120
|
+
name: '豆包',
|
|
121
|
+
short: '豆包',
|
|
122
|
+
color: '#3a7afe',
|
|
123
|
+
unit: '额度',
|
|
124
|
+
timeZoneMode: 'fixed',
|
|
125
|
+
timeZone: DOUBAO_TZ,
|
|
126
|
+
|
|
127
|
+
async account() {
|
|
128
|
+
const doubaos = await loadDoubaos(env)
|
|
129
|
+
if (!doubaos.length) {
|
|
130
|
+
return { loggedIn: false, label: '未配置', detail: '需要添加豆包 Cookie(手动粘贴或从浏览器读)', code: 'DOUBAO_NOT_CONFIGURED' }
|
|
131
|
+
}
|
|
132
|
+
return { loggedIn: true, label: '已配置', detail: `${doubaos.length} 个账号` }
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
async needsLogin() {
|
|
136
|
+
return !(await this.account()).loggedIn
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
async panel() {
|
|
140
|
+
const doubaos = await loadDoubaos(env)
|
|
141
|
+
const day = doubaos.length
|
|
142
|
+
return {
|
|
143
|
+
style: 'daily',
|
|
144
|
+
days: [{ dayNo: 1, date: beijingDay(), points: 200, bonusPoints: 0, status: day ? 2 : 1, isToday: true }],
|
|
145
|
+
today: { dayNo: 1, date: beijingDay(), points: 200, bonusPoints: 0, status: day ? 2 : 1, isToday: true },
|
|
146
|
+
claimable: day > 0,
|
|
147
|
+
claimedDays: 0,
|
|
148
|
+
totalPoints: 0,
|
|
149
|
+
accounts: day,
|
|
150
|
+
timeZone: DOUBAO_TZ,
|
|
151
|
+
description: day ? `已配置 ${day} 个豆包账号` : '未配置豆包 Cookie',
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
async run({ trigger = 'manual', dryRun = false } = {}) {
|
|
156
|
+
const doubaos = await loadDoubaos(env)
|
|
157
|
+
if (!doubaos.length) {
|
|
158
|
+
throw Object.assign(new Error('没有配置豆包 Cookie'), { code: 'DOUBAO_NOT_CONFIGURED' })
|
|
159
|
+
}
|
|
160
|
+
const day = beijingDay()
|
|
161
|
+
if (dryRun) {
|
|
162
|
+
return {
|
|
163
|
+
ok: true, outcome: OUTCOME.DRY, provider: 'doubao', trigger, timeZone: DOUBAO_TZ,
|
|
164
|
+
points: 0, day, message: `已配置 ${doubaos.length} 个豆包账号(干跑,不真签)`,
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
let signed = 0
|
|
168
|
+
let already = 0
|
|
169
|
+
let points = 0
|
|
170
|
+
const messages = []
|
|
171
|
+
for (const d of doubaos) {
|
|
172
|
+
const label = d.name || `#${d.id}`
|
|
173
|
+
try {
|
|
174
|
+
const r = await doubaoCheckin(d.cookie, d.seed)
|
|
175
|
+
if (r.state === 'signed') { signed += 1; points += r.credit ?? 0; messages.push(`${label}:+${r.credit ?? '?'} 额度`) }
|
|
176
|
+
else { already += 1; messages.push(`${label}:今天已签`) }
|
|
177
|
+
} catch (error) {
|
|
178
|
+
messages.push(`${label}:失败(${error.message.slice(0, 80)})`)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const ok = signed + already > 0
|
|
182
|
+
const outcome = signed > 0 ? OUTCOME.CLAIMED : already > 0 ? OUTCOME.ALREADY : 'failed'
|
|
183
|
+
const result = {
|
|
184
|
+
ok, outcome, provider: 'doubao', trigger, timeZone: DOUBAO_TZ, points, day,
|
|
185
|
+
message: `豆包:${messages.join(';')}`,
|
|
186
|
+
}
|
|
187
|
+
log(`dsh-checkin-all: [豆包] ${result.message}`)
|
|
188
|
+
if (!ok) throw Object.assign(new Error(result.message), { code: 'DOUBAO_ALL_FAILED' })
|
|
189
|
+
return result
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
async loginStart() {
|
|
193
|
+
throw Object.assign(new Error('豆包要在面板里添加 Cookie(手动粘贴或从浏览器读)'), { code: 'DOUBAO_MANUAL_CONFIG' })
|
|
194
|
+
},
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 从本机浏览器/豆包电脑版自动读 doubao.com 登录 Cookie(供面板「从本机读」用) */
|
|
199
|
+
export async function readLocalDoubaoCookie() {
|
|
200
|
+
const logins = await findDoubaoLogins()
|
|
201
|
+
if (!logins.length) return null
|
|
202
|
+
const cookie = await readDoubaoCookie(logins[0])
|
|
203
|
+
return { cookie, label: logins[0].label }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function beijingDay(now = new Date()) {
|
|
207
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone: DOUBAO_TZ, year: 'numeric', month: '2-digit', day: '2-digit' }).format(now)
|
|
208
|
+
}
|
package/lib/providers/index.js
CHANGED
|
@@ -6,6 +6,9 @@ import { createMinimaxProvider } from './minimax.js'
|
|
|
6
6
|
import { createLingxiProvider } from './lingxi.js'
|
|
7
7
|
import { createDumateProvider } from './dumate.js'
|
|
8
8
|
import { createAstudioProvider } from './astudio.js'
|
|
9
|
+
import { createQoderProvider } from './qoder.js'
|
|
10
|
+
import { createTraeProvider } from './trae.js'
|
|
11
|
+
import { createDoubaoProvider } from './doubao.js'
|
|
9
12
|
|
|
10
13
|
export function createProviders({ log = () => {}, config = async () => ({}), env = process.env } = {}) {
|
|
11
14
|
const list = [
|
|
@@ -13,6 +16,9 @@ export function createProviders({ log = () => {}, config = async () => ({}), env
|
|
|
13
16
|
createLingxiProvider({ log, env }),
|
|
14
17
|
createDumateProvider({ log, env }),
|
|
15
18
|
createAstudioProvider({ log, env }),
|
|
19
|
+
createQoderProvider({ log, env }),
|
|
20
|
+
createTraeProvider({ log, env }),
|
|
21
|
+
createDoubaoProvider({ log, env }),
|
|
16
22
|
]
|
|
17
23
|
const byId = new Map(list.map(p => [p.id, p]))
|
|
18
24
|
return {
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// lib/providers/qoder.js — Qoder 每日签到(领取每日赠送积分)
|
|
2
|
+
//
|
|
3
|
+
// 协议照 dsh-model 的 src/checkin/qoder.ts(原自 G57651/dsh-dual-checkin,MIT),
|
|
4
|
+
// 与 Qoder 桌面端「用量面板」自己的领取链路一致:
|
|
5
|
+
// 个人访问令牌(PAT)→ POST {openApi}/api/v1/jobToken/exchange → 短期 jobToken
|
|
6
|
+
// GET {openApi}/sash/api/v1/me/campaigns 找当天的 CLAIM_BENEFIT 活动
|
|
7
|
+
// POST {openApi}/sash/api/v1/me/campaigns/{id}/claim 幂等:重复领取返回 replayed,不会多发
|
|
8
|
+
// PAT 存在 ~/.dsh/dsh-checkin-all/secrets.json(0600);jobToken 只在内存里用,不落盘。
|
|
9
|
+
//
|
|
10
|
+
// 「今天」按北京时间算。一个服务一张卡片;多账号时 run() 逐个签,汇总结果。
|
|
11
|
+
|
|
12
|
+
import { loadQoders } from '../checkin-secrets.js'
|
|
13
|
+
import { OUTCOME } from './base.js'
|
|
14
|
+
|
|
15
|
+
export const QODER_REGIONS = {
|
|
16
|
+
cn: { label: 'Qoder(国内版)', openApi: 'https://openapi.qoder.com.cn' },
|
|
17
|
+
intl: { label: 'Qoder', openApi: 'https://openapi.qoder.sh' },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const TIMEOUT_MS = 20_000
|
|
21
|
+
const QODER_TZ = 'Asia/Shanghai'
|
|
22
|
+
|
|
23
|
+
async function call(url, init) {
|
|
24
|
+
const res = await fetch(url, { ...init, signal: AbortSignal.timeout(TIMEOUT_MS) })
|
|
25
|
+
const text = await res.text()
|
|
26
|
+
let json = {}
|
|
27
|
+
try { json = text ? JSON.parse(text) : {} } catch { /* 非 JSON */ }
|
|
28
|
+
return { status: res.status, json }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class QoderAuthError extends Error {}
|
|
32
|
+
|
|
33
|
+
/** PAT 换短期 token;PAT 不对就抛 QoderAuthError */
|
|
34
|
+
export async function exchangePat(pat, region) {
|
|
35
|
+
const r = await call(`${QODER_REGIONS[region].openApi}/api/v1/jobToken/exchange`, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: { accept: 'application/json', 'content-type': 'application/json', 'cosy-clienttype': '5', 'cosy-version': '1.0.1', 'user-agent': 'Qoder' },
|
|
38
|
+
body: JSON.stringify({ personal_token: pat }),
|
|
39
|
+
})
|
|
40
|
+
const token = typeof r.json.token === 'string' ? r.json.token : ''
|
|
41
|
+
if (r.status >= 400 || !token) throw new QoderAuthError(`Qoder 个人访问令牌无效或已过期(HTTP ${r.status})`)
|
|
42
|
+
return token
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const headers = (token) => ({ accept: 'application/json', authorization: `Bearer ${token}`, 'cosy-clienttype': '10', 'user-agent': 'Qoder' })
|
|
46
|
+
|
|
47
|
+
const epoch = (v) => {
|
|
48
|
+
if (typeof v === 'number' && Number.isFinite(v) && v > 0) return v >= 1e12 ? v : v * 1000
|
|
49
|
+
if (typeof v === 'string' && v) {
|
|
50
|
+
const t = Date.parse(v)
|
|
51
|
+
return Number.isNaN(t) ? undefined : t
|
|
52
|
+
}
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 当天能领的 CLAIM_BENEFIT 活动 */
|
|
57
|
+
export function claimableCampaign(payload, now = Date.now()) {
|
|
58
|
+
const list = payload?.campaigns ?? payload?.data?.campaigns
|
|
59
|
+
if (!Array.isArray(list)) return undefined
|
|
60
|
+
for (const c of list) {
|
|
61
|
+
if (!c || c.actionType !== 'CLAIM_BENEFIT') continue
|
|
62
|
+
const start = epoch(c.startAt ?? c.beginAt)
|
|
63
|
+
const end = epoch(c.endAt)
|
|
64
|
+
if (start !== undefined && now < start) continue
|
|
65
|
+
if (end !== undefined && now > end) continue
|
|
66
|
+
return c
|
|
67
|
+
}
|
|
68
|
+
return undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const amountOf = (claim, campaign) => {
|
|
72
|
+
const n = Number(claim.data?.benefit?.amount ?? claim.benefit?.amount ?? campaign.benefit?.amount)
|
|
73
|
+
return Number.isFinite(n) && n > 0 ? n : undefined
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 一个 Qoder 账号签到:signed(这次签上)/ already(今天已签);返回送的积分 */
|
|
77
|
+
export async function qoderCheckin(pat, region) {
|
|
78
|
+
const base = QODER_REGIONS[region].openApi
|
|
79
|
+
const token = await exchangePat(pat, region)
|
|
80
|
+
const list = await call(`${base}/sash/api/v1/me/campaigns`, { headers: headers(token) })
|
|
81
|
+
if (list.status === 401 || list.status === 403) throw new QoderAuthError(`Qoder 登录无效(HTTP ${list.status})`)
|
|
82
|
+
if (list.status >= 400) throw new Error(`Qoder 活动列表 HTTP ${list.status}`)
|
|
83
|
+
const campaign = claimableCampaign(list.json)
|
|
84
|
+
if (!campaign) throw new Error('Qoder 现在没有可领取的签到活动(每天滚动发放,稍后会再试)')
|
|
85
|
+
if (campaign.claimStatus === 'CLAIMED') return { state: 'already' }
|
|
86
|
+
const claim = await call(`${base}/sash/api/v1/me/campaigns/${encodeURIComponent(String(campaign.campaignId ?? campaign.id ?? ''))}/claim`, {
|
|
87
|
+
method: 'POST', headers: { ...headers(token), 'content-type': 'application/json' }, body: '{}',
|
|
88
|
+
})
|
|
89
|
+
if (claim.status >= 400) throw new Error(`Qoder 领取失败(HTTP ${claim.status}):${String(claim.json?.message ?? '').slice(0, 120)}`)
|
|
90
|
+
const body = (typeof claim.json.data === 'object' && claim.json.data !== null ? claim.json.data : claim.json)
|
|
91
|
+
if (body.replayed === true) return { state: 'already' }
|
|
92
|
+
if (body.status !== 'CLAIMED' && body.success !== true) throw new Error(`Qoder 签到返回异常:${JSON.stringify(claim.json).slice(0, 160)}`)
|
|
93
|
+
const credit = amountOf(claim.json, campaign)
|
|
94
|
+
return { state: 'signed', ...(credit !== undefined ? { credit } : {}) }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function createQoderProvider({ log = () => {}, env = process.env } = {}) {
|
|
98
|
+
return {
|
|
99
|
+
id: 'qoder',
|
|
100
|
+
name: 'Qoder',
|
|
101
|
+
short: 'Qoder',
|
|
102
|
+
color: '#e05a1a',
|
|
103
|
+
unit: '积分',
|
|
104
|
+
timeZoneMode: 'fixed',
|
|
105
|
+
timeZone: QODER_TZ,
|
|
106
|
+
|
|
107
|
+
async account() {
|
|
108
|
+
const qoders = await loadQoders(env)
|
|
109
|
+
if (!qoders.length) {
|
|
110
|
+
return { loggedIn: false, label: '未配置', detail: '需要添加 Qoder 个人访问令牌', code: 'QODER_NOT_CONFIGURED' }
|
|
111
|
+
}
|
|
112
|
+
const labels = qoders.map((q) => {
|
|
113
|
+
const region = q.region === 'cn' ? '国内版' : ''
|
|
114
|
+
const tag = q.name || (qoders.length > 1 ? `#${q.id}` : '')
|
|
115
|
+
return tag ? `Qoder(${[tag, region].filter(Boolean).join(' · ')})` : QODER_REGIONS[q.region].label
|
|
116
|
+
})
|
|
117
|
+
return { loggedIn: true, label: '已配置', detail: `${qoders.length} 个令牌`, accounts: labels }
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
async needsLogin() {
|
|
121
|
+
return !(await this.account()).loggedIn
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
/** 面板:Qoder 每天都有签到活动,这里只显示「今天可领」,真正的幂等由上游保证 */
|
|
125
|
+
async panel() {
|
|
126
|
+
const qoders = await loadQoders(env)
|
|
127
|
+
const day = qoders.length
|
|
128
|
+
return {
|
|
129
|
+
style: 'daily',
|
|
130
|
+
days: [{ dayNo: 1, date: beijingDay(), points: 0, bonusPoints: 0, status: day ? 2 : 1, isToday: true }],
|
|
131
|
+
today: { dayNo: 1, date: beijingDay(), points: 0, bonusPoints: 0, status: day ? 2 : 1, isToday: true },
|
|
132
|
+
claimable: day > 0,
|
|
133
|
+
claimedDays: 0,
|
|
134
|
+
totalPoints: 0,
|
|
135
|
+
accountCredits: undefined,
|
|
136
|
+
accounts: day,
|
|
137
|
+
timeZone: QODER_TZ,
|
|
138
|
+
description: day ? `已配置 ${day} 个 Qoder 令牌` : '未配置 Qoder 令牌',
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
async run({ trigger = 'manual', dryRun = false } = {}) {
|
|
143
|
+
const qoders = await loadQoders(env)
|
|
144
|
+
if (!qoders.length) {
|
|
145
|
+
throw Object.assign(new Error('没有配置 Qoder 个人访问令牌'), { code: 'QODER_NOT_CONFIGURED' })
|
|
146
|
+
}
|
|
147
|
+
const day = beijingDay()
|
|
148
|
+
if (dryRun) {
|
|
149
|
+
return {
|
|
150
|
+
ok: true, outcome: OUTCOME.DRY, provider: 'qoder', trigger, timeZone: QODER_TZ,
|
|
151
|
+
points: 0, day, message: `已配置 ${qoders.length} 个 Qoder 令牌(干跑,不真签)`,
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
let signed = 0
|
|
155
|
+
let already = 0
|
|
156
|
+
let points = 0
|
|
157
|
+
const messages = []
|
|
158
|
+
for (const q of qoders) {
|
|
159
|
+
try {
|
|
160
|
+
const r = await qoderCheckin(q.pat, q.region)
|
|
161
|
+
if (r.state === 'signed') { signed += 1; points += r.credit ?? 0; messages.push(`${q.name || `#${q.id}`}:+${r.credit ?? '?'} 积分`) }
|
|
162
|
+
else { already += 1; messages.push(`${q.name || `#${q.id}`}:今天已签`) }
|
|
163
|
+
} catch (error) {
|
|
164
|
+
messages.push(`${q.name || `#${q.id}`}:失败(${error.message.slice(0, 80)})`)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const ok = signed + already > 0
|
|
168
|
+
const outcome = signed > 0 ? OUTCOME.CLAIMED : already > 0 ? OUTCOME.ALREADY : 'failed'
|
|
169
|
+
const result = {
|
|
170
|
+
ok,
|
|
171
|
+
outcome,
|
|
172
|
+
provider: 'qoder',
|
|
173
|
+
trigger,
|
|
174
|
+
timeZone: QODER_TZ,
|
|
175
|
+
points,
|
|
176
|
+
day,
|
|
177
|
+
message: `Qoder:${messages.join(';')}`,
|
|
178
|
+
}
|
|
179
|
+
log(`dsh-checkin-all: [Qoder] ${result.message}`)
|
|
180
|
+
if (!ok) throw Object.assign(new Error(result.message), { code: 'QODER_ALL_FAILED' })
|
|
181
|
+
return result
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
async loginStart() {
|
|
185
|
+
throw Object.assign(new Error('Qoder 要在面板里添加个人访问令牌(PAT)'), { code: 'QODER_MANUAL_CONFIG' })
|
|
186
|
+
},
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** 北京时间的 YYYY-MM-DD */
|
|
191
|
+
function beijingDay(now = new Date()) {
|
|
192
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone: QODER_TZ, year: 'numeric', month: '2-digit', day: '2-digit' }).format(now)
|
|
193
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// lib/providers/trae.js — Trae(国内版 / SOLO)每日签到
|
|
2
|
+
//
|
|
3
|
+
// 登录信息复用本机已登录的 Trae 桌面 App 或 CLI(只读,不落盘,只在内存里用):
|
|
4
|
+
// 1) 桌面 App:<应用数据>/{TRAE SOLO CN | Trae CN | Trae | TRAE SOLO}/User/globalStorage/storage.json
|
|
5
|
+
// 里的 iCubeAuthInfo://icube.cloudide(加密信封)
|
|
6
|
+
// 2) CLI:~/.trae-cn/trae-jwt-token、~/.trae/trae-jwt-token
|
|
7
|
+
// 解密算法、接口与请求头照 dsh-model 的 src/checkin/trae.ts(原自 G57651/dsh-dual-checkin,MIT)。
|
|
8
|
+
// POST https://api.trae.cn/trae/api/v2/ug/checkin_credits/status 今天签没签、能领多少
|
|
9
|
+
// POST https://api.trae.cn/trae/api/v2/ug/checkin_credits/claim 签到
|
|
10
|
+
|
|
11
|
+
import { createDecipheriv, createHash, randomUUID } from 'node:crypto'
|
|
12
|
+
import { readFile } from 'node:fs/promises'
|
|
13
|
+
import { homedir } from 'node:os'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
import { OUTCOME } from './base.js'
|
|
16
|
+
|
|
17
|
+
const API = 'https://api.trae.cn'
|
|
18
|
+
const AUTH_KEY = 'iCubeAuthInfo://icube.cloudide'
|
|
19
|
+
const DEVICE_PREFIX = 'iCubeAuthInfo://icube-dc:'
|
|
20
|
+
const APPS = ['TRAE SOLO CN', 'Trae CN', 'Trae', 'TRAE SOLO']
|
|
21
|
+
const TRAE_TZ = 'Asia/Shanghai'
|
|
22
|
+
|
|
23
|
+
const SALT_A = Uint8Array.from([82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195, 78, 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209, 37])
|
|
24
|
+
const SALT_B = Uint8Array.from([31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, 96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, 160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125])
|
|
25
|
+
const SALT_C = Uint8Array.from([191, 192, 216, 250, 122, 246, 220, 97, 31, 254, 98, 27, 8, 72, 71, 176, 135, 99, 96, 18, 127, 101, 203, 104, 211, 102, 191, 125, 37, 72, 150, 156, 51, 229, 121, 35, 17, 153, 141, 177, 110, 131, 150, 128, 172, 255, 254, 6, 18, 140, 55, 62, 236, 249, 135, 64, 135, 12, 117, 4, 89, 149, 168, 209])
|
|
26
|
+
const SALT_D = Uint8Array.from([246, 204, 26, 232, 232, 70, 129, 109, 223, 146, 169, 242, 23, 241, 105, 145, 50, 196, 165, 42, 254, 120, 3, 54, 244, 207, 209, 85, 53, 6, 138, 106, 175, 148, 31, 204, 186, 186, 165, 182, 87, 142, 49, 10, 39, 110, 26, 154, 86, 56, 173, 125, 18, 64, 198, 225, 99, 99, 83, 82, 191, 134, 76, 170])
|
|
27
|
+
|
|
28
|
+
const xor = (a, b) => Buffer.from(a.map((v, i) => v ^ (b[i] ?? 0)))
|
|
29
|
+
|
|
30
|
+
/** 解开 storage.json 里的加密信封。导出给测试 */
|
|
31
|
+
export function decryptStorageValue(encoded) {
|
|
32
|
+
const buf = Buffer.from(encoded, 'base64')
|
|
33
|
+
if (buf.length <= 102) throw new Error('Trae 登录信息太短')
|
|
34
|
+
const header = buf.subarray(0, 6)
|
|
35
|
+
const kind = header.equals(Buffer.from([116, 99, 5, 16, 0, 0])) ? 'aes' : header.equals(Buffer.from([18, 57, 32, 32, 2, 3])) ? 'aes-private' : null
|
|
36
|
+
if (!kind) throw new Error('Trae 登录信息的加密格式不认识(Trae 可能又改版了)')
|
|
37
|
+
const salt = kind === 'aes-private' ? xor(SALT_C, SALT_D) : xor(SALT_A, SALT_B)
|
|
38
|
+
const first = createHash('sha512').update(buf.subarray(6, 38)).digest()
|
|
39
|
+
const derived = createHash('sha512').update(Buffer.concat([first, salt])).digest()
|
|
40
|
+
const decipher = createDecipheriv('aes-128-cbc', derived.subarray(0, 16), derived.subarray(16, 32))
|
|
41
|
+
const out = Buffer.concat([decipher.update(buf.subarray(38)), decipher.final()])
|
|
42
|
+
if (out.length < 64) throw new Error('Trae 登录信息解开后太短')
|
|
43
|
+
const plain = out.subarray(64)
|
|
44
|
+
if (!out.subarray(0, 64).equals(createHash('sha512').update(plain).digest())) throw new Error('Trae 登录信息校验不通过')
|
|
45
|
+
return plain.toString('utf8')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** JWT 里的账号 id(data.id);读不出来返回 undefined */
|
|
49
|
+
export function tokenAccountId(token) {
|
|
50
|
+
try {
|
|
51
|
+
const p = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString())
|
|
52
|
+
const id = p.data?.id ?? p.sub
|
|
53
|
+
return id === undefined || id === null || id === '' ? undefined : String(id)
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 各平台的应用数据目录 */
|
|
60
|
+
function appDataRoots(home, platform = process.platform, env = process.env) {
|
|
61
|
+
if (platform === 'darwin') return [join(home, 'Library', 'Application Support')]
|
|
62
|
+
if (platform === 'win32') return [...new Set([env.APPDATA, join(home, 'AppData', 'Roaming')].filter(Boolean))]
|
|
63
|
+
return [env.XDG_CONFIG_HOME || join(home, '.config')]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function readTraeCredentials(home, platform = process.platform, env = process.env) {
|
|
67
|
+
if (process.env.DSH_CHECKIN_NO_APP_DISCOVERY && home === homedir()) return []
|
|
68
|
+
const found = []
|
|
69
|
+
for (const root of appDataRoots(home, platform, env)) {
|
|
70
|
+
for (const app of APPS) {
|
|
71
|
+
const file = join(root, app, 'User', 'globalStorage', 'storage.json')
|
|
72
|
+
try {
|
|
73
|
+
const storage = JSON.parse(await readFile(file, 'utf8'))
|
|
74
|
+
const raw = storage[AUTH_KEY]
|
|
75
|
+
if (typeof raw !== 'string' || !raw.trim()) continue
|
|
76
|
+
const text = raw.trim().startsWith('{') ? raw : decryptStorageValue(raw)
|
|
77
|
+
const auth = JSON.parse(text)
|
|
78
|
+
const token = auth.token || auth.accessToken
|
|
79
|
+
if (!token) continue
|
|
80
|
+
const dc = Object.keys(storage).find((k) => k.startsWith(DEVICE_PREFIX))
|
|
81
|
+
const accountId = auth.userId !== undefined && auth.userId !== null && auth.userId !== '' ? String(auth.userId) : tokenAccountId(token)
|
|
82
|
+
found.push({ token, deviceId: dc ? dc.slice(DEVICE_PREFIX.length) : String(storage['telemetry.devDeviceId'] ?? ''), source: app, ...(accountId ? { accountId } : {}) })
|
|
83
|
+
} catch {
|
|
84
|
+
// 没装、读不了或解不开:看下一个
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const dir of ['.trae-cn', '.trae']) {
|
|
89
|
+
try {
|
|
90
|
+
const text = (await readFile(join(home, dir, 'trae-jwt-token'), 'utf8')).trim()
|
|
91
|
+
const token = text.startsWith('{') ? String((JSON.parse(text).token ?? '')) : text
|
|
92
|
+
const accountId = tokenAccountId(token)
|
|
93
|
+
if (token.split('.').length === 3) found.push({ token, deviceId: '', source: `~/${dir}`, ...(accountId ? { accountId } : {}) })
|
|
94
|
+
} catch {
|
|
95
|
+
// 没有
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return found
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 几份登录里挑一份:没过期的优先 → 带设备 id 的(桌面 App)优先 → 到期最晚的。导出给测试 */
|
|
102
|
+
export function pickTraeCredential(list, now = Date.now()) {
|
|
103
|
+
const exp = (t) => {
|
|
104
|
+
const d = tokenDaysLeft(t, now)
|
|
105
|
+
return d === null ? Number.POSITIVE_INFINITY : d
|
|
106
|
+
}
|
|
107
|
+
const ranked = [...list].sort((a, b) => {
|
|
108
|
+
const live = Number(exp(b.token) >= 0) - Number(exp(a.token) >= 0)
|
|
109
|
+
if (live) return live
|
|
110
|
+
const desktop = Number(Boolean(b.deviceId)) - Number(Boolean(a.deviceId))
|
|
111
|
+
if (desktop) return desktop
|
|
112
|
+
return exp(b.token) - exp(a.token)
|
|
113
|
+
})
|
|
114
|
+
return ranked[0] ?? null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 令牌还剩几天(读 JWT 的 exp);读不出来返回 null */
|
|
118
|
+
export function tokenDaysLeft(token, now = Date.now()) {
|
|
119
|
+
try {
|
|
120
|
+
const exp = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString()).exp
|
|
121
|
+
return typeof exp === 'number' ? Math.floor((exp * 1000 - now) / 86_400_000) : null
|
|
122
|
+
} catch {
|
|
123
|
+
return null
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 本机的每个 Trae 账号各一份登录(同一个账号装了几个 Trae 只算一个),第一个是最该用的 */
|
|
128
|
+
export async function findTraeCredentials(home = homedir(), platform = process.platform, env = process.env) {
|
|
129
|
+
const found = await readTraeCredentials(home, platform, env)
|
|
130
|
+
const groups = new Map()
|
|
131
|
+
for (const c of found) {
|
|
132
|
+
const key = c.accountId ?? `?${c.source}`
|
|
133
|
+
groups.set(key, [...(groups.get(key) ?? []), c])
|
|
134
|
+
}
|
|
135
|
+
const best = [...groups.values()].map((g) => pickTraeCredential(g)).filter(Boolean)
|
|
136
|
+
const first = pickTraeCredential(best)
|
|
137
|
+
return first ? [first, ...best.filter((c) => c !== first)] : []
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function headers(c) {
|
|
141
|
+
return {
|
|
142
|
+
authorization: `Cloud-IDE-JWT ${c.token}`,
|
|
143
|
+
'content-type': 'application/json',
|
|
144
|
+
'user-agent': 'VSCode 1.107.1 (TRAE SOLO CN)',
|
|
145
|
+
'x-user-region': 'CN',
|
|
146
|
+
'package-type': 'stable_cn',
|
|
147
|
+
'x-lscbd-aid': '787976',
|
|
148
|
+
'x-lscbd-platform': 'windows',
|
|
149
|
+
'app-version': '0.1.51',
|
|
150
|
+
accept: '*/*',
|
|
151
|
+
'x-request-id': randomUUID().replace(/-/g, ''),
|
|
152
|
+
'x-device-brand': 'To be filled by O.E.M.',
|
|
153
|
+
'x-device-type': 'windows',
|
|
154
|
+
'x-lgw-req-sdk-type': '3',
|
|
155
|
+
...(c.deviceId ? { 'x-device-id': c.deviceId } : {}),
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function post(c, path) {
|
|
160
|
+
const res = await fetch(`${API}${path}`, { method: 'POST', headers: headers(c), body: '{}', signal: AbortSignal.timeout(20_000) })
|
|
161
|
+
const text = await res.text()
|
|
162
|
+
if (res.status === 401 || res.status === 403) throw new Error(`Trae 登录无效或已过期(HTTP ${res.status})`)
|
|
163
|
+
if (!res.ok) throw new Error(`Trae HTTP ${res.status}: ${text.slice(0, 160)}`)
|
|
164
|
+
return text ? JSON.parse(text) : {}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 今天签没签、签到送多少 */
|
|
168
|
+
export async function traeStatus(c) {
|
|
169
|
+
const r = await post(c, '/trae/api/v2/ug/checkin_credits/status')
|
|
170
|
+
if (r.code && r.code !== 0) throw new Error(`Trae 查询签到状态失败(code ${String(r.code)}:${String(r.message ?? '')})${/1001|authent/i.test(String(r.message ?? r.code)) ? ',令牌可能过期,请重新登录 Trae' : ''}`)
|
|
171
|
+
const d = (typeof r.data === 'object' && r.data !== null ? r.data : r)
|
|
172
|
+
const credits = (typeof d.credits === 'number' ? d.credits : 0) + (typeof d.extra_credits === 'number' ? d.extra_credits : 0)
|
|
173
|
+
return { checkedIn: d.checked_in === true, ...(credits ? { credits } : {}) }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export async function traeCheckin(c) {
|
|
177
|
+
const st = await traeStatus(c)
|
|
178
|
+
if (st.checkedIn) return { state: 'already' }
|
|
179
|
+
const r = await post(c, '/trae/api/v2/ug/checkin_credits/claim')
|
|
180
|
+
if (r.code !== undefined && r.code !== 0) throw new Error(`Trae 签到失败(code ${String(r.code)}:${String(r.message ?? '')})`)
|
|
181
|
+
return { state: 'signed', ...(st.credits ? { credit: st.credits } : {}) }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function createTraeProvider({ log = () => {}, env = process.env } = {}) {
|
|
185
|
+
const creds = () => findTraeCredentials(env.HOME || env.USERPROFILE || homedir(), env.TRAE_PLATFORM || process.platform, env)
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
id: 'trae',
|
|
189
|
+
name: 'Trae',
|
|
190
|
+
short: 'Trae',
|
|
191
|
+
color: '#6b3fa0',
|
|
192
|
+
unit: '积分',
|
|
193
|
+
timeZoneMode: 'fixed',
|
|
194
|
+
timeZone: TRAE_TZ,
|
|
195
|
+
|
|
196
|
+
async account() {
|
|
197
|
+
const list = await creds()
|
|
198
|
+
if (!list.length) {
|
|
199
|
+
return { loggedIn: false, label: '未登录', detail: '这台机器没装/没登录 Trae', code: 'TRAE_NOT_LOGGED_IN' }
|
|
200
|
+
}
|
|
201
|
+
return { loggedIn: true, label: '已登录', detail: `${list.length} 个账号` }
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
async needsLogin() {
|
|
205
|
+
return !(await this.account()).loggedIn
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
async panel() {
|
|
209
|
+
const list = await creds()
|
|
210
|
+
const day = list.length
|
|
211
|
+
return {
|
|
212
|
+
style: 'daily',
|
|
213
|
+
days: [{ dayNo: 1, date: beijingDay(), points: 0, bonusPoints: 0, status: day ? 2 : 1, isToday: true }],
|
|
214
|
+
today: { dayNo: 1, date: beijingDay(), points: 0, bonusPoints: 0, status: day ? 2 : 1, isToday: true },
|
|
215
|
+
claimable: day > 0,
|
|
216
|
+
claimedDays: 0,
|
|
217
|
+
totalPoints: 0,
|
|
218
|
+
accounts: day,
|
|
219
|
+
timeZone: TRAE_TZ,
|
|
220
|
+
description: day ? `本机有 ${day} 个 Trae 账号` : '这台机器没装/没登录 Trae',
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
async run({ trigger = 'manual', dryRun = false } = {}) {
|
|
225
|
+
const list = await creds()
|
|
226
|
+
if (!list.length) {
|
|
227
|
+
throw Object.assign(new Error('这台机器没装/没登录 Trae(要在装了 Trae 的电脑上签)'), { code: 'TRAE_NOT_LOGGED_IN' })
|
|
228
|
+
}
|
|
229
|
+
const day = beijingDay()
|
|
230
|
+
if (dryRun) {
|
|
231
|
+
return {
|
|
232
|
+
ok: true, outcome: OUTCOME.DRY, provider: 'trae', trigger, timeZone: TRAE_TZ,
|
|
233
|
+
points: 0, day, message: `本机有 ${list.length} 个 Trae 账号(干跑,不真签)`,
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
let signed = 0
|
|
237
|
+
let already = 0
|
|
238
|
+
let points = 0
|
|
239
|
+
const messages = []
|
|
240
|
+
for (const t of list) {
|
|
241
|
+
const label = t.accountId ? `…${t.accountId.slice(-4)}` : t.source
|
|
242
|
+
try {
|
|
243
|
+
const r = await traeCheckin(t)
|
|
244
|
+
if (r.state === 'signed') { signed += 1; points += r.credit ?? 0; messages.push(`${label}:+${r.credit ?? '?'} 积分`) }
|
|
245
|
+
else { already += 1; messages.push(`${label}:今天已签`) }
|
|
246
|
+
} catch (error) {
|
|
247
|
+
messages.push(`${label}:失败(${error.message.slice(0, 80)})`)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const ok = signed + already > 0
|
|
251
|
+
const outcome = signed > 0 ? OUTCOME.CLAIMED : already > 0 ? OUTCOME.ALREADY : 'failed'
|
|
252
|
+
const result = {
|
|
253
|
+
ok, outcome, provider: 'trae', trigger, timeZone: TRAE_TZ, points, day,
|
|
254
|
+
message: `Trae:${messages.join(';')}`,
|
|
255
|
+
}
|
|
256
|
+
log(`dsh-checkin-all: [Trae] ${result.message}`)
|
|
257
|
+
if (!ok) throw Object.assign(new Error(result.message), { code: 'TRAE_ALL_FAILED' })
|
|
258
|
+
return result
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
async loginStart() {
|
|
262
|
+
throw Object.assign(new Error('Trae 的登录在 Trae App 里完成:打开 Trae 登录一次'), { code: 'TRAE_MANUAL_LOGIN' })
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function beijingDay(now = new Date()) {
|
|
268
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone: TRAE_TZ, year: 'numeric', month: '2-digit', day: '2-digit' }).format(now)
|
|
269
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-checkin-all",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "每日自动签到领积分:MiniMax Code、WPS 灵犀、百度 DuMate 一键签到打卡,连续签到不断签。支持 check-in / sign-in / 签到 / 打卡 / 每日领取 / 积分 / 智点,面板按服务切换卡片,本机凭据零配置,签完记账。DeepSeek Harness (dsh) 插件。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh-plugin",
|
package/web/panel.js
CHANGED
|
@@ -155,7 +155,7 @@ function renderDetail() {
|
|
|
155
155
|
|
|
156
156
|
<section class="card">
|
|
157
157
|
<div class="card-head">
|
|
158
|
-
<h2>本周签到表</h2>
|
|
158
|
+
<h2 id="week-title">本周签到表</h2>
|
|
159
159
|
<button class="btn tiny" id="btn-refresh">刷新</button>
|
|
160
160
|
</div>
|
|
161
161
|
<div id="week" class="week"><span class="muted">读取中…</span></div>
|
|
@@ -211,29 +211,49 @@ function renderWeek(panel) {
|
|
|
211
211
|
box.innerHTML = '<span class="muted">签到表读不出来</span>'
|
|
212
212
|
return
|
|
213
213
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
214
|
+
|
|
215
|
+
// 「每日登录积分」型服务(如 AStudio):只显示今天一天,标题改成「每日登录」
|
|
216
|
+
const isDaily = panel.style === 'daily'
|
|
217
|
+
const title = $('#week-title')
|
|
218
|
+
if (title) title.textContent = isDaily ? '每日登录积分' : '本周签到表'
|
|
219
|
+
|
|
220
|
+
if (isDaily) {
|
|
221
|
+
const day = panel.days[0]
|
|
222
|
+
const done = day.status === 3
|
|
223
|
+
box.innerHTML = `<div class="day ${done ? 'claimed' : 'claimable'} today">
|
|
224
|
+
<div class="no">今天</div>
|
|
225
|
+
<div class="pts">+${day.points}</div>
|
|
226
|
+
<div class="tag">${done ? '已到账' : '可领取'}</div>
|
|
222
227
|
</div>`
|
|
223
|
-
}
|
|
228
|
+
} else {
|
|
229
|
+
box.innerHTML = panel.days.map((day) => {
|
|
230
|
+
const cls = day.status === 3 ? 'claimed' : day.status === 2 ? 'claimable' : ''
|
|
231
|
+
const bonus = day.bonusPoints ? `<div class="tag">+${day.bonusPoints} 奖励</div>` : ''
|
|
232
|
+
return `<div class="day ${cls}${day.isToday ? ' today' : ''}">
|
|
233
|
+
<div class="no">第 ${day.dayNo} 天</div>
|
|
234
|
+
<div class="pts">${day.points}</div>
|
|
235
|
+
<div class="tag">${STATUS_TAG[day.status] || day.status}</div>
|
|
236
|
+
${bonus}
|
|
237
|
+
</div>`
|
|
238
|
+
}).join('')
|
|
239
|
+
}
|
|
224
240
|
|
|
225
241
|
const note = $('#week-note')
|
|
226
242
|
if (!note) return
|
|
227
243
|
const parts = []
|
|
228
|
-
if (
|
|
244
|
+
if (isDaily) {
|
|
245
|
+
parts.push(panel.today.status === 3
|
|
246
|
+
? `今天已自动到账 +${panel.today.points} 积分`
|
|
247
|
+
: `今天可领取 +${panel.today.points} 积分`)
|
|
248
|
+
} else if (panel.today) {
|
|
229
249
|
parts.push(panel.today.status === 3
|
|
230
250
|
? `今天(第 ${panel.today.dayNo} 天)已签,+${panel.today.points + panel.today.bonusPoints}`
|
|
231
251
|
: panel.today.status === 2
|
|
232
252
|
? `今天(第 ${panel.today.dayNo} 天)还没签,可领 ${panel.today.points + panel.today.bonusPoints}`
|
|
233
253
|
: `今天(第 ${panel.today.dayNo} 天)不可领`)
|
|
234
254
|
}
|
|
235
|
-
if (panel.consecutiveDays !== undefined) parts.push(`连续 ${panel.consecutiveDays} 天`)
|
|
236
|
-
parts.push(`本周已领 ${panel.claimedDays} 天,共 ${panel.totalPoints}`)
|
|
255
|
+
if (!isDaily && panel.consecutiveDays !== undefined) parts.push(`连续 ${panel.consecutiveDays} 天`)
|
|
256
|
+
if (!isDaily) parts.push(`本周已领 ${panel.claimedDays} 天,共 ${panel.totalPoints}`)
|
|
237
257
|
if (panel.accountCredits) parts.push(`账户累计 ${panel.accountCredits}`)
|
|
238
258
|
note.textContent = parts.join(' · ')
|
|
239
259
|
note.classList.remove('hidden')
|