mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(update): suppress cli dev update badge
This commit is contained in:
1 parent
8b2e6de479
commit
5144c8070a
4 files changed
+70
-4
No files matched your search
@@ -20,7 +20,7 @@
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import type { FastifyInstance } from 'fastify'
|
||||
import { isNewerStableVersion, type PathProvider } from '@openchatlab/core'
|
||||
import type { PathProvider } from '@openchatlab/core'
|
||||
import type {
|
||||
DatabaseManager,
|
||||
AIConversationManager,
|
||||
@@ -43,6 +43,7 @@ import { MergeSessionCache } from '../../../merger/merge-cache'
|
||||
import { registerImportRoutes } from './import'
|
||||
import { openDirectoryPath, showPathInFolder } from './cache'
|
||||
import { getVersion } from '../../../version'
|
||||
import { buildWebUpdateCheckResult } from './update-check'
|
||||
|
||||
export interface AiContextOptions {
|
||||
aiDataDir: string
|
||||
@@ -149,9 +150,7 @@ export function registerWebRoutes(
|
||||
return { hasUpdate: false, currentVersion, error: `latest-version HTTP ${resp.status}` }
|
||||
}
|
||||
const data = (await resp.json()) as { version?: string }
|
||||
const latestVersion = data.version || currentVersion
|
||||
const hasUpdate = isNewerStableVersion(latestVersion, currentVersion)
|
||||
return { hasUpdate, currentVersion, latestVersion }
|
||||
return buildWebUpdateCheckResult({ currentVersion, latestVersion: data.version })
|
||||
} catch (err) {
|
||||
return {
|
||||
hasUpdate: false,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { buildWebUpdateCheckResult } from './update-check'
|
||||
|
||||
describe('CLI Web update check', () => {
|
||||
it('does not show an update notice for local development placeholder versions', () => {
|
||||
assert.deepEqual(buildWebUpdateCheckResult({ currentVersion: '0.0.0', latestVersion: '0.24.0' }), {
|
||||
hasUpdate: false,
|
||||
currentVersion: '0.0.0',
|
||||
latestVersion: '0.24.0',
|
||||
})
|
||||
assert.deepEqual(buildWebUpdateCheckResult({ currentVersion: '0.0.0-dev', latestVersion: '0.24.0' }), {
|
||||
hasUpdate: false,
|
||||
currentVersion: '0.0.0-dev',
|
||||
latestVersion: '0.24.0',
|
||||
})
|
||||
})
|
||||
|
||||
it('reports stable updates for real CLI versions', () => {
|
||||
assert.deepEqual(buildWebUpdateCheckResult({ currentVersion: '0.23.0', latestVersion: '0.24.0' }), {
|
||||
hasUpdate: true,
|
||||
currentVersion: '0.23.0',
|
||||
latestVersion: '0.24.0',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import { isNewerStableVersion } from '@openchatlab/core'
|
||||
|
||||
export interface WebUpdateCheckResult {
|
||||
hasUpdate: boolean
|
||||
currentVersion: string
|
||||
latestVersion?: string
|
||||
}
|
||||
|
||||
function isDevelopmentPlaceholderVersion(version: string): boolean {
|
||||
return /^0\.0\.0(?:$|-)/.test(version.trim())
|
||||
}
|
||||
|
||||
export function buildWebUpdateCheckResult(options: {
|
||||
currentVersion: string
|
||||
latestVersion?: string | null
|
||||
}): WebUpdateCheckResult {
|
||||
const latestVersion = options.latestVersion || options.currentVersion
|
||||
return {
|
||||
hasUpdate:
|
||||
!isDevelopmentPlaceholderVersion(options.currentVersion) &&
|
||||
isNewerStableVersion(latestVersion, options.currentVersion),
|
||||
currentVersion: options.currentVersion,
|
||||
latestVersion,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user