From f992cdbbaf562c344cb3f31007d3d1e1aeb24b3a Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 4 Jul 2024 15:07:09 +0200 Subject: [PATCH 1/2] 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'} Date: Mon, 8 Jul 2024 10:22:34 +0200 Subject: [PATCH 2/2] feat: download button --- package-lock.json | 8 +++--- package.json | 2 +- src/lib/sdk/functions.ts | 26 ------------------- src/lib/stores/sdk.ts | 4 +-- .../deployment-[deployment]/+page.svelte | 13 ++++++++++ .../function-[function]/table.svelte | 17 ++++++------ 6 files changed, 27 insertions(+), 43 deletions(-) delete mode 100644 src/lib/sdk/functions.ts diff --git a/package-lock.json b/package-lock.json index 2de8854a7..8dec65e39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "@appwrite/console", "dependencies": { - "@appwrite.io/console": "npm:matej-appwrite-console-16x@0.6.6", + "@appwrite.io/console": "npm:matej-appwrite-console-16x@0.6.7", "@appwrite.io/pink": "0.23.0", "@appwrite.io/pink-icons": "0.23.0", "@popperjs/core": "^2.11.8", @@ -150,9 +150,9 @@ }, "node_modules/@appwrite.io/console": { "name": "matej-appwrite-console-16x", - "version": "0.6.6", - "resolved": "https://registry.npmjs.org/matej-appwrite-console-16x/-/matej-appwrite-console-16x-0.6.6.tgz", - "integrity": "sha512-QkHHFqFgfMftRcr5L1fz6784+MLEvL3tKNNpBU5W5mzdfFiAwRoBUigrCSmCIfK2IeiAtZBfGrcf/4k83YbnWA==" + "version": "0.6.7", + "resolved": "https://registry.npmjs.org/matej-appwrite-console-16x/-/matej-appwrite-console-16x-0.6.7.tgz", + "integrity": "sha512-orhonLVjV0vzJE/OrI49DRJ75EAkEa+8QzWy30h1N04jNyAcEGFfx4OKmhWg4uG5XRrmWrrDj9nobHKCiBaDCg==" }, "node_modules/@appwrite.io/pink": { "version": "0.23.0", diff --git a/package.json b/package.json index 709b9258e..7fb2d9f0c 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "e2e:ui": "playwright test tests/e2e --ui" }, "dependencies": { - "@appwrite.io/console": "npm:matej-appwrite-console-16x@0.6.6", + "@appwrite.io/console": "npm:matej-appwrite-console-16x@0.6.7", "@appwrite.io/pink": "0.23.0", "@appwrite.io/pink-icons": "0.23.0", "@popperjs/core": "^2.11.8", diff --git a/src/lib/sdk/functions.ts b/src/lib/sdk/functions.ts deleted file mode 100644 index df494e54e..000000000 --- a/src/lib/sdk/functions.ts +++ /dev/null @@ -1,26 +0,0 @@ -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 a3e31c050..8dacdc079 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -23,7 +23,6 @@ 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`; @@ -75,8 +74,7 @@ export const sdk = { console: new Console(clientConsole), assistant: new Assistant(clientConsole), billing: new Billing(clientConsole), - sources: new Sources(clientConsole), - func: new Func(clientConsole) + sources: new Sources(clientConsole) }, get forProject() { const projectId = getProjectId(); diff --git a/src/routes/console/project-[project]/functions/function-[function]/deployment-[deployment]/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/deployment-[deployment]/+page.svelte index 4e38f0fbf..50cf9d442 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/deployment-[deployment]/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/deployment-[deployment]/+page.svelte @@ -29,6 +29,13 @@ invalidate(Dependencies.DEPLOYMENTS); } + function getDownload(deploymentId: string) { + return ( + sdk.forProject.functions.getDeploymentDownload($func.$id, deploymentId).toString() + + '&mode=admin' + ); + } + onMount(() => { logs = $deployment.buildLogs; if ($deployment.status === 'ready') { @@ -61,6 +68,12 @@ showCancel = true; }}>Cancel {/if} + + {#if $deployment.status === 'ready'} + + {/if}