|
2 | 2 | import { Modal } from '$lib/components'; |
3 | 3 | import { Logs } from '@appwrite.io/pink-svelte'; |
4 | 4 | import { app } from '$lib/stores/app'; |
5 | | - import type { Models } from '@appwrite.io/console'; |
| 5 | + import { ProxyRuleStatus, type Models } from '@appwrite.io/console'; |
| 6 | + import { Button } from '$lib/elements/forms'; |
| 7 | + import { getApexDomain } from '$lib/helpers/tlds'; |
| 8 | + import { isCloud } from '$lib/system'; |
| 9 | + import { sdk } from '$lib/stores/sdk'; |
| 10 | + import { page } from '$app/state'; |
| 11 | + import { Dependencies } from '$lib/constants'; |
| 12 | + import { invalidate } from '$app/navigation'; |
| 13 | + import { addNotification } from '$lib/stores/notifications'; |
| 14 | + import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; |
6 | 15 |
|
7 | 16 | let { |
8 | 17 | show = $bindable(false), |
9 | | - selectedProxyRule |
| 18 | + selectedProxyRule, |
| 19 | + domainsList |
10 | 20 | }: { |
11 | 21 | show: boolean; |
12 | 22 | selectedProxyRule: Models.ProxyRule; |
| 23 | + domainsList?: Models.DomainsList; |
13 | 24 | } = $props(); |
| 25 | +
|
| 26 | + let error = $state(null); |
| 27 | +
|
| 28 | + async function retryDomain() { |
| 29 | + error = null; |
| 30 | +
|
| 31 | + try { |
| 32 | + const apexDomain = getApexDomain(selectedProxyRule.domain); |
| 33 | + const domain = domainsList?.domains.find((d) => d.domain === apexDomain); |
| 34 | + if (isCloud && domain) { |
| 35 | + await sdk.forConsole.domains.updateNameservers({ |
| 36 | + domainId: domain.$id |
| 37 | + }); |
| 38 | + } |
| 39 | + } catch { |
| 40 | + // Ignore error |
| 41 | + } |
| 42 | +
|
| 43 | + try { |
| 44 | + selectedProxyRule = await sdk |
| 45 | + .forProject(page.params.region, page.params.project) |
| 46 | + .proxy.updateRuleVerification({ ruleId: selectedProxyRule.$id }); |
| 47 | +
|
| 48 | + await invalidate(Dependencies.DOMAINS); |
| 49 | + show = false; |
| 50 | + addNotification({ |
| 51 | + type: 'success', |
| 52 | + message: 'Domain verified successfully' |
| 53 | + }); |
| 54 | + trackEvent(Submit.DomainUpdateVerification); |
| 55 | + } catch (e) { |
| 56 | + error = e.message; |
| 57 | + trackError(e, Submit.DomainUpdateVerification); |
| 58 | + } |
| 59 | + } |
| 60 | +
|
| 61 | + $effect(() => { |
| 62 | + if (!show) { |
| 63 | + error = null; |
| 64 | + } |
| 65 | + }); |
14 | 66 | </script> |
15 | 67 |
|
16 | | -<Modal title="Certificate logs" bind:show size="m" hideFooter> |
| 68 | +<Modal |
| 69 | + title="Certificate logs" |
| 70 | + size="m" |
| 71 | + bind:show |
| 72 | + bind:error |
| 73 | + onSubmit={retryDomain} |
| 74 | + hideFooter={selectedProxyRule.status !== ProxyRuleStatus.Unverified}> |
17 | 75 | <Logs logs={selectedProxyRule.logs} theme={$app.themeInUse} showScrollButton height="250px" /> |
| 76 | + <svelte:fragment slot="footer"> |
| 77 | + {#if selectedProxyRule.status === ProxyRuleStatus.Unverified} |
| 78 | + <Button submit>Retry</Button> |
| 79 | + {/if} |
| 80 | + </svelte:fragment> |
18 | 81 | </Modal> |
0 commit comments