dsh-checkin-all 0.6.0 → 0.7.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 +18 -0
- package/bin/dsh-checkin-all.js +58 -0
- package/lib/checkin-secrets.js +42 -5
- package/lib/providers/astudio.js +6 -1
- package/lib/providers/dumate.js +20 -0
- package/lib/providers/lingxi.js +6 -0
- package/lib/providers/trae.js +9 -1
- package/lib/server.js +28 -2
- package/package.json +1 -1
- package/web/panel.js +116 -2
package/README.md
CHANGED
|
@@ -65,6 +65,24 @@ node bin/dsh-checkin-all.js time 08:30 # 改自动签到时间
|
|
|
65
65
|
node bin/dsh-checkin-all.js on | off # 开 / 关自动签到
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
### 手动配置凭据(VPS 等没有 App 的机器)
|
|
69
|
+
|
|
70
|
+
灵犀、搭子、AStudio、Trae 默认读本机 App 的登录文件;在 VPS 上或没有装对应 App 时,
|
|
71
|
+
可以手动配置凭据(存 `~/.dsh/dsh-checkin-all/secrets.json`,0600):
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
node bin/dsh-checkin-all.js set lingxi "<wps_sid>"
|
|
75
|
+
node bin/dsh-checkin-all.js set dumate "<完整 Cookie 串,含 bce-user-info>"
|
|
76
|
+
node bin/dsh-checkin-all.js set astudio "<accountId>,<token>,<ssoSessionId>"
|
|
77
|
+
node bin/dsh-checkin-all.js set trae "<Cloud-IDE-JWT token>"
|
|
78
|
+
|
|
79
|
+
node bin/dsh-checkin-all.js unset lingxi # 删除某个服务的手动凭据,回退到 App 文件
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
手动配置优先于 App 文件;删掉手动凭据后自动回退读 App。
|
|
83
|
+
|
|
84
|
+
也可以在面板里操作:打开对话页右侧栏「自动签到」,切到对应服务卡,点「配置凭据」,粘贴值保存即可(清除后回退 App 文件)。
|
|
85
|
+
|
|
68
86
|
### 不依赖 DSH 常驻:挂到系统 crontab
|
|
69
87
|
|
|
70
88
|
```cron
|
package/bin/dsh-checkin-all.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import { Runner } from '../lib/runner.js'
|
|
17
17
|
import { loadConfig, loadState, saveConfig, providerConfig } from '../lib/store.js'
|
|
18
|
+
import { setManual, getManual, loadSecrets } from '../lib/checkin-secrets.js'
|
|
18
19
|
|
|
19
20
|
const argv = process.argv.slice(2)
|
|
20
21
|
const command = (argv[0] || 'status').toLowerCase()
|
|
@@ -148,10 +149,67 @@ async function main() {
|
|
|
148
149
|
return
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
if (command === 'set' || command === 'cred' || command === '手动配置') {
|
|
153
|
+
const provider = rest[0]
|
|
154
|
+
const value = rest.slice(1).join(' ').trim()
|
|
155
|
+
if (!provider || !value) {
|
|
156
|
+
console.error('用法:dsh-checkin-all set <服务> <值>')
|
|
157
|
+
console.error(' lingxi → wps_sid 的值')
|
|
158
|
+
console.error(' dumate → 完整 Cookie 串(含 bce-user-info)')
|
|
159
|
+
console.error(' astudio → "accountId,token,ssoSessionId"(逗号分隔)')
|
|
160
|
+
console.error(' trae → Cloud-IDE-JWT token')
|
|
161
|
+
process.exitCode = 2
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
if (provider === 'astudio') {
|
|
165
|
+
const [accountId, token, ssoSessionId] = value.split(',').map(s => s.trim())
|
|
166
|
+
if (!accountId || !token) {
|
|
167
|
+
console.error('AStudio 需要 accountId 和 token(用逗号分隔)')
|
|
168
|
+
process.exitCode = 2
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
await setManual('astudio', { accountId, token, ...(ssoSessionId ? { ssoSessionId } : {}) })
|
|
172
|
+
console.log('已保存 AStudio 手动凭据')
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
if (provider === 'lingxi') {
|
|
176
|
+
await setManual('lingxi', { wps_sid: value })
|
|
177
|
+
console.log('已保存灵犀 wps_sid')
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
if (provider === 'dumate') {
|
|
181
|
+
await setManual('dumate', { cookie: value })
|
|
182
|
+
console.log('已保存搭子 Cookie')
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
if (provider === 'trae') {
|
|
186
|
+
await setManual('trae', { token: value })
|
|
187
|
+
console.log('已保存 Trae token')
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
console.error(`不认识的服务:${provider}(只能是 lingxi / dumate / astudio / trae)`)
|
|
191
|
+
process.exitCode = 2
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (command === 'unset' || command === '删配置') {
|
|
196
|
+
const provider = rest[0]
|
|
197
|
+
if (!provider) {
|
|
198
|
+
console.error('用法:dsh-checkin-all unset <服务>')
|
|
199
|
+
process.exitCode = 2
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
await setManual(provider, null)
|
|
203
|
+
console.log(`已删除 ${provider} 的手动凭据`)
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
151
207
|
console.log(`用法:
|
|
152
208
|
dsh-checkin-all status 所有服务:登录状态 + 本周签到表
|
|
153
209
|
dsh-checkin-all checkin [服务] 立刻签到(--dry 只看不领)
|
|
154
210
|
dsh-checkin-all login 设备码登录 MiniMax Code
|
|
211
|
+
dsh-checkin-all set <服务> <值> 手动配置凭据(lingxi/dumate/astudio/trae)
|
|
212
|
+
dsh-checkin-all unset <服务> 删除某个服务的手动凭据
|
|
155
213
|
dsh-checkin-all time 08:30 改自动签到时间
|
|
156
214
|
dsh-checkin-all on | off 开 / 关自动签到
|
|
157
215
|
dsh-checkin-all cron 给系统 crontab 用的静默签到
|
package/lib/checkin-secrets.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
// lib/checkin-secrets.js — Qoder PAT / 豆包 Cookie
|
|
1
|
+
// lib/checkin-secrets.js — 签到凭据存储(手动配置 + Qoder PAT / 豆包 Cookie)
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// 分开存,文件 0600。Trae 不在这里——它读本机 Trae App 的登录,不需要用户填。
|
|
3
|
+
// 这些是用户填写的签到凭据,和设置/历史分开存,文件 0600。
|
|
5
4
|
//
|
|
6
5
|
// 结构(~/.dsh/dsh-checkin-all/secrets.json):
|
|
7
|
-
// { "
|
|
8
|
-
//
|
|
6
|
+
// { "checkin": {
|
|
7
|
+
// "qoders": [{ id, pat, region, name?, savedAt? }],
|
|
8
|
+
// "doubaos": [{ id, cookie, seed, name?, from?, savedAt? }],
|
|
9
|
+
// "manual": {
|
|
10
|
+
// "lingxi": { wps_sid },
|
|
11
|
+
// "dumate": { cookie }, // 完整 Cookie 串,含 bce-user-info(csrftoken)
|
|
12
|
+
// "astudio": { accountId, token, ssoSessionId? },
|
|
13
|
+
// "trae": { token } // Cloud-IDE-JWT
|
|
14
|
+
// }
|
|
15
|
+
// } }
|
|
16
|
+
//
|
|
17
|
+
// manual 里的每项都能让服务独立配置,不依赖本机 App 文件(VPS 上也能用)。
|
|
9
18
|
|
|
10
19
|
import { randomBytes } from 'node:crypto'
|
|
11
20
|
import { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'
|
|
@@ -57,6 +66,34 @@ export function cookieValue(cookie, name) {
|
|
|
57
66
|
return undefined
|
|
58
67
|
}
|
|
59
68
|
|
|
69
|
+
// ── 手动配置(灵犀 / 搭子 / AStudio / Trae 的独立凭据)──
|
|
70
|
+
|
|
71
|
+
export async function loadManual(env = process.env) {
|
|
72
|
+
const secrets = await loadSecrets(env)
|
|
73
|
+
return secrets.checkin?.manual ?? {}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 读某个服务的手动凭据;没有返回 null */
|
|
77
|
+
export async function getManual(provider, env = process.env) {
|
|
78
|
+
const manual = await loadManual(env)
|
|
79
|
+
return manual[provider] && typeof manual[provider] === 'object' ? manual[provider] : null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 写某个服务的手动凭据(传 null 删除) */
|
|
83
|
+
export async function setManual(provider, entry, env = process.env) {
|
|
84
|
+
const secrets = await loadSecrets(env)
|
|
85
|
+
const checkin = { ...(secrets.checkin || {}) }
|
|
86
|
+
const manual = { ...(checkin.manual || {}) }
|
|
87
|
+
if (entry === null) delete manual[provider]
|
|
88
|
+
else manual[provider] = { ...(manual[provider] || {}), ...entry }
|
|
89
|
+
if (Object.keys(manual).length) checkin.manual = manual
|
|
90
|
+
else delete checkin.manual
|
|
91
|
+
if (Object.keys(checkin).length) secrets.checkin = checkin
|
|
92
|
+
else delete secrets.checkin
|
|
93
|
+
await saveSecrets(secrets, env)
|
|
94
|
+
return manual[provider] ?? null
|
|
95
|
+
}
|
|
96
|
+
|
|
60
97
|
// ── Qoder 令牌 ──
|
|
61
98
|
|
|
62
99
|
export async function loadQoders(env = process.env) {
|
package/lib/providers/astudio.js
CHANGED
|
@@ -24,6 +24,7 @@ import { existsSync } from 'node:fs'
|
|
|
24
24
|
import { readFile } from 'node:fs/promises'
|
|
25
25
|
import { homedir } from 'node:os'
|
|
26
26
|
import { join } from 'node:path'
|
|
27
|
+
import { getManual } from '../checkin-secrets.js'
|
|
27
28
|
import { OUTCOME } from './base.js'
|
|
28
29
|
|
|
29
30
|
const BASE = 'https://agent.xfyun.cn/xingchen-studio/'
|
|
@@ -65,8 +66,12 @@ function sessionPath(env) {
|
|
|
65
66
|
return join(astudioStateDir(env), SESSION_FILE)
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
/** 读登录态;没登录 / 不完整返回 null */
|
|
69
|
+
/** 读登录态;没登录 / 不完整返回 null。手动配置优先,读不到再读 App 文件 */
|
|
69
70
|
export async function readSession(env = process.env) {
|
|
71
|
+
const manual = await getManual('astudio', env)
|
|
72
|
+
if (manual?.accountId && manual?.token) {
|
|
73
|
+
return { accountId: String(manual.accountId), token: String(manual.token), ...(manual.ssoSessionId ? { ssoSessionId: String(manual.ssoSessionId) } : {}), manual: true }
|
|
74
|
+
}
|
|
70
75
|
const file = sessionPath(env)
|
|
71
76
|
if (!existsSync(file)) return null
|
|
72
77
|
let raw
|
package/lib/providers/dumate.js
CHANGED
|
@@ -21,6 +21,7 @@ import { readFile } from 'node:fs/promises'
|
|
|
21
21
|
import { createDecipheriv } from 'node:crypto'
|
|
22
22
|
import { homedir } from 'node:os'
|
|
23
23
|
import { join } from 'node:path'
|
|
24
|
+
import { getManual } from '../checkin-secrets.js'
|
|
24
25
|
import { OUTCOME } from './base.js'
|
|
25
26
|
|
|
26
27
|
const HOST = 'https://console.bce.baidu.com'
|
|
@@ -104,7 +105,26 @@ export function csrfToken(cookies, hostname) {
|
|
|
104
105
|
return found ? String(found.value).replace(/^["']+|["']+$/g, '') : ''
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
/** 把 "a=1; b=2" 这种 Cookie 串解析成 cookie 数组(给手动配置用) */
|
|
109
|
+
export function parseCookieHeader(header) {
|
|
110
|
+
return String(header || '').split(/;\s*/).filter(Boolean).map((pair) => {
|
|
111
|
+
const i = pair.indexOf('=')
|
|
112
|
+
if (i <= 0) return null
|
|
113
|
+
return { name: pair.slice(0, i).trim(), value: pair.slice(i + 1) }
|
|
114
|
+
}).filter(Boolean)
|
|
115
|
+
}
|
|
116
|
+
|
|
107
117
|
async function session(env) {
|
|
118
|
+
// 手动配置优先:直接给 Cookie 串(含 bce-user-info 做 csrftoken)
|
|
119
|
+
const manual = await getManual('dumate', env)
|
|
120
|
+
if (manual?.cookie) {
|
|
121
|
+
const cookieHeader = String(manual.cookie).trim()
|
|
122
|
+
const csrf = csrfToken(parseCookieHeader(cookieHeader), new URL(HOST).hostname)
|
|
123
|
+
if (!csrf) {
|
|
124
|
+
throw Object.assign(new Error('手动 Cookie 里没有 bce-user-info(csrftoken)'), { code: 'DUMATE_NO_CSRF' })
|
|
125
|
+
}
|
|
126
|
+
return { cookieHeader, csrf }
|
|
127
|
+
}
|
|
108
128
|
const cookies = await decryptCookies(env)
|
|
109
129
|
const hostname = new URL(HOST).hostname
|
|
110
130
|
const matched = cookiesForHost(cookies, hostname)
|
package/lib/providers/lingxi.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import { existsSync } from 'node:fs'
|
|
21
21
|
import { homedir } from 'node:os'
|
|
22
22
|
import { join } from 'node:path'
|
|
23
|
+
import { getManual } from '../checkin-secrets.js'
|
|
23
24
|
import { OUTCOME } from './base.js'
|
|
24
25
|
|
|
25
26
|
const HOST = 'https://lingxi.wps.cn'
|
|
@@ -57,6 +58,11 @@ export function cookieDbPath(env = process.env) {
|
|
|
57
58
|
* 优先取 lingxi.wps.cn 域下那条,没有再退回 .wps.cn。
|
|
58
59
|
*/
|
|
59
60
|
export async function readSessionCookie(env = process.env) {
|
|
61
|
+
// 手动配置优先(VPS 等没有灵犀 App 的机器也能独立用)
|
|
62
|
+
const manual = await getManual('lingxi', env)
|
|
63
|
+
if (manual?.wps_sid) {
|
|
64
|
+
return { sid: String(manual.wps_sid), host: 'manual' }
|
|
65
|
+
}
|
|
60
66
|
const dbPath = cookieDbPath(env)
|
|
61
67
|
if (!existsSync(dbPath)) {
|
|
62
68
|
throw Object.assign(new Error('没找到 WPS 灵犀的 Cookies 库,确认灵犀装好并登录过'), { code: 'LINGXI_NO_COOKIE_DB' })
|
package/lib/providers/trae.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createDecipheriv, createHash, randomUUID } from 'node:crypto'
|
|
|
12
12
|
import { readFile } from 'node:fs/promises'
|
|
13
13
|
import { homedir } from 'node:os'
|
|
14
14
|
import { join } from 'node:path'
|
|
15
|
+
import { getManual } from '../checkin-secrets.js'
|
|
15
16
|
import { OUTCOME } from './base.js'
|
|
16
17
|
|
|
17
18
|
const API = 'https://api.trae.cn'
|
|
@@ -182,7 +183,14 @@ export async function traeCheckin(c) {
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
export function createTraeProvider({ log = () => {}, env = process.env } = {}) {
|
|
185
|
-
|
|
186
|
+
// 手动配置优先(VPS 上也能独立签);否则读本机 Trae App/CLI
|
|
187
|
+
const creds = async () => {
|
|
188
|
+
const manual = await getManual('trae', env)
|
|
189
|
+
if (manual?.token) {
|
|
190
|
+
return [{ token: String(manual.token), deviceId: '', source: 'manual', ...(tokenAccountId(String(manual.token)) ? { accountId: tokenAccountId(String(manual.token)) } : {}) }]
|
|
191
|
+
}
|
|
192
|
+
return findTraeCredentials(env.HOME || env.USERPROFILE || homedir(), env.TRAE_PLATFORM || process.platform, env)
|
|
193
|
+
}
|
|
186
194
|
|
|
187
195
|
return {
|
|
188
196
|
id: 'trae',
|
package/lib/server.js
CHANGED
|
@@ -19,6 +19,7 @@ import { readFile } from 'node:fs/promises'
|
|
|
19
19
|
import { join } from 'node:path'
|
|
20
20
|
import { recentDays, loadConfig, loadState, saveConfig, claimedToday, providerConfig } from './store.js'
|
|
21
21
|
import { localTimeZone } from './signin.js'
|
|
22
|
+
import { setManual, getManual, loadManual } from './checkin-secrets.js'
|
|
22
23
|
|
|
23
24
|
const MAX_BODY = 64 * 1024
|
|
24
25
|
|
|
@@ -54,10 +55,10 @@ const STATIC = {
|
|
|
54
55
|
'/panel.css': ['web/panel.css', 'text/css; charset=utf-8'],
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
export function createHandler({ prefix, pkgRoot, runner, scheduler, version, log = () => {} }) {
|
|
58
|
+
export function createHandler({ prefix, pkgRoot, runner, scheduler, version, log = () => {}, env = process.env }) {
|
|
58
59
|
/** 会改东西的请求:必须 POST + JSON + 自定义头 */
|
|
59
60
|
const isSafePost = (req) => {
|
|
60
|
-
if (req.method !== 'POST') return false
|
|
61
|
+
if (req.method !== 'POST' && req.method !== 'DELETE') return false
|
|
61
62
|
if (!String(req.headers['content-type'] || '').startsWith('application/json')) return false
|
|
62
63
|
if (!req.headers['x-dsh-checkin-all']) return false
|
|
63
64
|
const origin = req.headers.origin
|
|
@@ -200,6 +201,31 @@ export function createHandler({ prefix, pkgRoot, runner, scheduler, version, log
|
|
|
200
201
|
return sendJson(res, 200, { ok: true })
|
|
201
202
|
}
|
|
202
203
|
|
|
204
|
+
// 手动凭据:GET 读(脱敏),POST 写,DELETE 删
|
|
205
|
+
if (path === '/credential') {
|
|
206
|
+
if (req.method === 'GET') {
|
|
207
|
+
const manual = await loadManual(env)
|
|
208
|
+
const meta = { ...manual }
|
|
209
|
+
// 脱敏:不把 token/cookie 原样回传,只告诉「有没有配置」
|
|
210
|
+
for (const key of Object.keys(meta)) {
|
|
211
|
+
const v = meta[key]
|
|
212
|
+
if (v && typeof v === 'object') {
|
|
213
|
+
meta[key] = { configured: true, ...Object.fromEntries(Object.entries(v).map(([k, val]) => [k, val === undefined ? false : String(val).length > 0])) }
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return sendJson(res, 200, { ok: true, manual: meta })
|
|
217
|
+
}
|
|
218
|
+
if (req.method === 'DELETE') {
|
|
219
|
+
if (!isSafePost(req)) return sendJson(res, 403, { ok: false, message: '只接受本页面发出的请求' })
|
|
220
|
+
await setManual(id, null, env)
|
|
221
|
+
return sendJson(res, 200, { ok: true, id })
|
|
222
|
+
}
|
|
223
|
+
if (!isSafePost(req)) return sendJson(res, 403, { ok: false, message: '只接受本页面发出的请求' })
|
|
224
|
+
const body = await readJson(req)
|
|
225
|
+
await setManual(id, body.entry || body, env)
|
|
226
|
+
return sendJson(res, 200, { ok: true, id })
|
|
227
|
+
}
|
|
228
|
+
|
|
203
229
|
return sendJson(res, 404, { error: 'not found' })
|
|
204
230
|
} catch (error) {
|
|
205
231
|
log(`dsh-checkin-all: ${path} 出错 ${error.message}`, 'warn')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-checkin-all",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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
|
@@ -10,10 +10,10 @@ async function api(path, { method = 'GET', body } = {}) {
|
|
|
10
10
|
const response = await fetch(BASE + path, {
|
|
11
11
|
method,
|
|
12
12
|
credentials: 'same-origin',
|
|
13
|
-
headers: method === 'POST'
|
|
13
|
+
headers: method === 'POST' || method === 'DELETE'
|
|
14
14
|
? { 'content-type': 'application/json', 'x-dsh-checkin-all': '1' }
|
|
15
15
|
: undefined,
|
|
16
|
-
body: method === 'POST' ? JSON.stringify(body || {}) : undefined,
|
|
16
|
+
body: method === 'POST' || method === 'DELETE' ? JSON.stringify(body || {}) : undefined,
|
|
17
17
|
})
|
|
18
18
|
// DSH 的鉴权拦截器对未认证请求回 401 + 空 body:直接 r.json() 会炸成
|
|
19
19
|
// "Unexpected end of JSON input",这里先读文本再解析,空响应给一句人话
|
|
@@ -122,6 +122,14 @@ function renderDetail() {
|
|
|
122
122
|
: ''
|
|
123
123
|
|
|
124
124
|
const canLogin = p.id === 'minimax'
|
|
125
|
+
// 支持手动配置凭据的服务
|
|
126
|
+
const canManual = ['lingxi', 'dumate', 'astudio', 'trae'].includes(p.id)
|
|
127
|
+
const manualHint = {
|
|
128
|
+
lingxi: 'wps_sid 的值',
|
|
129
|
+
dumate: '完整 Cookie 串(含 bce-user-info)',
|
|
130
|
+
astudio: 'accountId,token,ssoSessionId(逗号分隔)',
|
|
131
|
+
trae: 'Cloud-IDE-JWT token',
|
|
132
|
+
}[p.id]
|
|
125
133
|
|
|
126
134
|
box.innerHTML = `
|
|
127
135
|
<section class="card">
|
|
@@ -129,6 +137,7 @@ function renderDetail() {
|
|
|
129
137
|
<h2>${esc(p.name)}</h2>
|
|
130
138
|
<div class="head-actions">
|
|
131
139
|
${canLogin && !account.loggedIn ? '<button class="btn tiny" id="btn-login">登录</button>' : ''}
|
|
140
|
+
${canManual ? '<button class="btn tiny" id="btn-cred">配置凭据</button>' : ''}
|
|
132
141
|
<button class="btn tiny primary" id="btn-checkin">立刻签到</button>
|
|
133
142
|
</div>
|
|
134
143
|
</div>
|
|
@@ -153,6 +162,24 @@ function renderDetail() {
|
|
|
153
162
|
<span class="value ${last.ok ? 'ok' : 'bad'}">${esc(lastText)}</span></div>` : ''}
|
|
154
163
|
</section>
|
|
155
164
|
|
|
165
|
+
${canManual ? `
|
|
166
|
+
<section class="card" id="cred-card">
|
|
167
|
+
<div class="card-head">
|
|
168
|
+
<h2>凭据配置</h2>
|
|
169
|
+
<span class="hint" id="cred-status"></span>
|
|
170
|
+
</div>
|
|
171
|
+
<div class="field">
|
|
172
|
+
<label for="cred-value">${esc(manualHint)}</label>
|
|
173
|
+
<textarea id="cred-value" rows="3" placeholder="${esc(manualHint)}"></textarea>
|
|
174
|
+
</div>
|
|
175
|
+
<div class="actions">
|
|
176
|
+
<button class="btn primary" id="btn-cred-save">保存凭据</button>
|
|
177
|
+
<button class="btn" id="btn-cred-clear">清除凭据</button>
|
|
178
|
+
<span id="cred-msg" class="hint"></span>
|
|
179
|
+
</div>
|
|
180
|
+
</section>
|
|
181
|
+
` : ''}
|
|
182
|
+
|
|
156
183
|
<section class="card">
|
|
157
184
|
<div class="card-head">
|
|
158
185
|
<h2 id="week-title">本周签到表</h2>
|
|
@@ -198,12 +225,99 @@ function renderDetail() {
|
|
|
198
225
|
const loginBtn = $('#btn-login')
|
|
199
226
|
if (loginBtn) loginBtn.onclick = () => startLogin(p.id)
|
|
200
227
|
|
|
228
|
+
// 手动凭据配置
|
|
229
|
+
const credBtn = $('#btn-cred')
|
|
230
|
+
const credCard = $('#cred-card')
|
|
231
|
+
if (credCard && credBtn) {
|
|
232
|
+
credBtn.onclick = () => { credCard.scrollIntoView({ behavior: 'smooth', block: 'center' }) }
|
|
233
|
+
$('#btn-cred-save').onclick = () => saveCredential(p.id)
|
|
234
|
+
$('#btn-cred-clear').onclick = () => clearCredential(p.id)
|
|
235
|
+
loadCredentialStatus(p.id)
|
|
236
|
+
}
|
|
237
|
+
|
|
201
238
|
renderHistory(st.recent)
|
|
202
239
|
const cached = PANELS.get(p.id)
|
|
203
240
|
if (cached) renderWeek(cached)
|
|
204
241
|
else loadPanel(p.id)
|
|
205
242
|
}
|
|
206
243
|
|
|
244
|
+
/** 读某个服务的手动凭据状态(脱敏,只显示「已配置」) */
|
|
245
|
+
async function loadCredentialStatus(id) {
|
|
246
|
+
const status = $('#cred-status')
|
|
247
|
+
if (!status) return
|
|
248
|
+
try {
|
|
249
|
+
const r = await api(`/credential?id=${encodeURIComponent(id)}`)
|
|
250
|
+
if (r.ok && r.manual && r.manual[id]?.configured) {
|
|
251
|
+
status.textContent = '已配置(重新保存会覆盖)'
|
|
252
|
+
status.className = 'hint ok'
|
|
253
|
+
} else {
|
|
254
|
+
status.textContent = '未配置'
|
|
255
|
+
status.className = 'hint'
|
|
256
|
+
}
|
|
257
|
+
} catch (e) {
|
|
258
|
+
status.textContent = e.message
|
|
259
|
+
status.className = 'hint bad'
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** 保存手动凭据 */
|
|
264
|
+
async function saveCredential(id) {
|
|
265
|
+
const value = $('#cred-value').value.trim()
|
|
266
|
+
const msg = $('#cred-msg')
|
|
267
|
+
if (!value) {
|
|
268
|
+
if (msg) msg.textContent = '请输入凭据值'
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
let entry
|
|
272
|
+
if (id === 'astudio') {
|
|
273
|
+
const [accountId, token, ssoSessionId] = value.split(',').map(s => s.trim())
|
|
274
|
+
if (!accountId || !token) {
|
|
275
|
+
if (msg) msg.textContent = 'AStudio 需要 accountId 和 token(逗号分隔)'
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
entry = { accountId, token, ...(ssoSessionId ? { ssoSessionId } : {}) }
|
|
279
|
+
} else if (id === 'lingxi') {
|
|
280
|
+
entry = { wps_sid: value }
|
|
281
|
+
} else if (id === 'dumate') {
|
|
282
|
+
entry = { cookie: value }
|
|
283
|
+
} else if (id === 'trae') {
|
|
284
|
+
entry = { token: value }
|
|
285
|
+
} else {
|
|
286
|
+
if (msg) msg.textContent = '这个服务不支持手动配置'
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
const r = await api(`/credential?id=${encodeURIComponent(id)}`, { method: 'POST', body: { entry } })
|
|
291
|
+
if (r.ok) {
|
|
292
|
+
if (msg) { msg.textContent = '已保存'; setTimeout(() => { if (msg) msg.textContent = '' }, 2500) }
|
|
293
|
+
$('#cred-value').value = ''
|
|
294
|
+
loadCredentialStatus(id)
|
|
295
|
+
await refresh({ withPanels: false })
|
|
296
|
+
} else if (msg) {
|
|
297
|
+
msg.textContent = r.message || '保存失败'
|
|
298
|
+
}
|
|
299
|
+
} catch (e) {
|
|
300
|
+
if (msg) msg.textContent = `保存失败:${e.message}`
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** 清除手动凭据(回退到 App 文件读取) */
|
|
305
|
+
async function clearCredential(id) {
|
|
306
|
+
const msg = $('#cred-msg')
|
|
307
|
+
try {
|
|
308
|
+
const r = await api(`/credential?id=${encodeURIComponent(id)}`, { method: 'DELETE' })
|
|
309
|
+
if (r.ok) {
|
|
310
|
+
if (msg) { msg.textContent = '已清除'; setTimeout(() => { if (msg) msg.textContent = '' }, 2500) }
|
|
311
|
+
loadCredentialStatus(id)
|
|
312
|
+
await refresh({ withPanels: false })
|
|
313
|
+
} else if (msg) {
|
|
314
|
+
msg.textContent = r.message || '清除失败'
|
|
315
|
+
}
|
|
316
|
+
} catch (e) {
|
|
317
|
+
if (msg) msg.textContent = `清除失败:${e.message}`
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
207
321
|
function renderWeek(panel) {
|
|
208
322
|
const box = $('#week')
|
|
209
323
|
if (!box) return
|