forked from xhgit/webup-cloud
Add administrator-controlled IP project entry redirects
This commit is contained in:
1 parent
1f25bbd1f9
commit
2f93fb023a
13 files changed
+439
-5
No files matched your search
@@ -103,6 +103,7 @@ const fields = [
|
||||
["mainDomain", "官网域名"],
|
||||
["deploymentDomain", "用户部署根域名"],
|
||||
["domainDeliveryTarget", "项目入口 CNAME 目标(已接入的 Ingress 域名)"],
|
||||
["ipEntryOrigin", "项目 IP 入口地址(如 http://192.0.2.20,留空关闭)"],
|
||||
["domainTemplate", "用户域名模板({project} 为项目名)"],
|
||||
["faviconUrl", "Favicon HTTPS 地址"],
|
||||
["filing", "备案信息"],
|
||||
|
||||
@@ -59,6 +59,23 @@ async function history(p: any) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function configureIpEntry(site: any, enabled: boolean) {
|
||||
const alias = enabled
|
||||
? prompt("设置 IP 入口的项目路径,例如 student-info", site.ip_entry_alias || "")
|
||||
: "";
|
||||
if (alias === null) return;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await api(`/admin/sites/${site.id}/ip-entry`, {
|
||||
method: "PUT",
|
||||
body: body({ enabled, alias: alias.trim() }),
|
||||
});
|
||||
success.value = result.message;
|
||||
await load();
|
||||
} catch (cause) {
|
||||
error.value = (cause as Error).message;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
@@ -105,6 +122,7 @@ onMounted(load);
|
||||
}}<small class="block"
|
||||
>{{ p.stack }} · {{ p.services }} 服务</small
|
||||
>
|
||||
<small v-if="p.ip_entry_enabled" class="block">IP 入口 /{{ p.ip_entry_alias }}</small>
|
||||
</td>
|
||||
<td>
|
||||
{{ p.display_name }}<small class="block">{{ p.email }}</small>
|
||||
@@ -151,6 +169,14 @@ onMounted(load);
|
||||
封禁</button
|
||||
><button class="link" @click="history(p)">执行记录</button>
|
||||
</div>
|
||||
<div v-if="store.user?.permissions.includes('hosting:write')" class="table-actions">
|
||||
<button class="link" :disabled="busy" @click="configureIpEntry(p, true)">
|
||||
{{ p.ip_entry_enabled ? "编辑 IP 入口" : "开启 IP 入口" }}
|
||||
</button>
|
||||
<button v-if="p.ip_entry_enabled" class="link danger" :disabled="busy" @click="configureIpEntry(p, false)">
|
||||
关闭 IP 入口
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!sites.length">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
import ProjectIpEntry from "./ProjectIpEntry.vue";
|
||||
const projects = ref<any[]>([]),
|
||||
project = ref(""),
|
||||
services = ref<any[]>([]),
|
||||
@@ -240,6 +241,12 @@ onUnmounted(() => clearInterval(timer));
|
||||
output
|
||||
}}</pre>
|
||||
</section>
|
||||
<ProjectIpEntry
|
||||
v-if="project"
|
||||
:key="project"
|
||||
:project-id="project"
|
||||
:deployment-status="deployments[0]?.status"
|
||||
/>
|
||||
<div class="section-title" style="margin-top: 26px">
|
||||
<h3>托管套餐</h3>
|
||||
<span>购买快照,保护既有资源与价格</span>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from "vue";
|
||||
import { api } from "../api";
|
||||
|
||||
const props = defineProps<{ projectId: string; deploymentStatus?: string }>();
|
||||
const entry = ref<{ status: "ACTIVE" | "WAITING" | "DISABLED"; url: string }>();
|
||||
const error = ref("");
|
||||
const loading = ref(false);
|
||||
let request = 0;
|
||||
async function load() {
|
||||
const id = props.projectId;
|
||||
const current = ++request;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await api<typeof entry.value>(`/projects/${id}/ip-entry`);
|
||||
if (request === current && props.projectId === id) entry.value = result;
|
||||
} catch (cause) {
|
||||
if (request === current && props.projectId === id) error.value = (cause as Error).message;
|
||||
} finally {
|
||||
if (request === current) loading.value = false;
|
||||
}
|
||||
}
|
||||
watch([() => props.projectId, () => props.deploymentStatus], load, { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="alert info" aria-label="网站 IP 入口">
|
||||
<strong>网站 IP 入口</strong>
|
||||
<p v-if="error" role="alert">{{ error }}</p>
|
||||
<p v-else-if="entry?.status === 'ACTIVE'">
|
||||
<a class="link" :href="entry.url" target="_blank" rel="noopener noreferrer">{{ entry.url }}</a>
|
||||
</p>
|
||||
<p v-else-if="entry?.status === 'WAITING'">管理员已开启。项目发布并启用域名后,入口会显示在这里。</p>
|
||||
<p v-else-if="entry?.status === 'DISABLED'">管理员尚未为此项目开启。</p>
|
||||
<p v-else>正在读取 IP 入口…</p>
|
||||
<button class="link" :disabled="loading" @click="load">刷新 IP 入口</button>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user