- Introduced functionality to use download mirrors for GitHub releases, improving update speed in restricted networks. - Enhanced UpdateService to resolve download source based on locale and environment variables. - Updated UpdateIndicator to display mirror usage status and provide relevant hints to users. - Added utility functions for managing GitHub download mirrors and created unit tests to ensure reliability. - Modified error messages for manual download and installation to provide clearer instructions.
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
applyGithubDownloadMirror,
|
|
buildMirroredGithubLatestFeedUrl,
|
|
isGithubDownloadUrl,
|
|
resolveUpdateDownloadSource,
|
|
} from '@/shared/utils/githubDownloadMirror'
|
|
|
|
describe('githubDownloadMirror', () => {
|
|
it('detects github download hosts', () => {
|
|
expect(isGithubDownloadUrl('https://github.com/ad-naan/adnify/releases/download/v1.0.0/a.exe')).toBe(true)
|
|
expect(isGithubDownloadUrl('https://example.com/a.exe')).toBe(false)
|
|
})
|
|
|
|
it('prefixes mirror once', () => {
|
|
const url = 'https://github.com/ad-naan/adnify/releases/download/v1.0.0/a.exe'
|
|
const mirrored = applyGithubDownloadMirror(url, 'https://ghfast.top/')
|
|
expect(mirrored).toBe(`https://ghfast.top/${url}`)
|
|
expect(applyGithubDownloadMirror(mirrored, 'https://ghfast.top/')).toBe(mirrored)
|
|
})
|
|
|
|
it('builds mirrored latest/download feed', () => {
|
|
expect(buildMirroredGithubLatestFeedUrl('ad-naan', 'adnify', 'https://ghfast.top/')).toBe(
|
|
'https://ghfast.top/https://github.com/ad-naan/adnify/releases/latest/download',
|
|
)
|
|
})
|
|
|
|
it('resolves source from locale and env override', () => {
|
|
expect(resolveUpdateDownloadSource({ locale: 'zh-CN' })).toBe('mirror')
|
|
expect(resolveUpdateDownloadSource({ locale: 'en-US' })).toBe('github')
|
|
expect(resolveUpdateDownloadSource({ locale: 'zh-CN', envForce: 'github' })).toBe('github')
|
|
expect(resolveUpdateDownloadSource({ locale: 'en-US', envForce: 'mirror' })).toBe('mirror')
|
|
})
|
|
})
|