From 2f6ba45084bbc41666a6424a504cccb93c979e95 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 17 Nov 2022 22:50:26 +0530 Subject: [PATCH 01/15] feat: add support foor db pools --- src/lib/stores/project.ts | 65 +++++++++++++++++++ src/lib/stores/sdk.ts | 3 + .../project-[project]/overview/+layout.svelte | 4 +- .../project-[project]/overview/store.ts | 9 +-- 4 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 src/lib/stores/project.ts diff --git a/src/lib/stores/project.ts b/src/lib/stores/project.ts new file mode 100644 index 000000000..54c3b5129 --- /dev/null +++ b/src/lib/stores/project.ts @@ -0,0 +1,65 @@ +import type { Client, Models } from "@aw-labs/appwrite-console"; + +type Payload = { + [key: string]: any; +} + +class Service { + static CHUNK_SIZE = 5*1024*1024; // 5MB + + client: Client; + + constructor(client: Client) { + this.client = client; + } + + static flatten(data: Payload, prefix = ''): Payload { + let output: Payload = {}; + + for (const key in data) { + let value = data[key]; + let finalKey = prefix ? `${prefix}[${key}]` : key; + + if (Array.isArray(value)) { + output = Object.assign(output, this.flatten(value, finalKey)); + } + else { + output[finalKey] = value; + } + } + + return output; + } +} + +export class Project extends Service { + constructor(client: Client) + { + super(client); + } + + /** + * Get usage stats for a project + * + * + * @param {string} range + * @throws {AppwriteException} + * @returns {Promise} + */ + async getUsage(range?: string): Promise { + let path = '/project/usage'; + let payload: Payload = {}; + + console.log("Getting usage") + console.log(range) + + if (typeof range !== 'undefined') { + payload['range'] = range; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } +} \ No newline at end of file diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index cffc23dec..d4b322aba 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -12,6 +12,8 @@ import { Users } from '@aw-labs/appwrite-console'; +import { Project } from './project'; + const endpoint = import.meta.env.VITE_APPWRITE_ENDPOINT?.toString() ?? `${window?.location?.origin}/v1`; const clientConsole = new Client(); @@ -42,6 +44,7 @@ const sdkForProject = { functions: new Functions(clientProject), health: new Health(clientProject), locale: new Locale(clientProject), + project: new Project(clientProject), projects: new Projects(clientProject), storage: new Storage(clientProject), teams: new Teams(clientProject), diff --git a/src/routes/console/project-[project]/overview/+layout.svelte b/src/routes/console/project-[project]/overview/+layout.svelte index fbed69cfb..5f5d31ec1 100644 --- a/src/routes/console/project-[project]/overview/+layout.svelte +++ b/src/routes/console/project-[project]/overview/+layout.svelte @@ -42,7 +42,7 @@ afterNavigate(handle); async function handle() { - const promise = usage.load(projectId, period); + const promise = usage.load(period); if ($usage) { await promise; @@ -51,7 +51,7 @@ function changePeriod(newPeriod: UsagePeriods) { period = newPeriod; - usage.load(projectId, period); + usage.load(period); } diff --git a/src/routes/console/project-[project]/overview/store.ts b/src/routes/console/project-[project]/overview/store.ts index 17c8ad4a1..9534fce80 100644 --- a/src/routes/console/project-[project]/overview/store.ts +++ b/src/routes/console/project-[project]/overview/store.ts @@ -1,16 +1,17 @@ -import { sdkForConsole } from '$lib/stores/sdk'; +import { sdkForProject } from '$lib/stores/sdk'; import { cachedStore } from '$lib/helpers/cache'; import type { Models } from '@aw-labs/appwrite-console'; export const usage = cachedStore< Models.UsageProject, { - load: (projectId: string, range: string) => Promise; + load: (range: string) => Promise; } >('projectUsage', function ({ set }) { return { - load: async (projectId, range) => { - const usages = await sdkForConsole.projects.getUsage(projectId, range); + load: async (range) => { + const usages = await sdkForProject.project.getUsage(range); + console.log(usages) set(usages); } }; From 4e2cecefb571104f0dbbe5a578729f0e17a10242 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 18 Nov 2022 00:28:18 +0530 Subject: [PATCH 02/15] fix: issues with usage --- src/lib/stores/project.ts | 3 --- src/routes/console/project-[project]/overview/store.ts | 1 - 2 files changed, 4 deletions(-) diff --git a/src/lib/stores/project.ts b/src/lib/stores/project.ts index 54c3b5129..eb58f78c6 100644 --- a/src/lib/stores/project.ts +++ b/src/lib/stores/project.ts @@ -50,9 +50,6 @@ export class Project extends Service { let path = '/project/usage'; let payload: Payload = {}; - console.log("Getting usage") - console.log(range) - if (typeof range !== 'undefined') { payload['range'] = range; } diff --git a/src/routes/console/project-[project]/overview/store.ts b/src/routes/console/project-[project]/overview/store.ts index 9534fce80..3da5a6adf 100644 --- a/src/routes/console/project-[project]/overview/store.ts +++ b/src/routes/console/project-[project]/overview/store.ts @@ -11,7 +11,6 @@ export const usage = cachedStore< return { load: async (range) => { const usages = await sdkForProject.project.getUsage(range); - console.log(usages) set(usages); } }; From 6aa50b8b96b7941a710fe097f3f4d3a74f1eb823 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 18 Nov 2022 07:55:19 +0000 Subject: [PATCH 03/15] feat: linter --- .gitpod.yml | 7 +++++++ src/lib/stores/project.ts | 35 +++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 000000000..64f113ab2 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,7 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +tasks: + - init: npm install && npm run build + command: npm run dev diff --git a/src/lib/stores/project.ts b/src/lib/stores/project.ts index eb58f78c6..6ec0ab0c9 100644 --- a/src/lib/stores/project.ts +++ b/src/lib/stores/project.ts @@ -1,11 +1,11 @@ -import type { Client, Models } from "@aw-labs/appwrite-console"; +import type { Client, Models } from '@aw-labs/appwrite-console'; type Payload = { [key: string]: any; -} +}; class Service { - static CHUNK_SIZE = 5*1024*1024; // 5MB + static CHUNK_SIZE = 5 * 1024 * 1024; // 5MB client: Client; @@ -17,13 +17,12 @@ class Service { let output: Payload = {}; for (const key in data) { - let value = data[key]; - let finalKey = prefix ? `${prefix}[${key}]` : key; + const value = data[key]; + const finalKey = prefix ? `${prefix}[${key}]` : key; if (Array.isArray(value)) { output = Object.assign(output, this.flatten(value, finalKey)); - } - else { + } else { output[finalKey] = value; } } @@ -33,8 +32,7 @@ class Service { } export class Project extends Service { - constructor(client: Client) - { + constructor(client: Client) { super(client); } @@ -46,17 +44,22 @@ export class Project extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getUsage(range?: string): Promise { - let path = '/project/usage'; - let payload: Payload = {}; + async getUsage(range?: string): Promise { + const path = '/project/usage'; + const payload: Payload = {}; if (typeof range !== 'undefined') { payload['range'] = range; } const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); + return await this.client.call( + 'get', + uri, + { + 'content-type': 'application/json' + }, + payload + ); } -} \ No newline at end of file +} From 21c3d07a53496d74fd5a3c808165850363de5907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 09:57:01 +0000 Subject: [PATCH 04/15] Sum stats instead of last --- .../project-[project]/overview/+layout.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/console/project-[project]/overview/+layout.svelte b/src/routes/console/project-[project]/overview/+layout.svelte index fbed69cfb..18b05b6b8 100644 --- a/src/routes/console/project-[project]/overview/+layout.svelte +++ b/src/routes/console/project-[project]/overview/+layout.svelte @@ -65,7 +65,7 @@ {:else} {#if $usage} - {@const storage = humanFileSize(last($usage.storage).value)} + {@const storage = humanFileSize(total($usage.storage))}
@@ -89,14 +89,14 @@
- {format(last($usage.documents).value)} + {format(total($usage.documents))}
Documents
- Databases: {format(last($usage.databases).value)} + Databases: {format(total($usage.databases))}
@@ -124,7 +124,7 @@
- Buckets: {format(last($usage.buckets).value)} + Buckets: {format(total($usage.buckets))}
@@ -144,7 +144,7 @@
- {format(last($usage.users).value)} + {format(total($usage.users))}
Users
@@ -165,7 +165,7 @@
- {format(last($usage.executions).value)} + {format(total($usage.executions))}
Executions
From 7fbec8ecbe0b6077bbee7c273b03ff2c25d94948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 24 Nov 2022 09:14:23 +0000 Subject: [PATCH 05/15] Sum stats on usage page --- src/lib/layout/usage.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/layout/usage.svelte b/src/lib/layout/usage.svelte index e34799528..ec13ea4ad 100644 --- a/src/lib/layout/usage.svelte +++ b/src/lib/layout/usage.svelte @@ -57,7 +57,7 @@ {#if count} - {last(count).value} + {total(count)}

{countMetadata.title}

From 7339664a0896033b396e105e63ea2630924ccea2 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Thu, 24 Nov 2022 10:18:48 +0100 Subject: [PATCH 06/15] Fix executions usage --- .../function-[function]/usage/[[period]]/+page.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.svelte index 628eaf11e..91cb30b9e 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/usage/[[period]]/+page.svelte @@ -1,7 +1,7 @@ + + + Sign up - Appwrite + + + + {title} + +
+ + + + + + + By registering, you agree that you have read, understand, and acknowledge our + Privacy Policy + and accept our + General Terms of Use. + + + + +
+
+ + + +
diff --git a/src/routes/register/invite/[slug]/mlh-dark.svg b/src/routes/register/invite/[slug]/mlh-dark.svg new file mode 100644 index 000000000..0e5dbcdf8 --- /dev/null +++ b/src/routes/register/invite/[slug]/mlh-dark.svg @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/routes/register/invite/[slug]/mlh-light.svg b/src/routes/register/invite/[slug]/mlh-light.svg new file mode 100644 index 000000000..2ec970a5d --- /dev/null +++ b/src/routes/register/invite/[slug]/mlh-light.svg @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/routes/register/mlh-logo-black.svg b/src/routes/register/mlh-logo-black.svg deleted file mode 100644 index d8de1b931..000000000 --- a/src/routes/register/mlh-logo-black.svg +++ /dev/null @@ -1,38 +0,0 @@ - - - - mlh-logo-black - Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/routes/register/mlh-logo-white.svg b/src/routes/register/mlh-logo-white.svg deleted file mode 100644 index e7c5aee5f..000000000 --- a/src/routes/register/mlh-logo-white.svg +++ /dev/null @@ -1,38 +0,0 @@ - - - - mlh-logo-white - Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file