From 04756e24386a70db67d0279e3bbbd8d51f794f84 Mon Sep 17 00:00:00 2001 From: mayar osama Date: Wed, 1 Nov 2023 11:05:39 +0200 Subject: [PATCH 1/2] Adding validation for v2 --- .../src/components/select_vm_image.vue | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/playground/src/components/select_vm_image.vue b/packages/playground/src/components/select_vm_image.vue index 26f318148f..3f543407fb 100644 --- a/packages/playground/src/components/select_vm_image.vue +++ b/packages/playground/src/components/select_vm_image.vue @@ -84,14 +84,20 @@ watch( ); function isFlistExist(flist: string) { - return fetch(flist + ".md5") - .then(res => res.status !== 200) - .then(invalid => { - if (invalid) throw new Error(); - }) - .catch(() => { - return { message: `Couldn't find flist with the provided url.`, isExist: false }; - }); + if (flist.includes(".flist")) { + return fetch(flist + ".md5") + .then(res => res.status !== 200) + .then(invalid => { + if (invalid) throw new Error(); + }) + .catch(() => { + return { message: `Couldn't find flist with the provided url.`, isExist: false }; + }); + } else { + if (!flist.endsWith(".fl")) { + return { message: `Not supported flist url` }; + } + } } From 966184e730644809c5ccdf7a5884b26c4ce43c9a Mon Sep 17 00:00:00 2001 From: mayar osama Date: Wed, 1 Nov 2023 13:31:23 +0200 Subject: [PATCH 2/2] fixing type error --- .../src/components/select_vm_image.vue | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/playground/src/components/select_vm_image.vue b/packages/playground/src/components/select_vm_image.vue index 3f543407fb..1bfaa5a8a1 100644 --- a/packages/playground/src/components/select_vm_image.vue +++ b/packages/playground/src/components/select_vm_image.vue @@ -83,19 +83,17 @@ watch( { immediate: true, deep: true }, ); -function isFlistExist(flist: string) { +async function isFlistExist(flist: string) { if (flist.includes(".flist")) { - return fetch(flist + ".md5") - .then(res => res.status !== 200) - .then(invalid => { - if (invalid) throw new Error(); - }) - .catch(() => { - return { message: `Couldn't find flist with the provided url.`, isExist: false }; - }); + try { + const res = await fetch(flist + ".md5"); + if (res.status !== 200) throw new Error(); + } catch (error) { + return { message: `Couldn't find flist with the provided url.`, isExist: false }; + } } else { if (!flist.endsWith(".fl")) { - return { message: `Not supported flist url` }; + return { message: `Not a supported flist url` }; } } }