mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-04 21:44:54 +00:00
Add qiniu deployer
This commit is contained in:
File diff suppressed because one or more lines are too long
2
ui/dist/index.html
vendored
2
ui/dist/index.html
vendored
@@ -5,7 +5,7 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Certimate - Your Trusted SSL Automation Partner</title>
|
||||
<script type="module" crossorigin src="/assets/index-CglXs5Ou.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-CMS-AsEx.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BPSHHpDP.css">
|
||||
</head>
|
||||
<body class="bg-background">
|
||||
|
@@ -28,6 +28,7 @@ import {
|
||||
SelectValue,
|
||||
} from "../ui/select";
|
||||
import AccessCloudflareForm from "./AccessCloudflareForm";
|
||||
import AccessQiniuForm from "./AccessQiniuForm";
|
||||
|
||||
type TargetConfigEditProps = {
|
||||
op: "add" | "edit";
|
||||
@@ -99,6 +100,16 @@ export function AccessEdit({
|
||||
/>
|
||||
);
|
||||
break;
|
||||
case "qiniu":
|
||||
form = (
|
||||
<AccessQiniuForm
|
||||
data={data}
|
||||
onAfterReq={() => {
|
||||
setOpen(false);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
const getOptionCls = (val: string) => {
|
||||
@@ -122,6 +133,7 @@ export function AccessEdit({
|
||||
console.log(val);
|
||||
setConfigType(val);
|
||||
}}
|
||||
defaultValue={configType}
|
||||
>
|
||||
<SelectTrigger className="mt-3">
|
||||
<SelectValue placeholder="请选择服务商" />
|
||||
@@ -130,7 +142,7 @@ export function AccessEdit({
|
||||
<SelectGroup>
|
||||
<SelectLabel>服务商</SelectLabel>
|
||||
{typeKeys.map((key) => (
|
||||
<SelectItem value={key}>
|
||||
<SelectItem value={key} key={key}>
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center space-x-2 rounded cursor-pointer",
|
||||
|
195
ui/src/components/certimate/AccessQiniuForm.tsx
Normal file
195
ui/src/components/certimate/AccessQiniuForm.tsx
Normal file
@@ -0,0 +1,195 @@
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
|
||||
import z from "zod";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
import { Access, accessFormType, QiniuConfig } from "@/domain/access";
|
||||
import { save } from "@/repository/access";
|
||||
import { useConfig } from "@/providers/config";
|
||||
|
||||
import { ClientResponseError } from "pocketbase";
|
||||
import { PbErrorData } from "@/domain/base";
|
||||
|
||||
const AccessQiniuForm = ({
|
||||
data,
|
||||
onAfterReq,
|
||||
}: {
|
||||
data?: Access;
|
||||
onAfterReq: () => void;
|
||||
}) => {
|
||||
const { addAccess, updateAccess } = useConfig();
|
||||
const formSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
name: z.string().min(1).max(64),
|
||||
configType: accessFormType,
|
||||
accessKey: z.string().min(1).max(64),
|
||||
secretKey: z.string().min(1).max(64),
|
||||
});
|
||||
|
||||
let config: QiniuConfig = {
|
||||
accessKey: "",
|
||||
secretKey: "",
|
||||
};
|
||||
if (data) config = data.config as QiniuConfig;
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
id: data?.id,
|
||||
name: data?.name,
|
||||
configType: "qiniu",
|
||||
accessKey: config.accessKey,
|
||||
secretKey: config.secretKey,
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = async (data: z.infer<typeof formSchema>) => {
|
||||
const req: Access = {
|
||||
id: data.id as string,
|
||||
name: data.name,
|
||||
configType: data.configType,
|
||||
config: {
|
||||
accessKey: data.accessKey,
|
||||
secretKey: data.secretKey,
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const rs = await save(req);
|
||||
|
||||
onAfterReq();
|
||||
|
||||
req.id = rs.id;
|
||||
req.created = rs.created;
|
||||
req.updated = rs.updated;
|
||||
if (data.id) {
|
||||
updateAccess(req);
|
||||
return;
|
||||
}
|
||||
addAccess(req);
|
||||
} catch (e) {
|
||||
const err = e as ClientResponseError;
|
||||
|
||||
Object.entries(err.response.data as PbErrorData).forEach(
|
||||
([key, value]) => {
|
||||
form.setError(key as keyof z.infer<typeof formSchema>, {
|
||||
type: "manual",
|
||||
message: value.message,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="max-w-[35em] mx-auto mt-10">
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.stopPropagation();
|
||||
form.handleSubmit(onSubmit)(e);
|
||||
}}
|
||||
className="space-y-8"
|
||||
>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>名称</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="请输入授权名称" {...field} />
|
||||
</FormControl>
|
||||
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="id"
|
||||
render={({ field }) => (
|
||||
<FormItem className="hidden">
|
||||
<FormLabel>配置类型</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="configType"
|
||||
render={({ field }) => (
|
||||
<FormItem className="hidden">
|
||||
<FormLabel>配置类型</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="accessKey"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>AccessKey</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="请输入AccessKey" {...field} />
|
||||
</FormControl>
|
||||
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="secretKey"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>SecretKey</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="请输入SecretKey" {...field} />
|
||||
</FormControl>
|
||||
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormMessage />
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button type="submit">保存</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AccessQiniuForm;
|
@@ -4,6 +4,7 @@ export const accessTypeMap: Map<string, [string, string]> = new Map([
|
||||
["tencent", ["腾讯云", "/imgs/providers/tencent.svg"]],
|
||||
["aliyun", ["阿里云", "/imgs/providers/aliyun.svg"]],
|
||||
["cloudflare", ["Cloudflare", "/imgs/providers/cloudflare.svg"]],
|
||||
["qiniu", ["七牛云", "/imgs/providers/qiniu.svg"]],
|
||||
["ssh", ["SSH部署", "/imgs/providers/ssh.svg"]],
|
||||
["webhook", ["Webhook", "/imgs/providers/webhook.svg"]],
|
||||
]);
|
||||
@@ -15,6 +16,7 @@ export const accessFormType = z.union(
|
||||
z.literal("ssh"),
|
||||
z.literal("webhook"),
|
||||
z.literal("cloudflare"),
|
||||
z.literal("qiniu"),
|
||||
],
|
||||
{ message: "请选择云服务商" }
|
||||
);
|
||||
@@ -28,12 +30,18 @@ export type Access = {
|
||||
| AliyunConfig
|
||||
| SSHConfig
|
||||
| WebhookConfig
|
||||
| CloudflareConfig;
|
||||
| CloudflareConfig
|
||||
| QiniuConfig;
|
||||
deleted?: string;
|
||||
created?: string;
|
||||
updated?: string;
|
||||
};
|
||||
|
||||
export type QiniuConfig = {
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
};
|
||||
|
||||
export type WebhookConfig = {
|
||||
url: string;
|
||||
};
|
||||
|
@@ -32,6 +32,7 @@ export const targetTypeMap: Map<string, [string, string]> = new Map([
|
||||
["aliyun-oss", ["阿里云-OSS", "/imgs/providers/aliyun.svg"]],
|
||||
["tencent-cdn", ["腾讯云-CDN", "/imgs/providers/tencent.svg"]],
|
||||
["ssh", ["SSH部署", "/imgs/providers/ssh.svg"]],
|
||||
["qiniu-cdn", ["七牛云-CDN", "/imgs/providers/qiniu.svg"]],
|
||||
["webhook", ["Webhook", "/imgs/providers/webhook.svg"]],
|
||||
]);
|
||||
|
||||
|
Reference in New Issue
Block a user