diff --git a/locales/en.json b/locales/en.json index 2d67d6bf..c9ba78dd 100644 --- a/locales/en.json +++ b/locales/en.json @@ -352,10 +352,10 @@ "cmdAuthLoginDescription": "Authenticate the CLI session using the Fleek Platform Web app. Open the URL in your favourite browser to initiate the browser-based login process. Select your preferred authentication method and return to CLI once completed.", "cmdAuthLogoutDescription": "Ends your active CLI session, securing your account. Disables access to personal features such as storage and site deployment until re-authentication.", "invalidHostname": "Invalid hostname `{hostname}`. Please try again!", - "functionsUseAssets": "Path to assets to be uploaded to Fleek Storage along with your function code. Accessible via the global variable `fleek.env.ASSETS_URL`.", - "assetsPathIsNotAFolder": "The provided assets path is not a valid folder", + "functionsUseAssets": "Choose the assets directory to upload alongside your function. These assets will be accessible in your code through 'fleek.env.ASSETS_CID', e.g. /User/MyProject/assets.", + "assetsPathIsNotAFolder": "The specified path doesn't exist or is not a valid directory. Please provide a valid directory path containing your assets.", "uploadingAssets": "Uploading assets...", "assetsUploadSuccess": "Assets uploaded successfully", - "uploadAssetsFailed": "Failed to upload assets for function", + "uploadAssetsFailed": "Failed to upload function assets to Fleek. Check your network connection and try again.", "assetsNotSupportedInSgx": "Function assets are not supported in SGX" } diff --git a/src/commands/functions/deploy.ts b/src/commands/functions/deploy.ts index ea1dd531..71515f0c 100644 --- a/src/commands/functions/deploy.ts +++ b/src/commands/functions/deploy.ts @@ -28,10 +28,7 @@ type DeployActionArgs = { assetsPath?: string; }; -const deployAction: SdkGuardedFunction = async ({ - sdk, - args, -}) => { +const deployAction: SdkGuardedFunction = async ({ sdk, args }) => { const env = getEnvironmentVariables({ env: args.env, envFile: args.envFile }); const functionToDeploy = await getFunctionOrPrompt({ name: args.name, sdk }); const filePath = await getFunctionPathOrPrompt({ path: args.filePath }); @@ -56,21 +53,11 @@ const deployAction: SdkGuardedFunction = async ({ return; } - let assetsCid: string | undefined = undefined; - if (assetsPath) { - console.log('assetsPath', assetsPath); - if (!(await isValidFolder(assetsPath))) { - output.error(t('assetsPathIsNotAFolder')); - return; - } - output.spinner(t('uploadingAssets')); - assetsCid = await uploadFunctionAssets({ - sdk, - assetsPath, - functionName: functionToDeploy.name, - }); - output.success(t('assetsUploadSuccess')); - } + const assetsCid = await uploadFunctionAssets({ + sdk, + assetsPath, + functionName: functionToDeploy.name, + }); const filePathToUpload = isSGX ? await getWasmCodeFromPath({ filePath }) @@ -87,7 +74,7 @@ const deployAction: SdkGuardedFunction = async ({ { format: t('uploadProgress', { action: t('uploadCodeToIpfs') }), }, - cliProgress.Presets.shades_grey, + cliProgress.Presets.shades_grey ); const uploadResult = await getUploadResult({ @@ -107,7 +94,7 @@ const deployAction: SdkGuardedFunction = async ({ action: 'deploy', tryAgain: t('tryAgain'), message: t('uploadToIpfsFailed'), - }), + }) ); return; @@ -133,7 +120,7 @@ const deployAction: SdkGuardedFunction = async ({ action: 'deploy', tryAgain: t('tryAgain'), message: t('uploadToIpfsFailed'), - }), + }) ); return; @@ -187,9 +174,7 @@ const deployAction: SdkGuardedFunction = async ({ output.spinner(t('networkFetchMappings')); try { // TODO: The `fleek-test` address should be an env var - await fetch( - `https://fleek-test.network/services/0/ipfs/${uploadResult.pin.cid}`, - ); + await fetch(`https://fleek-test.network/services/0/ipfs/${uploadResult.pin.cid}`); } catch { output.error(t('networkFetchFailed')); return; @@ -207,20 +192,16 @@ const deployAction: SdkGuardedFunction = async ({ output.printNewLine(); output.log(`Blake3 Hash: ${blake3Hash} `); output.log( - `Invoke by sending request to https://fleek-test.network/services/3 with payload of {hash: , decrypt: true, inputs: "foo"}`, + `Invoke by sending request to https://fleek-test.network/services/3 with payload of {hash: , decrypt: true, inputs: "foo"}` ); output.printNewLine(); output.hint(`Here's an example:`); - output.link( - `curl ${functionToDeploy.invokeUrl} --data '{"hash": "${blake3Hash}", "decrypt": true, "input": "foo"}'`, - ); + output.link(`curl ${functionToDeploy.invokeUrl} --data '{"hash": "${blake3Hash}", "decrypt": true, "input": "foo"}'`); } if (isUntrustedPublicEnvironment) { output.log(t('callFleekFunctionByNetworkUrlReq')); - output.link( - `https://fleek-test.network/services/1/ipfs/${uploadResult.pin.cid}`, - ); + output.link(`https://fleek-test.network/services/1/ipfs/${uploadResult.pin.cid}`); } }; diff --git a/src/commands/functions/utils/uploadFunctionAssets.ts b/src/commands/functions/utils/uploadFunctionAssets.ts index c2ded79d..2897b4b3 100644 --- a/src/commands/functions/utils/uploadFunctionAssets.ts +++ b/src/commands/functions/utils/uploadFunctionAssets.ts @@ -1,6 +1,7 @@ import type { FleekSdk } from '@fleek-platform/sdk/node'; import { output } from '../../../cli'; import { t } from '../../../utils/translation'; +import { isValidFolder } from '@fleek-platform/utils-validation'; export const uploadFunctionAssets = async ({ sdk, @@ -8,9 +9,18 @@ export const uploadFunctionAssets = async ({ functionName, }: { sdk: FleekSdk; - assetsPath: string; functionName: string; -}): Promise => { + assetsPath?: string; +}): Promise => { + if (!assetsPath) { + return; + } + + if (!(await isValidFolder(assetsPath))) { + output.error(t('assetsPathIsNotAFolder')); + return; + } + try { output.spinner(t('uploadingAssets')); const result = await sdk.storage().uploadDirectory({