Supports certificate downloads, wildcard domains, and more.

This commit is contained in:
yoan
2024-08-26 21:51:30 +08:00
parent 5b05253e21
commit 4a03f930a1
9 changed files with 373 additions and 232 deletions

View File

@@ -16,6 +16,8 @@ export type Domain = {
updated?: string;
deleted?: string;
rightnow?: boolean;
certificate?: string;
privateKey?: string;
expand?: {
lastDeployment?: Deployment;
};

View File

@@ -1,3 +1,5 @@
import JSZip from "jszip";
export function readFileContent(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
@@ -15,3 +17,24 @@ export function readFileContent(file: File): Promise<string> {
reader.readAsText(file);
});
}
export type CustomFile = {
name: string;
content: string;
};
export const saveFiles2ZIP = async (zipName: string, files: CustomFile[]) => {
const zip = new JSZip();
files.forEach((file) => {
zip.file(file.name, file.content);
});
const content = await zip.generateAsync({ type: "blob" });
// Save the zip file to the local system
const link = document.createElement("a");
link.href = URL.createObjectURL(content);
link.download = zipName;
link.click();
};

View File

@@ -62,7 +62,7 @@ const Edit = () => {
const formSchema = z.object({
id: z.string().optional(),
domain: z.string().regex(/^(?!:\/\/)([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,}$/, {
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
message: "请输入正确的域名",
}),
access: z.string().regex(/^[a-zA-Z0-9]+$/, {

View File

@@ -19,6 +19,7 @@ import { Toaster } from "@/components/ui/toaster";
import { Tooltip, TooltipTrigger } from "@/components/ui/tooltip";
import { useToast } from "@/components/ui/use-toast";
import { Domain } from "@/domain/domain";
import { CustomFile, saveFiles2ZIP } from "@/lib/file";
import { convertZulu2Beijing, getDate } from "@/lib/time";
import {
list,
@@ -127,6 +128,22 @@ const Home = () => {
}
};
const handleDownloadClick = async (domain: Domain) => {
const zipName = `${domain.id}-${domain.domain}.zip`;
const files: CustomFile[] = [
{
name: `${domain.domain}.pem`,
content: domain.certificate ? domain.certificate : "",
},
{
name: `${domain.domain}.key`,
content: domain.privateKey ? domain.privateKey : "",
},
];
await saveFiles2ZIP(zipName, files);
};
return (
<>
<div className="">
@@ -253,6 +270,17 @@ const Home = () => {
</Button>
</Show>
<Show when={domain.expiredAt ? true : false}>
<Separator orientation="vertical" className="h-4 mx-2" />
<Button
variant={"link"}
className="p-0"
onClick={() => handleDownloadClick(domain)}
>
</Button>
</Show>
{!domain.enabled && (
<>
<Separator orientation="vertical" className="h-4 mx-2" />