mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 23:20:07 +00:00
[Desktop] Fix mirror validation in settings dialog (#2375)
This commit is contained in:
@@ -10,7 +10,10 @@
|
||||
</div>
|
||||
<UrlInput
|
||||
v-model="modelValue"
|
||||
:validate-url-fn="checkMirrorReachable"
|
||||
:validate-url-fn="
|
||||
(mirror: string) =>
|
||||
checkMirrorReachable(mirror + (item.validationPathSuffix ?? ''))
|
||||
"
|
||||
@state-change="validationState = $event"
|
||||
/>
|
||||
</div>
|
||||
@@ -20,8 +23,8 @@
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
|
||||
import { UVMirror } from '@/constants/uvMirrors'
|
||||
import { electronAPI } from '@/utils/envUtil'
|
||||
import { isValidUrl, normalizeI18nKey } from '@/utils/formatUtil'
|
||||
import { normalizeI18nKey } from '@/utils/formatUtil'
|
||||
import { checkMirrorReachable } from '@/utils/networkUtil'
|
||||
import { ValidationState } from '@/utils/validationUtil'
|
||||
|
||||
const { item } = defineProps<{
|
||||
@@ -39,15 +42,6 @@ const normalizedSettingId = computed(() => {
|
||||
return normalizeI18nKey(item.settingId)
|
||||
})
|
||||
|
||||
const checkMirrorReachable = async (mirror: string) => {
|
||||
return (
|
||||
isValidUrl(mirror) &&
|
||||
(await electronAPI().NetWork.canAccessUrl(
|
||||
mirror + (item.validationPathSuffix ?? '')
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
modelValue.value = item.mirror
|
||||
})
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { PYTHON_MIRROR } from '@/constants/uvMirrors'
|
||||
import { t } from '@/i18n'
|
||||
import { app } from '@/scripts/app'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
import { useWorkflowStore } from '@/stores/workflowStore'
|
||||
import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
|
||||
import { checkMirrorReachable } from '@/utils/networkUtil'
|
||||
|
||||
;(async () => {
|
||||
if (!isElectron()) return
|
||||
@@ -60,21 +62,34 @@ import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
|
||||
name: 'Python Install Mirror',
|
||||
tooltip: `Managed Python installations are downloaded from the Astral python-build-standalone project. This variable can be set to a mirror URL to use a different source for Python installations. The provided URL will replace https://github.com/astral-sh/python-build-standalone/releases/download in, e.g., https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz. Distributions can be read from a local directory by using the file:// URL scheme.`,
|
||||
type: 'url',
|
||||
defaultValue: ''
|
||||
defaultValue: '',
|
||||
attrs: {
|
||||
validateUrlFn(mirror: string) {
|
||||
return checkMirrorReachable(
|
||||
mirror + PYTHON_MIRROR.validationPathSuffix
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'Comfy-Desktop.UV.PypiInstallMirror',
|
||||
name: 'Pypi Install Mirror',
|
||||
tooltip: `Default pip install mirror`,
|
||||
type: 'url',
|
||||
defaultValue: ''
|
||||
defaultValue: '',
|
||||
attrs: {
|
||||
validateUrlFn: checkMirrorReachable
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'Comfy-Desktop.UV.TorchInstallMirror',
|
||||
name: 'Torch Install Mirror',
|
||||
tooltip: `Pip install mirror for pytorch`,
|
||||
type: 'url',
|
||||
defaultValue: ''
|
||||
defaultValue: '',
|
||||
attrs: {
|
||||
validateUrlFn: checkMirrorReachable
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
@@ -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))
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user