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.
- package/lib/index.js +25 -23
- 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
|
-
|
|
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
|
|
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
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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 自己会画「暂无数据」)。
|