From 47f10d07491072a3b1f032dc10d9571a3c967588 Mon Sep 17 00:00:00 2001
From: Arman
Date: Thu, 24 Nov 2022 14:17:08 +0100
Subject: [PATCH 01/34] fix: account deletion
---
src/routes/console/account/delete.svelte | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/routes/console/account/delete.svelte b/src/routes/console/account/delete.svelte
index a64b1321f..bf1a7d2a3 100644
--- a/src/routes/console/account/delete.svelte
+++ b/src/routes/console/account/delete.svelte
@@ -1,17 +1,19 @@
{#if $collection}
-
- {$collection.name}
-
-
-
-
-
Created: {toLocaleDateTime($collection.$createdAt)}
-
Last Updated: {toLocaleDateTime($collection.$updatedAt)}
-
-
-
-
-
- Update
-
-
-
-
-
- Update Name
-
-
-
-
- {#if showError === 'name'}
- {errorMessage}
- {/if}
-
-
-
-
- Update
-
-
-
-
- Update Permissions
-
- Choose who can access your collection and documents. For more information, check out
- the Permissions Guide in our documentation.
-
-
- {#if collectionPermissions}
-
- {/if}
-
-
- Update
-
-
-
-
- Update Document Security
-
-
-
-
-
- When document security is enabled, users will be able to access documents for
- which they have been granted either Document or Collection permissions .
-
-
- If document security is disabled, users can access documents only if they have Collection permissions . Document permissions will be ignored.
-
-
-
- Update
-
-
-
-
- Delete Collection
-
- The collection will be permanently deleted, including all the documents within it.
- This action is irreversible.
-
-
-
-
- {$collection.name}
-
- Last Updated: {toLocaleDateTime($collection.$updatedAt)}
-
-
-
-
- (showDelete = true)}>Delete
-
-
+
+
+
+
+
{/if}
-
-
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/dangerZone.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/dangerZone.svelte
new file mode 100644
index 000000000..53653a2d4
--- /dev/null
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/dangerZone.svelte
@@ -0,0 +1,31 @@
+
+
+
+ Delete Collection
+
+ The collection will be permanently deleted, including all the documents within it. This
+ action is irreversible.
+
+
+
+
+ {$collection.name}
+
+ Last Updated: {toLocaleDateTime($collection.$updatedAt)}
+
+
+
+
+ (showDelete = true)}>Delete
+
+
+
+
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateName.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateName.svelte
new file mode 100644
index 000000000..e98422453
--- /dev/null
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateName.svelte
@@ -0,0 +1,66 @@
+
+
+
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte
new file mode 100644
index 000000000..9548472e3
--- /dev/null
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte
@@ -0,0 +1,74 @@
+
+
+
+ Update Permissions
+
+ Choose who can access your collection and documents. For more information, check out the Permissions Guide in our documentation.
+
+
+ {#if collectionPermissions}
+
+ {/if}
+
+
+ Update
+
+
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateSecurity.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateSecurity.svelte
new file mode 100644
index 000000000..87d601be6
--- /dev/null
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateSecurity.svelte
@@ -0,0 +1,70 @@
+
+
+
+ Update Document Security
+
+
+
+
+
+ When document security is enabled, users will be able to access documents for which they
+ have been granted either Document or Collection permissions .
+
+
+ If document security is disabled, users can access documents only if they have Collection permissions . Document permissions will be ignored.
+
+
+
+ Update
+
+
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateStatus.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateStatus.svelte
new file mode 100644
index 000000000..6c1353320
--- /dev/null
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updateStatus.svelte
@@ -0,0 +1,68 @@
+
+
+
+ {$collection.name}
+
+
+
+
+
Created: {toLocaleDateTime($collection.$createdAt)}
+
Last Updated: {toLocaleDateTime($collection.$updatedAt)}
+
+
+
+
+
+ Update
+
+
+
From 7f315c19d7007385079d4935f95d229cc8b6343b Mon Sep 17 00:00:00 2001
From: Arman
Date: Fri, 25 Nov 2022 16:27:34 +0100
Subject: [PATCH 11/34] fix: add missing class
---
.../collection-[collection]/settings/updatePermissions.svelte | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte
index 9548472e3..6589c22c0 100644
--- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/updatePermissions.svelte
@@ -61,7 +61,8 @@
Choose who can access your collection and documents. For more information, check out the Permissions Guide in our documentation.
+ rel="noopener noreferrer"
+ class="link">Permissions Guide in our documentation.
{#if collectionPermissions}
From 3c0ff70ea13a2abc939e6deb0fc44e49d03c9b3e Mon Sep 17 00:00:00 2001
From: Arman
Date: Mon, 5 Dec 2022 16:06:14 +0100
Subject: [PATCH 12/34] feat: unbundle webhooks page
---
.../settings/webhooks/[webhook]/+page.svelte | 359 +-----------------
.../webhooks/[webhook]/dangerZone.svelte | 30 ++
.../webhooks/[webhook]/updateEvents.svelte | 109 ++++++
.../webhooks/[webhook]/updateName.svelte | 66 ++++
.../webhooks/[webhook]/updateSecurity.svelte | 110 ++++++
.../webhooks/[webhook]/updateSignature.svelte | 30 ++
.../webhooks/[webhook]/updateURL.svelte | 66 ++++
7 files changed, 423 insertions(+), 347 deletions(-)
create mode 100644 src/routes/console/project-[project]/settings/webhooks/[webhook]/dangerZone.svelte
create mode 100644 src/routes/console/project-[project]/settings/webhooks/[webhook]/updateEvents.svelte
create mode 100644 src/routes/console/project-[project]/settings/webhooks/[webhook]/updateName.svelte
create mode 100644 src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSecurity.svelte
create mode 100644 src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSignature.svelte
create mode 100644 src/routes/console/project-[project]/settings/webhooks/[webhook]/updateURL.svelte
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/+page.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/+page.svelte
index 9b7195420..ab3bd3c63 100644
--- a/src/routes/console/project-[project]/settings/webhooks/[webhook]/+page.svelte
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/+page.svelte
@@ -1,353 +1,18 @@
-
- Signature Key
-
- Add the Signature Key to the X-Appwrite-Webhook-Signature header to validate your
- webhooks. Learn more about webhook validation.
-
-
-
-
-
- (showRegenerate = true)} secondary submit>
- Regenerate Key
-
-
-
-
-
-
-
-
-
-
-
-
-
- Delete Webhook
-
- The webhook will be permanently deleted. This action is irreversible.
-
-
-
- {$webhook.name}
-
- Last updated: {toLocaleDateTime($webhook.$updatedAt)}
-
-
-
-
- (showDelete = true)}>Delete
-
-
+
+
+
+
+
+
-
-
-
-
-
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/dangerZone.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/dangerZone.svelte
new file mode 100644
index 000000000..c531b91a4
--- /dev/null
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/dangerZone.svelte
@@ -0,0 +1,30 @@
+
+
+
+
+ Delete Webhook
+
+ The webhook will be permanently deleted. This action is irreversible.
+
+
+
+ {$webhook.name}
+
+ Last updated: {toLocaleDateTime($webhook.$updatedAt)}
+
+
+
+
+ (showDelete = true)}>Delete
+
+
+
+
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateEvents.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateEvents.svelte
new file mode 100644
index 000000000..919d21402
--- /dev/null
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateEvents.svelte
@@ -0,0 +1,109 @@
+
+
+
+
+
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateName.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateName.svelte
new file mode 100644
index 000000000..1d4fcd0cf
--- /dev/null
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateName.svelte
@@ -0,0 +1,66 @@
+
+
+
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSecurity.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSecurity.svelte
new file mode 100644
index 000000000..dc1d1d8ce
--- /dev/null
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSecurity.svelte
@@ -0,0 +1,110 @@
+
+
+
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSignature.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSignature.svelte
new file mode 100644
index 000000000..7f65c7677
--- /dev/null
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateSignature.svelte
@@ -0,0 +1,30 @@
+
+
+
+ Signature Key
+
+ Add the Signature Key to the X-Appwrite-Webhook-Signature header to validate your webhooks. Learn more about webhook validation.
+
+
+
+
+
+ (showRegenerate = true)} secondary submit>Regenerate Key
+
+
+
+
diff --git a/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateURL.svelte b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateURL.svelte
new file mode 100644
index 000000000..ff775045d
--- /dev/null
+++ b/src/routes/console/project-[project]/settings/webhooks/[webhook]/updateURL.svelte
@@ -0,0 +1,66 @@
+
+
+
From ca4344698ca7ce54dc9814451a1e9e01dcca3103 Mon Sep 17 00:00:00 2001
From: Arman
Date: Mon, 5 Dec 2022 16:39:48 +0100
Subject: [PATCH 13/34] feat: growth is now an enviroment variable
---
.env.example | 1 +
src/lib/actions/analytics.ts | 4 ++--
src/lib/constants.ts | 2 ++
src/lib/stores/app.ts | 3 ++-
4 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/.env.example b/.env.example
index 06149b167..e9457b89f 100644
--- a/.env.example
+++ b/.env.example
@@ -1,4 +1,5 @@
VITE_APPWRITE_ENDPOINT=
+VITE_APPWRITE_GROWTH_ENDPOINT=
VITE_GA_PROJECT=
VITE_SENTRY_DSN=
VITE_CONSOLE_MODE=self-hosted
\ No newline at end of file
diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts
index d169790ac..a57000024 100644
--- a/src/lib/actions/analytics.ts
+++ b/src/lib/actions/analytics.ts
@@ -3,7 +3,7 @@ import googleAnalytics from '@analytics/google-analytics';
import { get } from 'svelte/store';
import { page } from '$app/stores';
import { user } from '$lib/stores/user';
-import { Mode } from '$lib/constants';
+import { growthEndpoint, Mode } from '$lib/constants';
const analytics = Analytics({
app: 'appwrite',
@@ -40,7 +40,7 @@ function sendEventToGrowth(event: string, path: string, data: object = null): vo
email = userStore.email;
name = userStore.name;
}
- fetch('https://growth.appwrite.io/v1/analytics', {
+ fetch(`${growthEndpoint}/analytics`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 721c3db12..b2835c96d 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -7,6 +7,8 @@ export enum Mode {
SELF_HOSTED = 'mode:self-hosted'
}
+export const growthEndpoint = import.meta.env.VITE_APPWRITE_GROWTH_ENDPOINT;
+
export enum Dependencies {
ORGANIZATION = 'dependency:organization',
PROJECT = 'dependency:project',
diff --git a/src/lib/stores/app.ts b/src/lib/stores/app.ts
index 555d36415..f3b03e36b 100644
--- a/src/lib/stores/app.ts
+++ b/src/lib/stores/app.ts
@@ -1,4 +1,5 @@
import { browser } from '$app/environment';
+import { growthEndpoint } from '$lib/constants';
import { writable } from 'svelte/store';
export type AppStore = {
@@ -59,7 +60,7 @@ function createFeedbackStore() {
email?: string,
value?: number
) => {
- const response = await fetch('https://growth.appwrite.io/v1/feedback', {
+ const response = await fetch(`${growthEndpoint}/feedback`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
From c2b139f8173f12169440666c9ec337356e6a3438 Mon Sep 17 00:00:00 2001
From: tglide <26071571+TGlide@users.noreply.github.com>
Date: Mon, 5 Dec 2022 17:19:44 +0000
Subject: [PATCH 14/34] fix: enums no longer creatable without elements
---
src/lib/elements/forms/inputTags.svelte | 15 +++++++++++----
.../attributes/enum.svelte | 4 +++-
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/lib/elements/forms/inputTags.svelte b/src/lib/elements/forms/inputTags.svelte
index 93d31f8ac..82528258e 100644
--- a/src/lib/elements/forms/inputTags.svelte
+++ b/src/lib/elements/forms/inputTags.svelte
@@ -10,9 +10,11 @@
export let autofocus = false;
export let disabled = false;
export let readonly = false;
+ export let required = false;
let value = '';
let element: HTMLInputElement;
+ let hiddenEl: HTMLInputElement;
let error: string;
onMount(() => {
@@ -54,11 +56,11 @@
const handleInvalid = (event: Event) => {
event.preventDefault();
- if (element.validity.valueMissing) {
+ if (hiddenEl.validity.valueMissing) {
error = 'This field is required';
return;
}
- error = element.validationMessage;
+ error = hiddenEl.validationMessage;
};
$: if (value) {
@@ -67,6 +69,12 @@
+
{label}
@@ -98,8 +106,7 @@
bind:value
bind:this={element}
on:keydown={handleInput}
- on:blur={addValue}
- on:invalid={handleInvalid} />
+ on:blur={addValue} />
{#if error}
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte
index 52a45d972..e61b3c030 100644
--- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte
+++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/enum.svelte
@@ -40,6 +40,7 @@
default: data.default
} = selectedAttribute);
}
+
$: if (data.required || data.array) {
data.default = null;
}
@@ -50,7 +51,8 @@
label="Elements"
bind:tags={data.elements}
placeholder="Add elements here"
- readonly={!!selectedAttribute} />
+ readonly={!!selectedAttribute}
+ required />
Date: Mon, 5 Dec 2022 17:41:39 +0000
Subject: [PATCH 15/34] fix: copy not working on http
---
src/lib/components/copy.svelte | 51 +++++++++++++++++++++++++++-------
1 file changed, 41 insertions(+), 10 deletions(-)
diff --git a/src/lib/components/copy.svelte b/src/lib/components/copy.svelte
index 1f0e5dfd8..e9272af34 100644
--- a/src/lib/components/copy.svelte
+++ b/src/lib/components/copy.svelte
@@ -9,23 +9,54 @@
let content = 'Click to copy';
- const copy = async () => {
+ async function securedCopy() {
try {
await navigator.clipboard.writeText(value);
+ } catch {
+ return false;
+ }
+
+ return true;
+ }
+
+ function unsecuredCopy() {
+ const textArea = document.createElement('textarea');
+ textArea.value = value;
+ document.body.appendChild(textArea);
+ textArea.focus();
+ textArea.select();
+
+ let success = true;
+ try {
+ document.execCommand('copy');
+ } catch {
+ success = false;
+ } finally {
+ document.body.removeChild(textArea);
+ }
+
+ return success;
+ }
+
+ async function copy() {
+ // Because of how JS works, unsecuredCopy only runs if securedCopy fails
+ const success = (await securedCopy()) || unsecuredCopy();
+
+ if (success) {
content = 'Copied';
- } catch (error) {
+ } else {
addNotification({
- message: error.message,
+ message: 'Unable to copy to clipboard',
type: 'error'
});
- } finally {
- if (event) {
- trackEvent('click_id_tag', {
- name: event
- });
- }
}
- };
+
+ if (event) {
+ trackEvent('click_id_tag', {
+ name: event
+ });
+ }
+ }
Date: Tue, 6 Dec 2022 13:27:28 +0100
Subject: [PATCH 16/34] feat: add compression algorithm setting
---
.../bucket-[bucket]/settings/+page.svelte | 66 +++++++++++++++----
1 file changed, 54 insertions(+), 12 deletions(-)
diff --git a/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte b/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte
index b7fd139e5..5d1aa0c48 100644
--- a/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte
+++ b/src/routes/console/project-[project]/storage/bucket-[bucket]/settings/+page.svelte
@@ -36,8 +36,9 @@
arePermsDisabled = true,
encryption: boolean = null,
antivirus: boolean = null,
- maxSize: number;
- let byteUnit = writable('KB');
+ maxSize: number,
+ compression: string = null;
+ let byteUnit = writable('MB');
let sizeInBytes: number = null;
const options = [
{ label: 'Bytes', value: 'Bytes' },
@@ -45,6 +46,11 @@
{ label: 'Megabytes', value: 'MB' },
{ label: 'Gigabytes', value: 'GB' }
];
+ const compressionOptions = [
+ { label: 'None', value: 'none' },
+ { label: 'Gzip', value: 'gzip' },
+ { label: 'Zstd', value: 'zstd' }
+ ];
let suggestedExtensions = ['jpg', 'png', 'svg', 'gif', 'html', 'pdf', 'mp4'];
let extensions = $bucket.allowedFileExtensions;
let isExtensionsDisabled = true;
@@ -57,8 +63,10 @@
bucketPermissions ??= $bucket.$permissions;
encryption ??= $bucket.encryption;
antivirus ??= $bucket.antivirus;
- maxSize = $bucket.maximumFileSize / 1024;
+ maxSize = $bucket.maximumFileSize / 1024 / 1024;
+ compression ??= $bucket.compression;
});
+
$: if (bucketPermissions) {
if (symmetricDifference(bucketPermissions, $bucket.$permissions).length) {
arePermsDisabled = false;
@@ -192,6 +200,17 @@
);
}
+ function updateCompression() {
+ updateBucket(
+ {
+ compression
+ },
+ {
+ trackEventName: 'submit_bucket_update_size'
+ }
+ );
+ }
+
function updateAllowedExtensions() {
updateBucket(
{
@@ -234,8 +253,8 @@
id="toggle"
bind:value={enabled} />
- Created: {toLocaleDateTime($bucket.$createdAt)}
- Last Updated: {toLocaleDateTime($bucket.$updatedAt)}
+ Created: {toLocaleDateTime($bucket.$createdAt)}
+ Last Updated: {toLocaleDateTime($bucket.$updatedAt)}
@@ -320,7 +339,7 @@
+
+
diff --git a/src/routes/console/project-[project]/overview/platforms/wizard/android/step1.svelte b/src/routes/console/project-[project]/overview/platforms/wizard/android/step1.svelte
index 2ff8ac01c..7971b24e6 100644
--- a/src/routes/console/project-[project]/overview/platforms/wizard/android/step1.svelte
+++ b/src/routes/console/project-[project]/overview/platforms/wizard/android/step1.svelte
@@ -31,9 +31,9 @@
projectId,
'android',
$createPlatform.name,
+ $createPlatform.key,
undefined,
- undefined,
- $createPlatform.hostname
+ undefined
);
$createPlatform.$id = platform.$id;
@@ -50,11 +50,11 @@
required
bind:value={$createPlatform.name} />
+ bind:value={$createPlatform.key} />
From a14a60fe50addb14c69a35e4b6489826044826df Mon Sep 17 00:00:00 2001
From: tglide <26071571+TGlide@users.noreply.github.com>
Date: Wed, 7 Dec 2022 18:09:42 +0000
Subject: [PATCH 25/34] refactor: rename android overview fields
---
.../overview/platforms/[platform]/android.svelte | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/routes/console/project-[project]/overview/platforms/[platform]/android.svelte b/src/routes/console/project-[project]/overview/platforms/[platform]/android.svelte
index b3d93c638..fa23169a1 100644
--- a/src/routes/console/project-[project]/overview/platforms/[platform]/android.svelte
+++ b/src/routes/console/project-[project]/overview/platforms/[platform]/android.svelte
@@ -10,10 +10,10 @@
import { project } from '../../../store';
import { platform } from './store';
- let packageName: string = null;
+ let key: string = null;
onMount(() => {
- packageName ??= $platform.key;
+ key ??= $platform.key;
});
const updateHostname = async () => {
@@ -22,7 +22,7 @@
$project.$id,
$platform.$id,
$platform.name,
- packageName,
+ key,
$platform.store,
$platform.hostname
);
@@ -52,16 +52,16 @@
- Update
+ Update
From 9b7895c11de4772b8ccd1847198482ce4e4e020d Mon Sep 17 00:00:00 2001
From: tglide <26071571+TGlide@users.noreply.github.com>
Date: Fri, 9 Dec 2022 11:44:38 +0000
Subject: [PATCH 26/34] refactor: add copy helper & fix copyInput
---
src/lib/components/copy.svelte | 38 +++--------------------------
src/lib/components/copyInput.svelte | 14 ++++++-----
src/lib/helpers/copy.ts | 36 +++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 40 deletions(-)
create mode 100644 src/lib/helpers/copy.ts
diff --git a/src/lib/components/copy.svelte b/src/lib/components/copy.svelte
index 2bfa61ddd..0e859e79c 100644
--- a/src/lib/components/copy.svelte
+++ b/src/lib/components/copy.svelte
@@ -2,6 +2,7 @@
import { trackEvent } from '$lib/actions/analytics';
import { tooltip } from '$lib/actions/tooltip';
import { clickOnEnter } from '$lib/helpers/a11y';
+ import { copy } from '$lib/helpers/copy';
import { addNotification } from '$lib/stores/notifications';
export let value: string;
@@ -9,39 +10,8 @@
let content = 'Click to copy';
- async function securedCopy() {
- try {
- await navigator.clipboard.writeText(value);
- } catch {
- return false;
- }
-
- return true;
- }
-
- function unsecuredCopy() {
- const textArea = document.createElement('textarea');
- textArea.value = value;
- document.body.appendChild(textArea);
- textArea.focus();
- textArea.select();
-
- let success = true;
- try {
- document.execCommand('copy');
- } catch {
- success = false;
- } finally {
- document.body.removeChild(textArea);
- }
-
- return success;
- }
-
- async function copy() {
- // securedCopy works only in HTTPS environment.
- // unsecuredCopy works in HTTP and only runs if securedCopy fails.
- const success = (await securedCopy()) || unsecuredCopy();
+ async function handleClick() {
+ const success = await copy(value);
if (success) {
content = 'Copied';
@@ -61,7 +31,7 @@
setTimeout(() => (content = 'Click to copy'))}
use:tooltip={{
diff --git a/src/lib/components/copyInput.svelte b/src/lib/components/copyInput.svelte
index 65bd6bb81..b06f1ae36 100644
--- a/src/lib/components/copyInput.svelte
+++ b/src/lib/components/copyInput.svelte
@@ -1,5 +1,6 @@