()
| 169 | } |
| 170 | |
| 171 | async function reupOpenlistVersion() { |
| 172 | const MAX_RETRIES = 3 |
| 173 | const RETRY_DELAY_MS = 500 |
| 174 | let attempts = 0 |
| 175 | |
| 176 | while (attempts < MAX_RETRIES) { |
| 177 | attempts++ |
| 178 | |
| 179 | // 主路径:尝试 /api/admin/setting/get |
| 180 | try { |
| 181 | const version = await openlist_api_get('/api/admin/setting/get', { key: 'version' }) |
| 182 | |
| 183 | if (version.code === 200 && version.data?.value) { |
| 184 | openlistInfo.version.version = version.data.value |
| 185 | console.log('OpenList version retrieved via /api/admin/setting/get:', version.data.value) |
| 186 | return true |
| 187 | } |
| 188 | } catch (primaryError) { |
| 189 | console.warn(`Primary version endpoint attempt ${attempts} failed:`, primaryError) |
| 190 | } |
| 191 | |
| 192 | // 如果还有重试次数,尝试回退路径 |
| 193 | if (attempts < MAX_RETRIES) { |
| 194 | console.log( |
| 195 | `Primary version endpoint failed, trying fallback... (attempt ${attempts}/${MAX_RETRIES})` |
| 196 | ) |
| 197 | |
| 198 | try { |
| 199 | const publicSettings = await openlist_api_get('/api/public/settings') |
| 200 | if (publicSettings.data?.version) { |
| 201 | openlistInfo.version.version = publicSettings.data.version |
| 202 | console.log( |
| 203 | 'OpenList version retrieved via /api/public/settings:', |
| 204 | publicSettings.data.version |
| 205 | ) |
| 206 | return true |
| 207 | } |
| 208 | } catch (fallbackError) { |
| 209 | console.warn(`Fallback version endpoint attempt ${attempts} failed:`, fallbackError) |
| 210 | } |
| 211 | |
| 212 | // 等待后重试 |
| 213 | if (attempts < MAX_RETRIES) { |
| 214 | console.log( |
| 215 | `All version endpoints failed, retrying in ${RETRY_DELAY_MS}ms... (attempt ${attempts + 1}/${MAX_RETRIES})` |
| 216 | ) |
| 217 | await sleep(RETRY_DELAY_MS) |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // 所有重试都失败了 |
| 223 | console.error( |
| 224 | 'All version endpoints failed after', |
| 225 | MAX_RETRIES, |
| 226 | 'attempts. Using fallback version.' |
| 227 | ) |
| 228 | openlistInfo.version.version = 'unknown' |
no test coverage detected