[Desktop] Fix mirror validation in settings dialog (#2375)

This commit is contained in:
Chenlei Hu
2025-01-29 14:57:36 -08:00
committed by GitHub
parent e019277ba0
commit 766710cf37
3 changed files with 38 additions and 15 deletions

View File

@@ -1,5 +1,8 @@
import axios from 'axios'
import { electronAPI } from './envUtil'
import { isValidUrl } from './formatUtil'
const VALID_STATUS_CODES = [200, 201, 301, 302, 307, 308]
export const checkUrlReachable = async (url: string): Promise<boolean> => {
try {
@@ -10,3 +13,14 @@ export const checkUrlReachable = async (url: string): Promise<boolean> => {
return false
}
}
/**
* Check if a mirror is reachable from the electron App.
* @param mirror - The mirror to check.
* @returns True if the mirror is reachable, false otherwise.
*/
export const checkMirrorReachable = async (mirror: string) => {
return (
isValidUrl(mirror) && (await electronAPI().NetWork.canAccessUrl(mirror))
)
}