Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/routes/(auth)/(project)/domain/cdn-downgrade/+page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { redirect, error } from '@sveltejs/kit'
import api from '$lib/api'

export async function load ({ url, parent, fetch }) {
const { project } = await parent()
const domainName = url.searchParams.get('domain')

/** @type {Api.Response<Api.Domain>} */
const domain = await api.invoke('domain.get', { project, domain: domainName }, fetch)
if (!domain.ok) {
if (domain.error?.notFound) redirect(302, `/domain?project=${project}`)
error(500, domain.error?.message)
}
if (!domain.result) redirect(302, `/domain?project=${project}`)
if (!domain.result.cdn) redirect(302, `/domain/detail?project=${project}&domain=${domainName}`)

/** @type {Api.Response<Api.Location>} */
const location = await api.invoke('location.get', { id: domain.result.location }, fetch)
if (!location.ok) {
error(500, location.error?.message)
}
if (!location.result) redirect(302, `/domain?project=${project}`)

return {
domain: domain.result,
location: location.result
}
}
136 changes: 136 additions & 0 deletions src/routes/(auth)/(project)/domain/cdn-downgrade/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<script>
import { onMount } from 'svelte'
import ClipboardJS from 'clipboard'
import { goto } from '$app/navigation'
import * as modal from '$lib/modal'
import api from '$lib/api'

const { data } = $props()

const project = $derived(data.project)
const domain = $derived(data.domain)
const location = $derived(data.location)

onMount(() => {
const copyList = new ClipboardJS('.copy')
return () => {
copyList.destroy()
}
})

function downgradeCdn () {
modal.confirm({
html: `Remove CDN from "${domain.domain}" ?`,
yes: 'Downgrade',
callback: async () => {
const resp = await api.invoke('domain.create', {
project,
location: domain.location,
domain: domain.domain,
wildcard: domain.wildcard,
cdn: false
}, fetch)
if (!resp.ok) {
modal.error({ error: resp.error })
return
}
await goto(`/domain/detail?project=${project}&domain=${domain.domain}`)
}
})
}
</script>

<div class="nm-breadcrumb">
<div class="nm-breadcrumb-item">
<a href={`/domain?project=${project}`} class="nm-link"><h6>Domains</h6></a>
</div>
<div class="nm-breadcrumb-item">
<a href="/domain/detail?project={project}&domain={domain.domain}" class="nm-link"><h6>{domain.domain}</h6></a>
</div>
<div class="nm-breadcrumb-item">
<h6>CDN Downgrade</h6>
</div>
</div>

<br>
<div class="nm-panel is-level-300 _dp-g _g-7">
<div class="lo-12 _g-5">
<h3>
<strong>CDN Downgrade</strong>
</h3>
</div>

<hr>

<div class="content _dp-g _g-6 _w-100pct">
<div class="nm-field">
<label for="input-gsa">Domain</label>
<div class="nm-input">
<input id="input-gsa" value={domain.domain} readonly disabled>
</div>
</div>
<div class="nm-field">
<label for="input-location">Location</label>
<div class="nm-input">
<input id="input-location" value={domain.location} readonly disabled>
</div>
</div>
<div class="nm-field">
<div class="nm-checkbox">
<input id="input-wildcard" type="checkbox" bind:checked={domain.wildcard} disabled readonly>
<label for="input-wildcard">Wildcard</label>
</div>
</div>

<hr>
{#if location.endpoint}
<div class="nm-field">
<label for="input-ip">A Record</label>
{#each [location.endpoint] as ip}
<div class="nm-input -has-icon-right _mgbt-3">
<input id="input-ip" value={ip} readonly disabled>
<span class="icon -is-right copy"
data-clipboard-text={ip}>
<i class="fa-light fa-copy"></i>
</span>
</div>
{/each}
</div>
{/if}
<!--{#if (domain.dnsConfig.ipv6 ?? []).length > 0}-->
<!-- <div class="nm-field">-->
<!-- <label for="input-ipv6">AAAA Record</label>-->
<!-- {#each domain.dnsConfig.ipv6 as ip}-->
<!-- <div class="nm-input -has-icon-right _mgbt-3">-->
<!-- <input id="input-ipv6" value={ip} readonly disabled>-->
<!-- <span class="icon -is-right copy"-->
<!-- data-clipboard-text={ip}>-->
<!-- <i class="fa-light fa-copy"></i>-->
<!-- </span>-->
<!-- </div>-->
<!-- {/each}-->
<!-- </div>-->
<!--{/if}-->
{#if location.cname}
<div class="nm-field">
<label for="input-cname">CNAME Record</label>
{#each [location.cname] as cname}
<div class="nm-input -has-icon-right">
<input id="input-cname" value={cname} readonly disabled>
<span class="icon -is-right copy"
data-clipboard-text={cname}>
<i class="fa-light fa-copy"></i>
</span>
</div>
{/each}
</div>
{/if}
</div>

<hr>
<div class="_dp-f _g-6">
<div class="_dp-f _alit-ct _fw-w">
<button class="nm-button" onclick={downgradeCdn}>Downgrade</button>
</div>
</div>
</div>
24 changes: 1 addition & 23 deletions src/routes/(auth)/(project)/domain/detail/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,6 @@
}
})
}

function downgradeCdn () {
modal.confirm({
html: `Remove CDN from "${domain.domain}" ?`,
yes: 'Downgrade',
callback: async () => {
const resp = await api.invoke('domain.create', {
project,
location: domain.location,
domain: domain.domain,
wildcard: domain.wildcard,
cdn: false
}, fetch)
if (!resp.ok) {
modal.error({ error: resp.error })
return
}
await api.invalidate('domain.get')
handleReload()
}
})
}
</script>

<div class="nm-breadcrumb">
Expand Down Expand Up @@ -457,7 +435,7 @@
<hr>
{#if domain.cdn}
<div class="_dp-f _alit-ct _fw-w">
<button class="nm-button" onclick={downgradeCdn}>Remove CDN (DDoS Protection)</button>
<a class="nm-button" href="/domain/cdn-downgrade?project={project}&domain={domain.domain}">Remove CDN (DDoS Protection)</a>
</div>
{:else}
<div class="_dp-f _alit-ct _fw-w">
Expand Down