()
| 87 | } |
| 88 | |
| 89 | async function getOpenlistToken(): Promise<string> { |
| 90 | if (openlistInfo.endpoint.auth.token) { |
| 91 | return openlistInfo.endpoint.auth.token |
| 92 | } |
| 93 | const username = nmConfig.framework.openlist.user |
| 94 | const password = nmConfig.framework.openlist.password |
| 95 | |
| 96 | const maxAttempts = 3 |
| 97 | let lastError: unknown |
| 98 | for (let attempt = 1; attempt <= maxAttempts; attempt++) { |
| 99 | try { |
| 100 | const token = await openlist_login(username, password) |
| 101 | openlistInfo.endpoint.auth.token = token |
| 102 | return token |
| 103 | } catch (e) { |
| 104 | lastError = e |
| 105 | if (attempt < maxAttempts) { |
| 106 | await new Promise(resolve => setTimeout(resolve, 500)) |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | throw new Error(`OpenList login failed after ${maxAttempts} attempts: ${String(lastError)}`) |
| 112 | } |
| 113 | |
| 114 | async function setOpenlistPass(pass: string) { |
| 115 | // v1.1.2 行为:每次启动都无条件写入 admin 密码,避免升级/迁移导致的"密码不一致"卡死。 |
no test coverage detected