From 92aae397e693fc21f920593f450797bf88bc8d62 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Mon, 10 Oct 2022 15:59:32 +0300 Subject: [PATCH] requested changes --- content/publish/form.json | 8 ++-- src/@utils/aquarius.ts | 2 +- src/@utils/docker.ts | 43 ++----------------- src/components/@shared/FileIcon/index.tsx | 2 +- .../FormFields/ContainerInput/index.tsx | 29 +++++++------ 5 files changed, 24 insertions(+), 60 deletions(-) diff --git a/content/publish/form.json b/content/publish/form.json index ab4657736..e625624ac 100644 --- a/content/publish/form.json +++ b/content/publish/form.json @@ -54,9 +54,9 @@ }, { "name": "dockerImageCustom", - "label": "Docker Image URL", - "placeholder": "e.g. oceanprotocol/algo_dockers:node-vibrant or https://example.com/image_path:image_tag", - "help": "Provide the name and the tag of a public Docker hub image or the full URL if you have it hosted in a 3rd party repository", + "label": "Custom Docker Image", + "placeholder": "e.g. oceanprotocol/algo_dockers:node-vibrant or quay.io/startx/mariadb", + "help": "Provide the name and the tag of a public Docker hub image or the custom image if you have it hosted in a 3rd party repository", "type": "container", "required": true }, @@ -69,7 +69,7 @@ }, { "name": "dockerImageCustomEntrypoint", - "label": "Docker Entrypoint", + "label": "Docker Image Entrypoint", "placeholder": "e.g. python $ALGO", "help": "Provide the entrypoint for your algorithm.", "required": true diff --git a/src/@utils/aquarius.ts b/src/@utils/aquarius.ts index 50f17c0da..b5b6119b7 100644 --- a/src/@utils/aquarius.ts +++ b/src/@utils/aquarius.ts @@ -268,7 +268,7 @@ export async function getAlgorithmDatasetsForCompute( const query = generateBaseQuery(baseQueryParams) const computeDatasets = await queryMetadata(query, cancelToken) - if (computeDatasets.totalResults === 0) return [] + if (computeDatasets?.totalResults === 0) return [] const datasets = await transformAssetToAssetSelection( datasetProviderUri, diff --git a/src/@utils/docker.ts b/src/@utils/docker.ts index cf514f746..ee917828d 100644 --- a/src/@utils/docker.ts +++ b/src/@utils/docker.ts @@ -1,6 +1,5 @@ import { LoggerInstance } from '@oceanprotocol/lib' import axios from 'axios' -import isUrl from 'is-url-superb' import { toast } from 'react-toastify' export interface dockerContainerInfo { @@ -8,7 +7,7 @@ export interface dockerContainerInfo { checksum: string } -async function getDockerHubImageChecksum( +export async function getContainerChecksum( image: string, tag: string ): Promise { @@ -30,7 +29,7 @@ async function getDockerHubImageChecksum( response.data.status !== 'success' ) { toast.error( - 'Could not fetch docker hub image info. Please check container image and tag and try again' + 'Could not fetch docker hub image informations. If you have it hosted in a 3rd party repository please fill in the container checksum manually.' ) return containerInfo } @@ -40,44 +39,8 @@ async function getDockerHubImageChecksum( } catch (error) { LoggerInstance.error(error.message) toast.error( - 'Could not fetch docker hub image info. Please check container image and tag and try again' + 'Could not fetch docker hub image informations. If you have it hosted in a 3rd party repository please fill in the container checksum manually.' ) return containerInfo } } - -async function validateContainerImageUrl( - imageURL: string -): Promise { - const containerInfo: dockerContainerInfo = { - exists: false, - checksum: null - } - try { - const response = await axios.head(imageURL) - if (!response || response.status !== 200) { - toast.error( - 'Could not fetch docker image info. Please check URL and try again' - ) - return containerInfo - } - containerInfo.exists = true - return containerInfo - } catch (error) { - LoggerInstance.error(error.message) - toast.error( - 'Could not fetch docker image info. Please check URL and try again' - ) - return containerInfo - } -} - -export async function getContainerChecksum( - dockerImage: string, - tag: string -): Promise { - const isValid = isUrl(dockerImage) - ? await validateContainerImageUrl(dockerImage) - : await getDockerHubImageChecksum(dockerImage, tag) - return isValid -} diff --git a/src/components/@shared/FileIcon/index.tsx b/src/components/@shared/FileIcon/index.tsx index 0d0e3fbb0..958f490ce 100644 --- a/src/components/@shared/FileIcon/index.tsx +++ b/src/components/@shared/FileIcon/index.tsx @@ -1,5 +1,5 @@ import React, { ReactElement } from 'react' -import { filesize } from 'filesize' +import filesize from 'filesize' import cleanupContentType from '@utils/cleanupContentType' import styles from './index.module.css' import Loader from '@shared/atoms/Loader' diff --git a/src/components/@shared/FormFields/ContainerInput/index.tsx b/src/components/@shared/FormFields/ContainerInput/index.tsx index 5c93e1056..400088ae1 100644 --- a/src/components/@shared/FormFields/ContainerInput/index.tsx +++ b/src/components/@shared/FormFields/ContainerInput/index.tsx @@ -24,22 +24,23 @@ export default function ContainerInput(props: InputProps): ReactElement { try { setIsLoading(true) const parsedContainerValue = container?.split(':') - const imageNname = parsedContainerValue?.slice(0, -1).join(':') + const imageName = + parsedContainerValue?.length > 1 + ? parsedContainerValue?.slice(0, -1).join(':') + : parsedContainerValue[0] const tag = parsedContainerValue?.length > 1 ? parsedContainerValue?.at(-1) : '' - const containerInfo = await getContainerChecksum(imageNname, tag) - if (containerInfo.exists) { - setFieldValue('metadata.dockerImageCustom', imageNname) - setFieldValue('metadata.dockerImageCustomTag', tag) - setChecked(true) - if (containerInfo.checksum) { - setFieldValue( - 'metadata.dockerImageCustomChecksum', - containerInfo.checksum - ) - helpersChecksum.setTouched(false) - setIsValid(true) - } + const containerInfo = await getContainerChecksum(imageName, tag) + setFieldValue('metadata.dockerImageCustom', imageName) + setFieldValue('metadata.dockerImageCustomTag', tag) + setChecked(true) + if (containerInfo.checksum) { + setFieldValue( + 'metadata.dockerImageCustomChecksum', + containerInfo.checksum + ) + helpersChecksum.setTouched(false) + setIsValid(true) } } catch (error) { setFieldError(`${field.name}[0].url`, error.message)