chore(plugin): add online plugin author email update function

1. 新增修改在线插件作者邮箱的接口与前后端实现
2. 调整插件作者相关类型定义,精简冗余字段并添加email字段
3. 新增邮箱格式校验逻辑
4. 在插件发布页面添加修改作者邮箱的交互功能
This commit is contained in:
xiaojunnuo
2026-08-30 00:43:47 +08:00
parent 580981a468
commit da406014ad
4 changed files with 102 additions and 15 deletions
@@ -108,6 +108,7 @@ export type OnlinePluginBean = {
desc?: string;
latest?: string;
status?: string;
email?: string;
downloadCount?: number;
score?: number;
aiCheckStatus?: string;
@@ -218,14 +219,8 @@ export async function OnlinePluginPublishInfo(body: { id: number }): Promise<{
export type OnlinePluginAuthorBean = {
id?: number;
appId?: number;
appOwnerId?: number;
developerId?: number;
name?: string;
displayName?: string;
avatar?: string;
desc?: string;
status?: string;
email?: string;
};
export async function OnlinePluginAuthorGet(options?: { showErrorNotify?: boolean }): Promise<{ registered?: boolean; author?: OnlinePluginAuthorBean }> {
@@ -236,13 +231,16 @@ export async function OnlinePluginAuthorGet(options?: { showErrorNotify?: boolea
});
}
export async function OnlinePluginAuthorAdd(body: { name: string; displayName?: string; avatar?: string; desc?: string }): Promise<OnlinePluginAuthorBean> {
export async function OnlinePluginAuthorAdd(body: { name: string; email: string }): Promise<OnlinePluginAuthorBean> {
return await request({
url: apiPrefix + "/online/author/add",
method: "post",
data: body,
});
}
export async function OnlinePluginAuthorUpdate(body: { email: string }): Promise<OnlinePluginAuthorBean> {
return await request({ url: apiPrefix + "/online/author/update", method: "post", data: body });
}
export type PluginConfigBean = {
name: string;
@@ -14,6 +14,9 @@ type PublishManagerResult =
| {
action: "registered";
}
| {
action: "updated";
}
| {
action: "cancel";
};
@@ -61,7 +64,7 @@ export function usePluginPublish() {
initialForm: {
name: "",
nameConfirm: "",
desc: "",
email: "",
},
async onSubmit(form: any) {
if (form.name?.trim() !== form.nameConfirm?.trim()) {
@@ -72,8 +75,7 @@ export function usePluginPublish() {
}
const author = await api.OnlinePluginAuthorAdd({
name: form.name,
displayName: form.displayName,
desc: form.desc,
email: form.email,
});
resolveAuthor(author);
},
@@ -111,6 +113,51 @@ export function usePluginPublish() {
],
},
},
email: {
title: "作者邮箱",
type: "text",
form: {
col: { span: 24 },
rules: [
{ required: true, message: "请输入作者邮箱" },
{ type: "email", message: "请输入有效的作者邮箱" },
],
},
},
},
});
});
}
function updatePluginAuthorEmail(author?: api.OnlinePluginAuthorBean) {
return new Promise<api.OnlinePluginAuthorBean | undefined>(async resolve => {
let resolved = false;
const resolveAuthor = (result?: api.OnlinePluginAuthorBean) => {
if (!resolved) {
resolved = true;
resolve(result);
}
};
await openFormDialog({
title: "修改作者邮箱",
wrapper: { width: 560, onClosed: () => resolveAuthor() },
initialForm: { email: author?.email || "" },
async onSubmit(form: any) {
const result = await api.OnlinePluginAuthorUpdate({ email: form.email });
resolveAuthor(result);
},
columns: {
email: {
title: "作者邮箱",
type: "text",
form: {
col: { span: 24 },
rules: [
{ required: true, message: "请输入作者邮箱" },
{ type: "email", message: "请输入有效的作者邮箱" },
],
},
},
},
});
});
@@ -326,7 +373,26 @@ export function usePluginPublish() {
function renderAuthor() {
if (info.authorRegistered) {
return author?.displayName || author?.name || "-";
return (
<span class="sys-plugin-publish__author-register">
<span>{author?.name || "-"}</span>
<a-button
size="small"
type="link"
onClick={async (event: any) => {
event.stopPropagation();
const updatedAuthor = await updatePluginAuthorEmail(author);
if (!updatedAuthor?.id) {
return;
}
resolveResult({ action: "updated" });
formWrapper?.close?.();
}}
>
修改邮箱
</a-button>
</span>
);
}
return (
<span class="sys-plugin-publish__author-register">
@@ -490,6 +556,10 @@ export function usePluginPublish() {
await publishLocalPlugin(row, options);
return;
}
if (action.action === "updated") {
await publishLocalPlugin(row, options);
return;
}
if (action.action !== "publish") {
return;
}
@@ -3,6 +3,7 @@ import { merge } from "lodash-es";
import { CrudController } from "@certd/lib-server";
import {
OnlinePluginAuthorAddReq,
OnlinePluginAuthorUpdateReq,
OnlinePluginDependenciesReq,
OnlinePluginInstallReq,
OnlinePluginListReq,
@@ -192,6 +193,11 @@ export class PluginController extends CrudController<PluginService> {
return this.ok(res);
}
@Post("/online/author/update", { description: "sys:settings:edit", summary: "修改在线插件作者邮箱" })
async onlineAuthorUpdate(@Body(ALL) body: OnlinePluginAuthorUpdateReq) {
return this.ok(await this.service.updateOnlinePluginAuthor(body));
}
@Post("/online/publish/info", { description: "sys:settings:view", summary: "查询本地插件发布信息" })
async onlinePublishInfo(@Body(ALL) body: OnlinePluginPublishInfoReq) {
const res = await this.service.getOnlinePluginPublishInfo(body);
@@ -85,6 +85,7 @@ export type OnlinePluginAuthorBean = {
avatar?: string;
desc?: string;
status?: string;
email?: string;
};
export type OnlinePluginAuthorGetReply = {
@@ -97,7 +98,9 @@ export type OnlinePluginAuthorAddReq = {
displayName?: string;
avatar?: string;
desc?: string;
email: string;
};
export type OnlinePluginAuthorUpdateReq = { email: string };
export type OnlinePluginBean = {
id?: number;
@@ -1208,6 +1211,9 @@ export class PluginService extends BaseService<PluginEntity> {
}
async addOnlinePluginAuthor(req: OnlinePluginAuthorAddReq): Promise<OnlinePluginAuthorBean> {
if (!/^\S+@\S+\.\S+$/.test(req.email?.trim() || "")) {
throw new Error("请输入有效的作者邮箱");
}
await this.getBindUserId("注册插件作者");
await this.plusService.register();
return await this.plusService.request({
@@ -1215,13 +1221,20 @@ export class PluginService extends BaseService<PluginEntity> {
method: "post",
data: {
name: req.name,
displayName: req.displayName || "",
avatar: req.avatar || "",
desc: req.desc || "",
email: req.email,
},
});
}
async updateOnlinePluginAuthor(req: OnlinePluginAuthorUpdateReq): Promise<OnlinePluginAuthorBean> {
if (!/^\S+@\S+\.\S+$/.test(req.email?.trim() || "")) {
throw new Error("请输入有效的作者邮箱");
}
await this.getBindUserId("修改插件作者");
await this.plusService.register();
return await this.plusService.request({ url: "/activation/plugin/author/update", method: "post", data: { email: req.email } });
}
async getOnlinePluginPublishInfo(req: OnlinePluginPublishInfoReq): Promise<OnlinePluginPublishInfo> {
if (!req.id) {
throw new Error("插件ID不能为空");