From 44cef85c20fdf138ad3e303de26459afdaaea6e6 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Sat, 9 Nov 2024 18:44:27 -0800 Subject: [PATCH] Valdiate. --- src/install/install.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/install/install.ts b/src/install/install.ts index d48cbc9e..93353705 100644 --- a/src/install/install.ts +++ b/src/install/install.ts @@ -102,8 +102,23 @@ export class ComfyUIInstall { }); } - async isValidComfyDirectory(selectedDirectory: string): Promise<{ valid: boolean; errorMessage?: string }> { - //TODO: Implement - return { valid: true }; + public async isValidComfyDirectory(selectedDirectory: string): Promise<{ valid: boolean; errorMessage?: string }> { + try { + const files = await fs.promises.readdir(selectedDirectory); + + if (files.includes('ComfyUI')) { + return { + valid: false, + errorMessage: 'A ComfyUI installation already exists in this directory. Please choose another location.', + }; + } + + return { valid: true }; + } catch (error) { + return { + valid: false, + errorMessage: 'Unable to access the selected directory. Please ensure you have proper permissions.', + }; + } } }