perf(plugin-ucloud): ucloud us3部署插件增加region选择

This commit is contained in:
xiaojunnuo
2026-08-10 22:25:11 +08:00
parent 1017a38eb4
commit 8165a5ff89
2 changed files with 52 additions and 3 deletions
@@ -196,9 +196,9 @@ export class UCloudAccess extends BaseAccess {
return resp; return resp;
} }
async invoke(req: { Action: string; [key: string]: any }) { async invoke(req: { Action: string;region?:string; [key: string]: any }) {
const { Request } = await this.importRuntime("@ucloud-sdks/ucloud-sdk-js"); const { Request } = await this.importRuntime("@ucloud-sdks/ucloud-sdk-js");
const client = await this.getClient(); const client = await this.getClient(req.region);
const resp = await client.invoke( const resp = await client.invoke(
new Request({ new Request({
...req, ...req,
@@ -2,6 +2,7 @@ import { AbstractTaskPlugin, IsTaskPlugin, PageSearch, pluginGroups, RunStrategy
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert"; import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib"; import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib";
import { UCloudAccess } from "../access.js"; import { UCloudAccess } from "../access.js";
import { UCloudRegions } from "./constants.js";
@IsTaskPlugin({ @IsTaskPlugin({
name: "UCloudDeployToUS3", name: "UCloudDeployToUS3",
@@ -40,6 +41,16 @@ export class UCloudDeployToUS3 extends AbstractTaskPlugin {
}) })
accessId!: string; accessId!: string;
@TaskInput(
createRemoteSelectInputDefine({
title: "地域",
helper: "选择UCloud地域",
action: UCloudDeployToUS3.prototype.onGetRegionList.name,
single: true,
})
)
region!: string;
@TaskInput( @TaskInput(
createRemoteSelectInputDefine({ createRemoteSelectInputDefine({
title: "存储桶", title: "存储桶",
@@ -58,7 +69,7 @@ export class UCloudDeployToUS3 extends AbstractTaskPlugin {
) )
domainList!: string[]; domainList!: string[];
async onInstance() {} async onInstance() { }
async execute(): Promise<void> { async execute(): Promise<void> {
const access = await this.getAccess<UCloudAccess>(this.accessId); const access = await this.getAccess<UCloudAccess>(this.accessId);
@@ -80,6 +91,43 @@ export class UCloudDeployToUS3 extends AbstractTaskPlugin {
this.logger.info("部署完成"); this.logger.info("部署完成");
} }
async onGetRegionList(req: PageSearch = {}) {
const access = await this.getAccess<UCloudAccess>(this.accessId);
const res = await access.GetRegion();
let list = res.Regions || [];
if (!list || list.length === 0) {
throw new Error("没有获取到UCloud地域列表");
}
const haveSet = {};
list = list.filter((item: any) => {
const region = item.Region;
if (haveSet[region]) {
return false;
}
haveSet[region] = true;
return true;
});
const options = list.map((item: any) => {
const region = item.Region;
const name = UCloudRegions.find(r => r.value === region)?.label || item.RegionName;
return {
label: `${name}(${item.Region})`,
value: item.Region,
};
});
return {
list: options,
total: options.length,
pageNo: 1,
pageSize: options.length,
};
}
async deployToUS3(req: { access: any; bucket: string; domain: string; cert: CertInfo; certName: string }) { async deployToUS3(req: { access: any; bucket: string; domain: string; cert: CertInfo; certName: string }) {
const { access, bucket, domain, cert, certName } = req; const { access, bucket, domain, cert, certName } = req;
@@ -105,6 +153,7 @@ export class UCloudDeployToUS3 extends AbstractTaskPlugin {
try { try {
const resp = await access.invoke({ const resp = await access.invoke({
region: this.region,
Action: "DescribeBucket", Action: "DescribeBucket",
ProjectId: access.projectId, ProjectId: access.projectId,
Offset: (pageNo - 1) * pageSize, Offset: (pageNo - 1) * pageSize,