Skip to content

Commit 6c144de

Browse files
committed
Extract electron mirror check and path annotator
1 parent ce5f2fe commit 6c144de

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

packages/shared-frontend-utils/src/formatUtil.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ResultItem } from '@/schemas/apiSchema'
2-
import type { operations } from '@/types/comfyRegistryTypes'
1+
import type { operations } from '@comfyorg/registry-types'
32

43
export function formatCamelCase(str: string): string {
54
// Check if the string is camel case
@@ -194,27 +193,6 @@ export function isValidUrl(url: string): boolean {
194193
return false
195194
}
196195
}
197-
const hasAnnotation = (filepath: string): boolean =>
198-
/\[(input|output|temp)\]/i.test(filepath)
199-
200-
const createAnnotation = (filepath: string, rootFolder = 'input'): string =>
201-
!hasAnnotation(filepath) && rootFolder !== 'input' ? ` [${rootFolder}]` : ''
202-
203-
const createPath = (filename: string, subfolder = ''): string =>
204-
subfolder ? `${subfolder}/${filename}` : filename
205-
206-
/** Creates annotated filepath in format used by folder_paths.py */
207-
export function createAnnotatedPath(
208-
item: string | ResultItem,
209-
options: { rootFolder?: string; subfolder?: string } = {}
210-
): string {
211-
const { rootFolder = 'input', subfolder } = options
212-
if (typeof item === 'string')
213-
return `${createPath(item, subfolder)}${createAnnotation(item, rootFolder)}`
214-
return `${createPath(item.filename ?? '', item.subfolder)}${
215-
item.type ? createAnnotation(item.type, rootFolder) : ''
216-
}`
217-
}
218196

219197
/**
220198
* Parses a filepath into its filename and subfolder components.

packages/shared-frontend-utils/src/networkUtil.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import axios from 'axios'
22

3-
import { electronAPI } from './envUtil'
4-
import { isValidUrl } from './formatUtil'
5-
63
const VALID_STATUS_CODES = [200, 201, 301, 302, 307, 308]
74
export const checkUrlReachable = async (url: string): Promise<boolean> => {
85
try {
@@ -14,17 +11,6 @@ export const checkUrlReachable = async (url: string): Promise<boolean> => {
1411
}
1512
}
1613

17-
/**
18-
* Check if a mirror is reachable from the electron App.
19-
* @param mirror - The mirror to check.
20-
* @returns True if the mirror is reachable, false otherwise.
21-
*/
22-
export const checkMirrorReachable = async (mirror: string) => {
23-
return (
24-
isValidUrl(mirror) && (await electronAPI().NetWork.canAccessUrl(mirror))
25-
)
26-
}
27-
2814
/**
2915
* Checks if the user is likely in mainland China by:
3016
* 1. Checking navigator.language

src/components/install/mirror/MirrorItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ import { computed, onMounted, ref, watch } from 'vue'
6060
import UrlInput from '@/components/common/UrlInput.vue'
6161
import type { UVMirror } from '@/constants/uvMirrors'
6262
import { st } from '@/i18n'
63+
import { checkMirrorReachable } from '@/utils/electronMirrorCheck'
6364
import { normalizeI18nKey } from '@/utils/formatUtil'
64-
import { checkMirrorReachable } from '@/utils/networkUtil'
6565
import { ValidationState } from '@/utils/validationUtil'
6666
6767
const FILE_URL_SCHEME = 'file://'

src/extensions/core/electronAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { useToastStore } from '@/platform/updates/common/toastStore'
66
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
77
import { app } from '@/scripts/app'
88
import { useDialogService } from '@/services/dialogService'
9+
import { checkMirrorReachable } from '@/utils/electronMirrorCheck'
910
import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
10-
import { checkMirrorReachable } from '@/utils/networkUtil'
1111

1212
// Desktop documentation URLs
1313
const DESKTOP_DOCS = {

src/renderer/extensions/vueNodes/widgets/composables/useImageUploadWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { InputSpec } from '@/schemas/nodeDefSchema'
99
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
1010
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
1111
import { isImageUploadInput } from '@/types/nodeDefAugmentation'
12-
import { createAnnotatedPath } from '@/utils/formatUtil'
12+
import { createAnnotatedPath } from '@/utils/createAnnotatedPath'
1313
import { addToComboValues } from '@/utils/litegraphUtil'
1414

1515
const ACCEPTED_IMAGE_TYPES = 'image/png,image/jpeg,image/webp'

src/utils/createAnnotatedPath.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ResultItem } from '@/schemas/apiSchema'
2+
3+
const hasAnnotation = (filepath: string): boolean =>
4+
/\[(input|output|temp)\]/i.test(filepath)
5+
6+
const createAnnotation = (filepath: string, rootFolder = 'input'): string =>
7+
!hasAnnotation(filepath) && rootFolder !== 'input' ? ` [${rootFolder}]` : ''
8+
9+
const createPath = (filename: string, subfolder = ''): string =>
10+
subfolder ? `${subfolder}/${filename}` : filename
11+
12+
/** Creates annotated filepath in format used by folder_paths.py */
13+
export function createAnnotatedPath(
14+
item: string | ResultItem,
15+
options: { rootFolder?: string; subfolder?: string } = {}
16+
): string {
17+
const { rootFolder = 'input', subfolder } = options
18+
if (typeof item === 'string')
19+
return `${createPath(item, subfolder)}${createAnnotation(item, rootFolder)}`
20+
return `${createPath(item.filename ?? '', item.subfolder)}${
21+
item.type ? createAnnotation(item.type, rootFolder) : ''
22+
}`
23+
}

src/utils/electronMirrorCheck.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { electronAPI } from '@/utils/envUtil'
2+
import { isValidUrl } from '@/utils/formatUtil'
3+
4+
/**
5+
* Check if a mirror is reachable from the electron App.
6+
* @param mirror - The mirror to check.
7+
* @returns True if the mirror is reachable, false otherwise.
8+
*/
9+
export const checkMirrorReachable = async (mirror: string) => {
10+
return (
11+
isValidUrl(mirror) && (await electronAPI().NetWork.canAccessUrl(mirror))
12+
)
13+
}

0 commit comments

Comments
 (0)