From f992cdbbaf562c344cb3f31007d3d1e1aeb24b3a Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 4 Jul 2024 15:07:09 +0200 Subject: [PATCH] feat: download deployment --- src/lib/components/filters/filters.svelte | 2 -- src/lib/sdk/functions.ts | 26 +++++++++++++++++++ src/lib/stores/sdk.ts | 4 ++- .../auth/security/updateMockNumbers.svelte | 2 -- .../function-[function]/table.svelte | 17 ++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/lib/sdk/functions.ts diff --git a/src/lib/components/filters/filters.svelte b/src/lib/components/filters/filters.svelte index 4eba0cbca..cae6f2878 100644 --- a/src/lib/components/filters/filters.svelte +++ b/src/lib/components/filters/filters.svelte @@ -98,8 +98,6 @@ function toggleMobileModal() { showFiltersMobile = !showFiltersMobile; } - - $: console.log(selectedColumn, operatorKey, value, arrayValues);
diff --git a/src/lib/sdk/functions.ts b/src/lib/sdk/functions.ts new file mode 100644 index 000000000..df494e54e --- /dev/null +++ b/src/lib/sdk/functions.ts @@ -0,0 +1,26 @@ +import type { Client } from '@appwrite.io/console'; + +export class Func { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + async downloadDeployment(functionId: string, deploymentId: string): Promise { + const path = `/functions/${functionId}/deployments/${deploymentId}/download`; + const params = { + functionId, + deploymentId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'GET', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } +} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 8dacdc079..a3e31c050 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -23,6 +23,7 @@ import { } from '@appwrite.io/console'; import { Billing } from '../sdk/billing'; import { Sources } from '$lib/sdk/sources'; +import { Func } from '$lib/sdk/functions'; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; @@ -74,7 +75,8 @@ export const sdk = { console: new Console(clientConsole), assistant: new Assistant(clientConsole), billing: new Billing(clientConsole), - sources: new Sources(clientConsole) + sources: new Sources(clientConsole), + func: new Func(clientConsole) }, get forProject() { const projectId = getProjectId(); diff --git a/src/routes/console/project-[project]/auth/security/updateMockNumbers.svelte b/src/routes/console/project-[project]/auth/security/updateMockNumbers.svelte index 353783dbc..faf065fc1 100644 --- a/src/routes/console/project-[project]/auth/security/updateMockNumbers.svelte +++ b/src/routes/console/project-[project]/auth/security/updateMockNumbers.svelte @@ -48,8 +48,6 @@ numbers.splice(index, 1); numbers = numbers; } - - $: console.log(numbers, initialNumbers);
diff --git a/src/routes/console/project-[project]/functions/function-[function]/table.svelte b/src/routes/console/project-[project]/functions/function-[function]/table.svelte index 3791a8d5d..a0e0a9b16 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/table.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/table.svelte @@ -26,6 +26,7 @@ import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import Cancel from './cancel.svelte'; + import { sdk } from '$lib/stores/sdk'; export let columns: Column[]; export let data: PageData; @@ -41,6 +42,13 @@ function handleActivate() { invalidate(Dependencies.DEPLOYMENTS); } + + async function getDownload(deploymentId: string) { + return ( + (await sdk.forConsole.func.downloadDeployment($func.$id, deploymentId)).toString() + + '&mode=admin' + ); + } @@ -139,6 +147,15 @@ href={`/console/project-${$page.params.project}/functions/function-${$page.params.function}/deployment-${deployment.$id}`}> Logs + {#if deployment.status === 'ready'} + {#await getDownload(deployment.$id)} + Download + {:then href} + + Download + + {/await} + {/if} {#if deployment.status === 'processing' || deployment.status === 'building'}