Compare commits

...

4 Commits

Author SHA1 Message Date
xiaojunnuo 7a9eec88e8 perf: 1panel支持先上传证书再选择证书 2026-04-10 00:08:10 +08:00
xiaojunnuo a7a4f66633 chore: 资源迁移到项目提示优化 2026-04-09 18:55:05 +08:00
xiaojunnuo a88d0a6ae1 fix: 修复创建流水线无法选择通知的bug 2026-04-09 18:43:57 +08:00
xiaojunnuo db87bc770e chore: 1 2026-04-09 18:20:36 +08:00
18 changed files with 250 additions and 20 deletions
@@ -7,6 +7,9 @@ import { ILogger } from "@certd/basic";
import dayjs from "dayjs";
import { uniq } from "lodash-es";
export interface ICertInfoGetter {
getByPipelineId: (pipelineId: number) => Promise<CertInfo>;
}
export type CertInfo = {
crt: string; //fullchain证书
key: string; //私钥
@@ -1,2 +1,2 @@
export const CertApplyPluginNames = [":cert:"];
export const EVENT_CERT_APPLY_SUCCESS = "CertApply.success";
export const EVENT_CERT_APPLY_SUCCESS = "CertApply.success";
@@ -1,4 +1,4 @@
export * from "./convert.js";
export * from "./cert-reader.js";
export * from "./consts.js";
export * from "./dns-provider/index.js";
export * from "./dns-provider/index.js";
@@ -44,6 +44,10 @@ export function createRemoteSelectInputDefine(opts?: {
component?: any;
value?: any;
pageSize?: number;
uploadCert?: {
title?: string;
columns?: Record<string, any>;
};
}) {
const title = opts?.title || "请选择";
const certDomainsInputKey = opts?.certDomainsInputKey || "certDomains";
@@ -74,6 +78,7 @@ export function createRemoteSelectInputDefine(opts?: {
multi,
pageSize: opts?.pageSize,
watches: [certDomainsInputKey, accessIdInputKey, ...watches],
uploadCert: opts?.uploadCert,
...opts.component,
},
value: opts.value,
@@ -25,8 +25,9 @@
</div>
</template>
</a-select>
<div class="ml-5">
<div class="ml-5 flex flex-row no-wrap">
<fs-button :loading="loading" title="刷新选项" icon="ion:refresh-outline" @click="refreshOptions"></fs-button>
<UploadCert v-if="uploadCert" class="ml-5" v-bind="uploadCert" @submit="refreshOptions"></UploadCert>
</div>
</div>
<div class="helper" :class="{ error: hasError }">
@@ -39,6 +40,8 @@ import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
import { defineComponent, inject, ref, useAttrs, watch, Ref } from "vue";
import { PluginDefine } from "@certd/pipeline";
import { getInputFromForm } from "./utils";
import UploadCert from "./upload-cert.vue";
import { UploadCertProps } from "./types";
defineOptions({
name: "RemoteSelect",
@@ -65,9 +68,10 @@ const props = defineProps<
pager?: boolean;
multi?: boolean;
pageSize?: number;
uploadCert?: UploadCertProps;
} & ComponentPropsType
>();
debugger;
const emit = defineEmits<{
"update:value": any;
}>();
@@ -0,0 +1,5 @@
export interface UploadCertProps {
title?: string;
columns?: Record<string, any>;
button?: any;
}
@@ -0,0 +1,101 @@
<template>
<div class="upload-cert">
<fs-button v-model:loading="loading" type="primary" text="上传" v-bind="props.button" @click="openUploadCertDialog"></fs-button>
</div>
</template>
<script lang="ts" setup>
import { message } from "ant-design-vue";
import { useFormDialog } from "../../../use/use-dialog";
import { computed, inject, ref } from "vue";
import { doRequest } from "../lib";
import { getInputFromForm } from "./utils";
import { UploadCertProps } from "./types";
import { merge } from "lodash-es";
const props = defineProps<UploadCertProps>();
const loading = ref(false);
const emit = defineEmits(["submit"]);
const { openFormDialog } = useFormDialog();
const pipeline = inject("pipeline", null);
const getCurrentPluginDefine: any = inject("getCurrentPluginDefine", () => {
return {};
});
const getScope: any = inject("get:scope", () => {
return {};
});
const getPluginType: any = inject("get:plugin:type", () => {
return "plugin";
});
const title = computed(() => props.title || "上传证书");
function openUploadCertDialog() {
const columns = merge(
{
certName: {
title: "证书名称",
form: {
component: {
name: "a-input",
vModel: "value",
},
helper: "上传后证书显示名称",
},
},
},
props.columns
);
openFormDialog({
title: title.value,
columns: {
certName: {
title: "证书名称",
form: {
component: {
name: "a-input",
vModel: "value",
},
},
},
...props.columns,
},
onSubmit: async (form: any) => {
const pluginType = getPluginType();
const scope = getScope();
const { input, record } = getInputFromForm(scope.form, pluginType);
loading.value = true;
try {
const res = await doRequest(
{
type: pluginType,
typeName: scope.form.type,
action: "onUploadCert",
input,
record,
data: {
pipelineId: pipeline?.value?.id,
...form,
},
},
{
// onError(err: any) {
// message.error(err.message);
// },
showErrorNotify: true,
}
);
message.success("上传成功");
emit("submit");
} finally {
loading.value = false;
}
},
});
}
</script>
<style lang="less">
.upload-cert {
display: flex;
align-items: center;
}
</style>
@@ -4,7 +4,7 @@
<div class="step-item overflow-hidden">
<div class="text">
<h3 class="title">{{ number }} {{ currentStepItem.title }}</h3>
<h3 class="title font-bold">{{ number }} {{ currentStepItem.title }}</h3>
<div class="description mt-5">
<div v-for="(desc, index) of currentStepItem.descriptions" :key="index">{{ desc }}</div>
</div>
@@ -247,6 +247,7 @@ function previewMask() {
<style lang="less">
.tutorial-steps {
display: flex;
.step-item {
display: flex !important;
flex-direction: row;
@@ -251,7 +251,7 @@ function openUpgrade() {
class: "vip-modal",
maskClosable: true,
okText: t("vip.close"),
width: 1100,
width: 1180,
content: () => {
return <VipModalContent placeholder={placeholder} isPlus={isPlus} productInfo={productInfo} goBuyPlusPage={goBuyPlusPage} goBuyCommPage={goBuyCommPage} openStarModal={openStarModal} modalRef={modalRef} />;
},
@@ -65,6 +65,11 @@
</div>
<div class="get-show">
<template v-if="item.type === 'plus'">
<span v-if="todayOrderCount.showVipTotal" class="mr-5">
已有
<span class="color-red"> {{ todayOrderCount.vipTotal }}</span>
位伙伴支持
</span>
<a-tooltip :title="t('vip.afdian_support_vip')">
<a-button size="small" type="primary" @click="goBuyPlusPage">
{{ t("vip.get_after_support") }}
@@ -260,12 +265,16 @@ const todayOrderCount = computed(() => {
const lastStage = countInfo?.stages?.[countInfo?.stages?.length - 1] || {};
lastStage.orderCount = orderCount;
const vipTotal = countInfo?.vipTotal || 0;
const showVipTotal = countInfo?.showVipTotal || false;
const userTotal = countInfo?.userTotal || 0;
const stages: any = [];
stages.push({
title: countInfo.title,
vipTotal: countInfo?.vipTotal || 0,
orderCount: orderCount,
bg: lastStage.bg,
showVipTotal: showVipTotal,
});
if (lastStage.orderCount > 0) {
stages.push(lastStage);
@@ -273,6 +282,9 @@ const todayOrderCount = computed(() => {
return {
enabled: enabled,
stages: stages,
showVipTotal: showVipTotal,
vipTotal: vipTotal,
userTotal: userTotal,
};
});
@@ -65,7 +65,7 @@ export default {
click_to_get_7_day_trial: "Click to get 7-day trial",
years: "years",
afdian_support_vip: "Obtain the permanent professional version coupon",
get_after_support: "Get after sponsoring",
get_after_support: "sponsoring",
business_edition: "Business Edition",
commercial_license: "Commercial license, allowed for external operation",
@@ -33,7 +33,7 @@ export default {
activateCertDesc2: "让证书生效",
taskSuccessTitle: "部署任务添加成功",
taskSuccessDesc: "现在可以运行",
pluginsTitle: "本系统提供茫茫多的部署插件",
pluginsTitle: "本系统提供海量的部署插件",
pluginsDesc: "您可以根据自身需求将证书部署到各种应用和平台",
},
},
@@ -134,18 +134,21 @@ async function emitValue(value: any) {
const userId = userStore.userInfo.id;
const isEnterprice = projectStore.isEnterprise;
if (isEnterprice) {
const projectId = projectStore.currentProjectId;
if (pipeline?.value?.projectId !== projectId) {
message.error("对不起,您不能修改其他项目流水线的通知");
return;
}
} else {
if (pipeline?.value?.userId !== userId) {
message.error("对不起,您不能修改他人流水线的通知");
return;
if (pipeline?.value) {
if (isEnterprice) {
const projectId = projectStore.currentProjectId;
if (pipeline?.value?.projectId !== projectId) {
message.error("对不起,您不能修改其他项目流水线的通知");
return;
}
} else {
if (pipeline?.value?.userId !== userId) {
message.error("对不起,您不能修改他人流水线的通知");
return;
}
}
}
emit("change", value);
emit("update:modelValue", value);
}
@@ -118,6 +118,10 @@ export function useTransfer() {
<div class="text-2xl font-bold"> </div>
<div>"{projectStore.currentProject?.name}"</div>
</div>
<div class="text-center m-4">
<p class="text-red-500"></p>
</div>
<div class="flex flex-row items-center justify-center w-full">
<a-button type="primary" onClick={doTransfer}>
@@ -29,7 +29,7 @@ import { SysSettings } from "/@/views/sys/settings/api";
import * as api from "/@/views/sys/settings/api";
import { merge } from "lodash-es";
import { useSettingStore } from "/@/store/settings";
import { notification } from "ant-design-vue";
import { Modal, notification } from "ant-design-vue";
import { useI18n } from "/src/locales";
import { dict } from "@fast-crud/fast-crud";
import { useProjectStore } from "/@/store/project";
@@ -80,6 +80,24 @@ const onFinish = async (form: any) => {
notification.success({
message: t("certd.saveSuccess"),
});
if (formState.public.adminMode === "enterprise") {
Modal.confirm({
title: "数据迁移",
okText: "去迁移",
content: () => {
return (
<div>
<div>设置为企业模式之后之前创建的个人数据不会显示</div>
<div>是否前往迁移数据到项目? </div>
</div>
);
},
onOk: () => {
goCurrentProject();
},
});
}
} finally {
saveLoading.value = false;
}
@@ -0,0 +1,32 @@
import { CertInfo, CertReader, ICertInfoGetter } from '@certd/plugin-lib';
import { CertInfoService } from '../../../monitor/index.js';
export class CertInfoGetter implements ICertInfoGetter {
userId: number;
projectId: number;
certInfoService: CertInfoService;
constructor(userId: number, projectId: number, certInfoService: CertInfoService) {
this.userId = userId;
this.projectId = projectId;
this.certInfoService = certInfoService;
}
async getByPipelineId(pipelineId: number): Promise<CertInfo> {
if (!pipelineId) {
throw new Error(`流水线id不能为空`)
}
const query :any= {
pipelineId,
userId: this.userId,
}
if (this.projectId) {
query.projectId = this.projectId
}
const entity = await this.certInfoService.findOne({
where:query
})
if (!entity || !entity.certInfo) {
throw new Error(`流水线(${pipelineId})还未生成证书,请先运行一次流水线`)
}
return new CertReader(JSON.parse(entity.certInfo)).cert;
}
}
@@ -9,6 +9,9 @@ import { SubDomainsGetter } from "./sub-domain-getter.js";
import { DomainVerifierGetter } from "./domain-verifier-getter.js";
import { DomainService } from "../../../cert/service/domain-service.js";
import { SubDomainService } from "../sub-domain-service.js";
import { CertInfoGetter } from "./cert-info-getter.js";
import { CertInfoService } from "../../../monitor/index.js";
import { ICertInfoGetter } from "@certd/plugin-lib";
const serviceNames = [
'ocrService',
@@ -34,6 +37,8 @@ export class TaskServiceGetter implements IServiceGetter{
return await this.getNotificationService() as T
} else if (serviceName === 'domainVerifierGetter') {
return await this.getDomainVerifierGetter() as T
} else if (serviceName === 'certInfoGetter') {
return await this.getCertInfoGetter() as T
}else{
if(!serviceNames.includes(serviceName)){
throw new Error(`${serviceName} not in whitelist`)
@@ -51,6 +56,11 @@ export class TaskServiceGetter implements IServiceGetter{
return new SubDomainsGetter(this.userId,this.projectId, subDomainsService,domainService)
}
async getCertInfoGetter(): Promise<ICertInfoGetter> {
const certInfoService:CertInfoService = await this.appCtx.getAsync("certInfoService")
return new CertInfoGetter(this.userId, this.projectId, certInfoService)
}
async getAccessService(): Promise<AccessGetter> {
const accessService:AccessService = await this.appCtx.getAsync("accessService")
return new AccessGetter(this.userId, this.projectId, accessService.getById.bind(accessService));
@@ -2,7 +2,7 @@ import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
import { OnePanelAccess } from "../access.js";
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib";
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine, ICertInfoGetter } from "@certd/plugin-lib";
import { OnePanelClient } from "../client.js";
@IsTaskPlugin({
@@ -66,6 +66,7 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
watches: ["accessId"],
helper: "要更新的1Panel证书id,选择授权之后,从下拉框中选择\nIP需要加白名单,如果是同一台机器部署的,可以试试172.16.0.0/12",
required: true,
uploadCert: {}
})
)
sslIds!: string[];
@@ -213,5 +214,36 @@ export class OnePanelDeployToWebsitePlugin extends AbstractTaskPlugin {
});
return this.ctx.utils.options.buildGroupOptions(list, this.certDomains);
}
async onUploadCert(data: { pipelineId: string, certName: string }) {
if (!this.access) {
throw new Error("请先选择1panel授权");
}
const certInfoGetter = await this.ctx.serviceGetter.get<ICertInfoGetter>("certInfoGetter")
const cert = await certInfoGetter.getByPipelineId(Number(data.pipelineId));
const client = new OnePanelClient({
access: this.access,
http: this.http,
logger: this.logger,
utils: this.ctx.utils,
});
await client.doRequest({
url: `/api/${this.access.apiVersion}/websites/ssl/upload`,
method: "post",
data: {
sslId: 0,
certificate: cert.crt,
certificatePath: "",
description: data.certName,
privateKey: cert.key,
privateKeyPath: "",
type: "paste",
},
currentNode: this.currentNode,
});
}
}
new OnePanelDeployToWebsitePlugin();