From 294907e0c3d5ec65916f3e89c804232cdfeede7c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Feb 2023 12:59:24 +0100 Subject: [PATCH 1/8] feat: implement cloud --- src/lib/layout/unauthenticated.svelte | 7 +- src/lib/sdk/project.ts | 31 ++ src/lib/sdk/service.ts | 28 ++ src/lib/stores/sdk.ts | 2 + src/lib/system.ts | 2 + src/routes/+error.svelte | 12 + src/routes/+layout.svelte | 2 +- src/routes/+layout.ts | 2 +- .../usage/[[period]]/+page.svelte | 6 +- .../usage/[[period]]/+page.ts | 2 +- .../project-[project]/overview/+layout.svelte | 12 +- .../project-[project]/overview/store.ts | 7 +- src/routes/register/invite/+layout.ts | 9 + .../register/invite/[slug]/+page.svelte | 147 +++++++++ .../register/invite/[slug]/mlh-dark.svg | 293 ++++++++++++++++++ .../register/invite/[slug]/mlh-light.svg | 284 +++++++++++++++++ 16 files changed, 830 insertions(+), 16 deletions(-) create mode 100644 src/lib/sdk/project.ts create mode 100644 src/lib/sdk/service.ts create mode 100644 src/routes/+error.svelte create mode 100644 src/routes/register/invite/+layout.ts create mode 100644 src/routes/register/invite/[slug]/+page.svelte create mode 100644 src/routes/register/invite/[slug]/mlh-dark.svg create mode 100644 src/routes/register/invite/[slug]/mlh-light.svg diff --git a/src/lib/layout/unauthenticated.svelte b/src/lib/layout/unauthenticated.svelte index ba13c1248..e2470d309 100644 --- a/src/lib/layout/unauthenticated.svelte +++ b/src/lib/layout/unauthenticated.svelte @@ -6,6 +6,9 @@ import { base } from '$app/paths'; import { user } from '$lib/stores/user'; + export let imgLight = LoginLight; + export let imgDark = LoginDark; + const technologies = [ 'js', 'flutter', @@ -38,9 +41,9 @@ class="container u-margin-block-start-20 is-not-mobile" style="--p-container-max-size: var(--container-size-large);"> {#if $app.themeInUse === 'dark'} - + {:else} - + {/if} diff --git a/src/lib/sdk/project.ts b/src/lib/sdk/project.ts new file mode 100644 index 000000000..35a5ac9fe --- /dev/null +++ b/src/lib/sdk/project.ts @@ -0,0 +1,31 @@ +import type { Models, Payload } from '@aw-labs/appwrite-console'; +import { Service } from './service'; + +export class Project extends Service { + /** + * Get usage stats for a project + * + * + * @param {string} range + * @throws {AppwriteException} + * @returns {Promise} + */ + 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 + ); + } +} diff --git a/src/lib/sdk/service.ts b/src/lib/sdk/service.ts new file mode 100644 index 000000000..eb63e5771 --- /dev/null +++ b/src/lib/sdk/service.ts @@ -0,0 +1,28 @@ +import type { Client, Payload } from '@aw-labs/appwrite-console'; + +export 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) { + const value = data[key]; + const finalKey = prefix ? `${prefix}[${key}]` : key; + + if (Array.isArray(value)) { + output = Object.assign(output, this.flatten(value, finalKey)); + } else { + output[finalKey] = value; + } + } + + return output; + } +} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index ec05508fc..174da52a7 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -1,3 +1,4 @@ +import { Project } from '$lib/sdk/project'; import { VARS } from '$lib/system'; import { Account, @@ -42,6 +43,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/lib/system.ts b/src/lib/system.ts index fc00cbd8e..596e4faca 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -21,3 +21,5 @@ export const ENV = { }; export const MODE = VARS.CONSOLE_MODE === Mode.CLOUD ? Mode.CLOUD : Mode.SELF_HOSTED; +export const isCloud = MODE === Mode.CLOUD; +export const isSelfHosted = MODE === Mode.SELF_HOSTED; diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte new file mode 100644 index 000000000..4e9d8e540 --- /dev/null +++ b/src/routes/+error.svelte @@ -0,0 +1,12 @@ + + + + {$page.status} + {$page.error.message} + + diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 97d2b07a7..73031b18a 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -59,7 +59,7 @@ } loading.set(false); } else { - if (acceptedRoutes.includes($page.url.pathname)) { + if (acceptedRoutes.some((n) => $page.url.pathname.startsWith(n))) { await goto(`${base}${$page.url.pathname}${$page.url.search}`); } else { await goto(`${base}/login`, { diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index e8ec15b77..aad16fd59 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -28,7 +28,7 @@ export const load: LayoutLoad = async ({ depends, url }) => { '/auth/oauth2/failure' ]; - if (!acceptedRoutes.includes(url.pathname)) { + if (!acceptedRoutes.some((n) => url.pathname.startsWith(n))) { throw redirect(303, '/login'); } } 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 98d3effb8..3ab991246 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..4ad7517de --- /dev/null +++ b/src/routes/register/invite/[slug]/mlh-dark.svg @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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..2b6aab33b --- /dev/null +++ b/src/routes/register/invite/[slug]/mlh-light.svg @@ -0,0 +1,284 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f53edc248d5860d092ec0457d19631cc92e78af9 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Feb 2023 13:21:07 +0100 Subject: [PATCH 2/8] fix: remove unused `Projects` service from project sdk --- search/config.json | 20 ++++++++++++++++++++ src/lib/stores/sdk.ts | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 search/config.json diff --git a/search/config.json b/search/config.json new file mode 100644 index 000000000..457c13078 --- /dev/null +++ b/search/config.json @@ -0,0 +1,20 @@ +{ + "index_uid": "docs", + "start_urls": ["https://appwrite.io/docs"], + "sitemap_urls": [], + "stop_urls": [], + "remove_get_params": true, + "selectors": { + "lvl0": { + "selector": "#top-header a.selected", + "global": true, + "default_value": "Docs" + }, + "lvl1": "h1", + "lvl2": "h2", + "lvl3": "h3", + "lvl4": "h4", + "text": "p" + }, + "selectors_exclude": [] +} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 174da52a7..de55f3d0a 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -44,7 +44,6 @@ const sdkForProject = { health: new Health(clientProject), locale: new Locale(clientProject), project: new Project(clientProject), - projects: new Projects(clientProject), storage: new Storage(clientProject), teams: new Teams(clientProject), users: new Users(clientProject) From 0448fef3e57206595bd7248697e6283efb01c7a1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Feb 2023 13:22:28 +0100 Subject: [PATCH 3/8] Revert "fix: remove unused `Projects` service from project sdk" This reverts commit f53edc248d5860d092ec0457d19631cc92e78af9. --- search/config.json | 20 -------------------- src/lib/stores/sdk.ts | 1 + 2 files changed, 1 insertion(+), 20 deletions(-) delete mode 100644 search/config.json diff --git a/search/config.json b/search/config.json deleted file mode 100644 index 457c13078..000000000 --- a/search/config.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "index_uid": "docs", - "start_urls": ["https://appwrite.io/docs"], - "sitemap_urls": [], - "stop_urls": [], - "remove_get_params": true, - "selectors": { - "lvl0": { - "selector": "#top-header a.selected", - "global": true, - "default_value": "Docs" - }, - "lvl1": "h1", - "lvl2": "h2", - "lvl3": "h3", - "lvl4": "h4", - "text": "p" - }, - "selectors_exclude": [] -} diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index de55f3d0a..174da52a7 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -44,6 +44,7 @@ const sdkForProject = { health: new Health(clientProject), locale: new Locale(clientProject), project: new Project(clientProject), + projects: new Projects(clientProject), storage: new Storage(clientProject), teams: new Teams(clientProject), users: new Users(clientProject) From 4c93d23473325fea5a2205fe4d51deca6a639e9e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Feb 2023 13:23:06 +0100 Subject: [PATCH 4/8] fix: remove unused `Projects` service from project sdk --- src/lib/stores/sdk.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index 174da52a7..de55f3d0a 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -44,7 +44,6 @@ const sdkForProject = { health: new Health(clientProject), locale: new Locale(clientProject), project: new Project(clientProject), - projects: new Projects(clientProject), storage: new Storage(clientProject), teams: new Teams(clientProject), users: new Users(clientProject) From 77ba31859b2ef27738471f40d3e349b2afbfdb8a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Feb 2023 13:31:35 +0100 Subject: [PATCH 5/8] fix: usage --- 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 dc97d6314..fe00d9d62 100644 --- a/src/lib/layout/usage.svelte +++ b/src/lib/layout/usage.svelte @@ -58,7 +58,7 @@ {#if count} - {last(count).value} + {total(count)}

{countMetadata.title}

From 4da4cd6509af4805a008cebe22a0d3022c1be0c6 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 22 Feb 2023 12:19:35 +0000 Subject: [PATCH 6/8] feat: update endpoint --- .gitpod.yml | 9 +++++++++ src/lib/stores/sdk.ts | 2 +- src/routes/register/invite/[slug]/+page.svelte | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 000000000..3c1848749 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,9 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) +# and commit this file to your remote git repository to share the goodness with others. + +# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart + +tasks: + - init: npm install && npm run build + command: npm run dev diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index de55f3d0a..e01f0d655 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -49,4 +49,4 @@ const sdkForProject = { users: new Users(clientProject) }; -export { sdkForConsole, sdkForProject, setProject }; +export { sdkForConsole, sdkForProject, setProject, endpoint }; diff --git a/src/routes/register/invite/[slug]/+page.svelte b/src/routes/register/invite/[slug]/+page.svelte index c1d86c3e9..aa61660f6 100644 --- a/src/routes/register/invite/[slug]/+page.svelte +++ b/src/routes/register/invite/[slug]/+page.svelte @@ -11,7 +11,7 @@ InputText } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; - import { sdkForConsole } from '$lib/stores/sdk'; + import { sdkForConsole, endpoint } from '$lib/stores/sdk'; import { Unauthenticated } from '$lib/layout'; import FormList from '$lib/elements/forms/formList.svelte'; import { Dependencies } from '$lib/constants'; @@ -51,7 +51,7 @@ async function invite() { try { disabled = true; - const res = await fetch(`${VARS.APPWRITE_ENDPOINT}/account/invite`, { + const res = await fetch(`${endpoint}/account/invite`, { method: 'POST', headers: { 'Content-Type': 'application/json' From 6f69d2c8e3a69bd6476519a2cfdba8bf9bfc0a09 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 22 Feb 2023 12:21:59 +0000 Subject: [PATCH 7/8] feat: update endpoint --- src/routes/register/invite/[slug]/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/register/invite/[slug]/+page.svelte b/src/routes/register/invite/[slug]/+page.svelte index aa61660f6..ebf6353c9 100644 --- a/src/routes/register/invite/[slug]/+page.svelte +++ b/src/routes/register/invite/[slug]/+page.svelte @@ -20,7 +20,7 @@ import { page } from '$app/stores'; import LoginLight from '$lib/images/login/login-light-mode.svg'; import LoginDark from '$lib/images/login/login-dark-mode.svg'; - import { isCloud, VARS } from '$lib/system'; + import { isCloud } from '$lib/system'; let slug = $page.params.slug; let imgLight = LoginLight; From 39727607a036534a323101fea876cbe68b05f4f0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 22 Feb 2023 12:23:07 +0000 Subject: [PATCH 8/8] feat: remove gitpod file --- .gitpod.yml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index 3c1848749..000000000 --- a/.gitpod.yml +++ /dev/null @@ -1,9 +0,0 @@ -# This configuration file was automatically generated by Gitpod. -# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) -# and commit this file to your remote git repository to share the goodness with others. - -# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart - -tasks: - - init: npm install && npm run build - command: npm run dev