feat: download button

This commit is contained in:
Arman committed 2024-07-08 10:22:34 +02:00
1 parent f992cdbbaf
commit 343b9f987f
6 files changed
+27 -43

No files matched your search

+4 -4
View File
@@ -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",
+1 -1
View File
@@ -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",
-26
View File
@@ -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<string> {
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
);
}
}
+1 -3
View File
@@ -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();
@@ -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</Button>
{/if}
{#if $deployment.status === 'ready'}
<Button text href={getDownload($deployment.$id)} class="u-margin-inline-end-16">
Download code
</Button>
{/if}
<Button
secondary
disabled={data.activeDeployment}
@@ -43,9 +43,9 @@
invalidate(Dependencies.DEPLOYMENTS);
}
async function getDownload(deploymentId: string) {
function getDownload(deploymentId: string) {
return (
(await sdk.forConsole.func.downloadDeployment($func.$id, deploymentId)).toString() +
sdk.forProject.functions.getDeploymentDownload($func.$id, deploymentId).toString() +
'&mode=admin'
);
}
@@ -148,13 +148,12 @@
Logs
</DropListLink>
{#if deployment.status === 'ready'}
{#await getDownload(deployment.$id)}
<DropListItem icon="terminal">Download</DropListItem>
{:then href}
<DropListLink icon="terminal" external {href}>
Download
</DropListLink>
{/await}
<DropListLink
icon="download"
href={getDownload(deployment.$id)}
on:click={() => (showDropdown[index] = false)}>
Download
</DropListLink>
{/if}
{#if deployment.status === 'processing' || deployment.status === 'building'}
<DropListItem