daily-question 2.0.0 → 2.1.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/CHANGELOG.md +32 -0
- package/LICENSE +21 -21
- package/README.md +98 -20
- package/client.js +281 -61
- package/index.js +2 -2
- package/lib/async.js +17 -0
- package/lib/bank.js +3 -3
- package/lib/generate.js +121 -101
- package/lib/generation-history.js +67 -0
- package/lib/llm-json.js +17 -8
- package/lib/pdf-worker.js +5 -0
- package/lib/pdf.js +156 -34
- package/lib/reference-reader.js +178 -0
- package/lib/reference-sources.js +83 -0
- package/lib/references.js +159 -0
- package/lib/research.js +166 -0
- package/lib/routes.js +2 -0
- package/lib/service.js +199 -50
- package/lib/subjects.js +19 -0
- package/lib/tutor.js +6 -5
- package/lib/updates.js +49 -0
- package/package.json +4 -2
package/lib/updates.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
export const PLUGIN_VERSION=JSON.parse(readFileSync(new URL('../package.json',import.meta.url),'utf8')).version
|
|
4
|
+
export const UPDATE_INTERVAL=6*60*60*1000
|
|
5
|
+
const REGISTRY='https://registry.npmjs.org/daily-question/latest'
|
|
6
|
+
|
|
7
|
+
function versionParts(value) {
|
|
8
|
+
if(typeof value!=='string')throw new Error('npm 返回的版本号无效')
|
|
9
|
+
const match=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.exec(value)
|
|
10
|
+
if(!match||match[4]?.split('.').some((p)=>/^0\d+$/.test(p)))throw new Error('npm 返回的版本号无效')
|
|
11
|
+
return {numbers:match.slice(1,4).map(BigInt),pre:match[4]?.split('.')}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function newerVersion(latest,current) {
|
|
15
|
+
const a=versionParts(latest),b=versionParts(current)
|
|
16
|
+
for(let i=0;i<3;i++)if(a.numbers[i]!==b.numbers[i])return a.numbers[i]>b.numbers[i]
|
|
17
|
+
if(!a.pre||!b.pre)return Boolean(!a.pre&&b.pre)
|
|
18
|
+
for(let i=0;i<Math.max(a.pre.length,b.pre.length);i++) {
|
|
19
|
+
const x=a.pre[i],y=b.pre[i]
|
|
20
|
+
if(x===y)continue
|
|
21
|
+
if(x===undefined||y===undefined)return y===undefined
|
|
22
|
+
const nx=/^\d+$/.test(x),ny=/^\d+$/.test(y)
|
|
23
|
+
return nx&&ny?BigInt(x)>BigInt(y):nx!==ny?!nx:x>y
|
|
24
|
+
}
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createUpdateChecker({fetchImpl=globalThis.fetch,currentVersion=PLUGIN_VERSION,now=Date.now}={}) {
|
|
29
|
+
let cached,pending
|
|
30
|
+
return async ({force=false}={})=>{
|
|
31
|
+
if(pending)return {...await pending}
|
|
32
|
+
if(force!==true&&cached&&now()-cached.at>=0&&now()-cached.at<UPDATE_INTERVAL)return {...cached.result}
|
|
33
|
+
pending=(async()=>{
|
|
34
|
+
try {
|
|
35
|
+
const response=await fetchImpl(REGISTRY,{signal:AbortSignal.timeout(10000),redirect:'error',headers:{accept:'application/json'}})
|
|
36
|
+
if(!response.ok)throw new Error(`npm 服务返回 ${response.status}`)
|
|
37
|
+
const metadata=await response.json()
|
|
38
|
+
if(metadata?.name!=='daily-question')throw new Error('npm 返回的包信息不匹配')
|
|
39
|
+
const updateAvailable=newerVersion(metadata.version,currentVersion)
|
|
40
|
+
const at=now(),result={ok:true,currentVersion,latestVersion:metadata.version,updateAvailable,checkedAt:new Date(at).toISOString(),packageUrl:'https://www.npmjs.com/package/daily-question'}
|
|
41
|
+
cached={at,result}
|
|
42
|
+
return {...result}
|
|
43
|
+
} catch(error) {
|
|
44
|
+
throw new Error(`检查更新失败:${error.name==='TimeoutError'?'连接 npm 超时,请稍后重试':error.message}`)
|
|
45
|
+
}
|
|
46
|
+
})()
|
|
47
|
+
try{return {...await pending}}finally{pending=null}
|
|
48
|
+
}
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "daily-question",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "考研每日一题 — DSH 插件:每科每天一道独立校验过的考研题,含倒计时、错题本、收藏与按题隔离的追问。",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"node": ">=20.3.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"test": "node test/check.mjs && node test/service-check.mjs && node test/render-check.mjs"
|
|
34
|
+
"test": "node test/check.mjs && node test/service-check.mjs && node test/tutor-status-check.mjs && node test/attempt-binding-check.mjs && node test/list-performance-check.mjs && node test/daily-attempt-check.mjs && node test/render-check.mjs && node test/ui-race-check.mjs && node test/followup-check.mjs && node test/task-check.mjs && node test/generation-check.mjs && node test/generation-history-check.mjs && node test/reference-check.mjs && node test/reference-reader-check.mjs && node test/research-check.mjs && node test/pdf-safety-check.mjs && node test/update-check.mjs",
|
|
35
|
+
"test:live": "node test/live-check.mjs"
|
|
35
36
|
},
|
|
36
37
|
"exports": {
|
|
37
38
|
".": "./index.js",
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
"cordis.patch.yml",
|
|
46
47
|
"locale/*.json",
|
|
47
48
|
"icon.svg",
|
|
49
|
+
"CHANGELOG.md",
|
|
48
50
|
"lib/*.js",
|
|
49
51
|
"vendor/mathjax/*"
|
|
50
52
|
],
|