dsh-go-codearts 1.0.0 → 1.0.3

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.
Files changed (2) hide show
  1. package/lib/index.js +25 -23
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // 手机端的 CodeArts 登录入口:dsh-codearts 的设置卡片是 web 组件,Flutter 界面里看不到,
2
2
  // 这里把登录、账号状态、今日用量搬到原生胶囊和面板里。
3
3
  import { readFile, readdir, writeFile } from 'node:fs/promises'
4
- import { readFileSync } from 'node:fs'
4
+ import { readFileSync, writeFileSync } from 'node:fs'
5
5
  import { join, dirname } from 'node:path'
6
6
  import { homedir } from 'node:os'
7
7
  import { pathToFileURL, fileURLToPath } from 'node:url'
@@ -240,33 +240,35 @@ async function setAutoEnabled(on) {
240
240
  } catch {}
241
241
  }
242
242
 
243
- // 自动签到:引擎在线时每 30 分钟检查一次,按本机日期去重;静默领取,只写自己账号。
244
- let autoCheckinDay = ''
243
+ // 自动签到:引擎在线时每 30 分钟检查一次,遍历本机所有账号逐个签到(全账号)。
244
+ // 去重 key = 日期 + 账号,互不影响;服务端也按天去重,重载后重复检查不会重复领取。
245
+ const autoCheckinDays = new Set()
245
246
  async function autoCheckin() {
246
247
  if (!(await autoEnabled())) return
247
248
  const d = new Date()
248
- const key = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
249
- if (key === autoCheckinDay) return
249
+ const dayKey = `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
250
250
  const accounts = await readAccounts()
251
251
  if (accounts.length === 0) return
252
- const acct = pickAccount(accounts)?.id
253
- try {
254
- const pre = await claimState(true, acct)
255
- if (pre.state === 'already') {
256
- autoCheckinDay = key
257
- return
258
- }
259
- if (pre.state !== 'claimable') return
260
- const { up } = await codearts()
261
- const Store = mod0().t
262
- const store = new Store((mod0().i)(dshHome()), (mod0().a)(dshHome()))
263
- const cred = await store.resolve(acct ?? accounts[0].id)
264
- const answer = await up.a(cred)
265
- if (answer.state === 'claimed' || answer.state === 'already') {
266
- autoCheckinDay = key
267
- await pushStrip(true)
268
- }
269
- } catch {}
252
+ for (const acc of accounts) {
253
+ const acct = String(acc?.id ?? '')
254
+ if (acct === '') continue
255
+ const key = `${dayKey}-${acct}`
256
+ if (autoCheckinDays.has(key)) continue
257
+ try {
258
+ const pre = await claimState(true, acct)
259
+ if (pre.state === 'already') { autoCheckinDays.add(key); continue }
260
+ if (pre.state !== 'claimable') continue
261
+ const { up } = await codearts()
262
+ const Store = mod0().t
263
+ const store = new Store((mod0().i)(dshHome()), (mod0().a)(dshHome()))
264
+ const cred = await store.resolve(acct)
265
+ const answer = await up.a(cred)
266
+ if (answer.state === 'claimed' || answer.state === 'already') {
267
+ autoCheckinDays.add(key)
268
+ await pushStrip(true)
269
+ }
270
+ } catch {}
271
+ }
270
272
  }
271
273
 
272
274
  // 今日是否有调用记录:决定面板里画柱状图还是显示一句人话(无数据时 App 自己会画「暂无数据」)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-go-codearts",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "dsh": {