perf: 支持又拍云cdn

pull/361/head
xiaojunnuo 2025-03-26 20:48:26 +08:00
parent 57389a79a1
commit fd0536bd4b
10 changed files with 265 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { customAlphabet } from 'nanoid';
import { customAlphabet } from "nanoid";
export const randomNumber = customAlphabet('1234567890', 4);
export const simpleNanoId = customAlphabet('1234567890abcdefghijklmopqrstuvwxyz', 12);
export const randomNumber = customAlphabet("1234567890", 4);
export const simpleNanoId = customAlphabet("1234567890abcdefghijklmopqrstuvwxyz", 12);

View File

@ -54,6 +54,12 @@
<div class="content unicode" style="display: block;">
<ul class="icon_lists dib-box">
<li class="dib">
<span class="icon iconfont">&#xe62f;</span>
<div class="name">upyun</div>
<div class="code-name">&amp;#xe62f;</div>
</li>
<li class="dib">
<span class="icon iconfont">&#xecc0;</span>
<div class="name">plesk_</div>
@ -174,7 +180,7 @@
<pre><code class="language-css"
>@font-face {
font-family: 'iconfont';
src: url('iconfont.svg?t=1742822771904#iconfont') format('svg');
src: url('iconfont.svg?t=1742952318857#iconfont') format('svg');
}
</code></pre>
<h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
@ -200,6 +206,15 @@
<div class="content font-class">
<ul class="icon_lists dib-box">
<li class="dib">
<span class="icon iconfont icon-upyun"></span>
<div class="name">
upyun
</div>
<div class="code-name">.icon-upyun
</div>
</li>
<li class="dib">
<span class="icon iconfont icon-plesk"></span>
<div class="name">
@ -380,6 +395,14 @@
<div class="content symbol">
<ul class="icon_lists dib-box">
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#icon-upyun"></use>
</svg>
<div class="name">upyun</div>
<div class="code-name">#icon-upyun</div>
</li>
<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#icon-plesk"></use>

View File

@ -1,6 +1,6 @@
@font-face {
font-family: "iconfont"; /* Project id 4688792 */
src: url('iconfont.svg?t=1742822771904#iconfont') format('svg');
src: url('iconfont.svg?t=1742952318857#iconfont') format('svg');
}
.iconfont {
@ -11,6 +11,10 @@
-moz-osx-font-smoothing: grayscale;
}
.icon-upyun:before {
content: "\e62f";
}
.icon-plesk:before {
content: "\ecc0";
}

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,13 @@
"css_prefix_text": "icon-",
"description": "",
"glyphs": [
{
"icon_id": "5771134",
"name": "upyun",
"font_class": "upyun",
"unicode": "e62f",
"unicode_decimal": 58927
},
{
"icon_id": "27272666",
"name": "plesk_",

View File

@ -14,6 +14,8 @@
/>
<missing-glyph />
<glyph glyph-name="upyun" unicode="&#58927;" d="M800.499763 767.681969a449.332702 449.332702 0 0 1-55.882631 35.892097 31.803124 31.803124 0 0 1-40.435399-8.177947L584.238523 636.834832l-6.814954-12.266919a65.877899 65.877899 0 0 0-55.428301-25.89683h-23.625178a213.989588 213.989588 0 0 1-200.359678-224.893515 23.625177 23.625177 0 0 1 13.62991-20.444865 56.336962 56.336962 0 1 0-77.236157-67.24089v3.634642a56.791292 56.791292 0 0 0 10.903928 45.433034 34.529106 34.529106 0 0 1 7.269285 24.988168 261.694273 261.694273 0 0 0 259.422622 284.410791 48.613346 48.613346 0 0 1 38.618078 19.536204l110.402272 146.748699a19.990535 19.990535 0 0 1-10.903927 31.803123A479.772834 479.772834 0 0 1 278.928538-35.574066a31.803124 31.803124 0 0 1 40.88973 8.632277L441.124467 132.073829l8.177947 11.358258a66.332229 66.332229 0 0 0 55.428301 25.89683 204.902981 204.902981 0 0 1 23.625177 0 215.80691 215.80691 0 0 1 157.652627 84.959772 211.717937 211.717937 0 0 1 42.707051 139.933743 23.625177 23.625177 0 0 1-13.62991 20.444865 56.336962 56.336962 0 0 0-33.620445 40.4354 56.336962 56.336962 0 0 0 109.947941 25.4425 13.17558 13.17558 0 0 1 0-4.088973 57.245622 57.245622 0 0 0-10.903927-45.433034 34.529106 34.529106 0 0 1-7.269286-24.988168 261.694273 261.694273 0 0 0-259.422622-284.410791 48.613346 48.613346 0 0 1-38.618078-19.536204L365.705632-44.660672a20.444865 20.444865 0 0 1 10.449598-31.803124 480.227166 480.227166 0 0 1 424.344533 844.145765z" horiz-adv-x="1024" />
<glyph glyph-name="plesk" unicode="&#60608;" d="M716.942589 895.930235V211.95271h68.439611V896zM1987.156664 894.953523v-683.070578h68.369846V894.822713z m68.369846-430.930607L2286.10905 211.95271h94.810838L2141.477174 465.967619 2381.818114 700.448286h-91.810937zM1682.701552 709.238695c-49.882082 0-90.415634-11.65078-121.870996-35.161635q-46.986828-35.161635-46.951945-99.554868c0-24.199786 4.534735-44.091574 13.735014-59.718968a123.499576 123.499576 0 0 1 35.37093-38.588849 201.316059 201.316059 0 0 1 48.556544-24.836393c18.069174-6.488159 36.277878-12.487962 54.905173-17.659303a999.135047 999.135047 0 0 0 46.533355-14.171046 172.450729 172.450729 0 0 0 38.859188-18.069174 87.335066 87.335066 0 0 0 26.580522-25.88287q9.732238-15.17392 9.697355-37.673181c0-19.534242-8.860174-36.068582-26.580521-49.742552-17.659303-13.673969-44.998521-20.580719-81.834521-20.580719q-84.973952 0-138.134995 68.369847l-53.230809-46.87346c26.580522-29.301363 54.905173-50.230908 84.904186-63.067695 29.929249-12.627492 64.462998-18.9674 103.252421-18.9674a263.165044 263.165044 0 0 1 71.230218 9.278765 175.136687 175.136687 0 0 1 58.2539 27.688044l-0.488356-0.348826a134.548631 134.548631 0 0 1 38.998718 44.4404 123.211794 123.211794 0 0 1 14.232091 59.518393c0 24.199786-4.74403 44.091574-14.232091 60.067794a136.449731 136.449731 0 0 1-36.975529 40.254491l-0.418591 0.27906a207.96119 207.96119 0 0 1-49.254195 26.379948l-1.465068 0.488356c-9.836886 4.116144-28.18512 10.604303-46.672885 16.67387l-8.581114 2.441781q-22.499261 6.802102-43.463688 14.171046a184.546261 184.546261 0 0 0-37.742946 17.580817l0.837182-0.488356a86.116356 86.116356 0 0 0-25.394514 23.16203l-0.139531 0.27906a55.225656 55.225656 0 0 0-9.697355 31.394318v1.813893a59.891201 59.891201 0 0 0 20.929544 46.87346c13.95303 12.348431 38.440597 18.627295 73.183642 18.627295q40.91726 0 70.602331-15.139037c19.813302-10.115947 38.152816-25.88287 55.253999-47.440302l1.046477-0.906947 50.230908 45.975234q-37.987124 43.952044-79.322975 61.463096a235.913033 235.913033 0 0 1-90.345869 17.659304c-1.526113 0-3.069667 0-4.534735-0.069765h0.218017zM316.420866 705.401612q-82.043816 0-167.087533-26.440992v-709.372039h67.462899V222.626778a487.405496 487.405496 0 0 1 50.79775-10.682789 320.047623 320.047623 0 0 1 51.556445-4.046378 329.08657 329.08657 0 0 1 98.299096 14.929742l-2.30225-0.627887a238.439839 238.439839 0 0 1 83.500163 44.440401q36.626703 30.243192 59.160847 77.23002 22.289965 46.87346 22.394613 112.391656a262.628725 262.628725 0 0 1-18.627295 99.633354 226.263641 226.263641 0 0 1-53.169765 79.113679l-0.069765 0.069765a246.486813 246.486813 0 0 1-81.83452 51.277385l-1.674364 0.558121q-48.870487 18.531368-108.484807 18.627295z m826.57749 0a239.863484 239.863484 0 0 1-85.043717-15.139038 191.080204 191.080204 0 0 1-70.323271-46.533354 222.204181 222.204181 0 0 1-47.440301-77.020725l-0.488356-1.526113q-17.580818-47.405419-17.580818-111.842255a291.786197 291.786197 0 0 1 14.580916-92.857414 231.293272 231.293272 0 0 1 44.021809-78.136967 207.054243 207.054243 0 0 1 73.323172-54.216242q43.952044-20.092363 102.624535-20.092363 63.521169 0 108.484808 19.045886a226.717114 226.717114 0 0 1 79.043914 56.160945l-40.952143 42.992773q-28.464181-31.28967-63.556051-45.417112a203.949694 203.949694 0 0 0-75.485892-14.23209h-2.651075q-77.334668 0-122.228542 48.905369-44.893874 48.870487-47.789127 131.786368h366.406564q1.779011 126.100508-52.812218 191.993691-54.722039 66.032714-162.134207 66.058876z m2.860371-57.695779c24.199786 0 45.277582-3.706274 63.556051-11.232189a122.333189 122.333189 0 0 0 44.4404-29.789719 130.168688 130.168688 0 0 0 26.440992-44.998521 170.763284 170.763284 0 0 0 9.278765-56.649301h-296.153059a197.470255 197.470255 0 0 0 46.184529 102.83383l-0.218017-0.279061c10.325242 11.720545 24.557333 21.417901 42.417211 28.813007 17.929643 7.464871 39.277779 11.162424 64.114173 11.232189z m-823.507823-0.985432q85.915781 0 133.390965-52.393628 47.405419-52.219214 47.440302-137.228049c0-61.323566-17.223271-108.353998-51.34715-141.204662q-51.382033-49.393726-138.204761-49.31524a225.391576 225.391576 0 0 0-48.347249 5.302151 434.560575 434.560575 0 0 0-51.556445 14.171046l3.139432-0.976712V631.023242a260.609896 260.609896 0 0 0 51.835506 12.278666 424.403205 424.403205 0 0 0 53.6494 3.348727z m221.085758-612.808352v-64.393233h411.396365v64.393233z" horiz-adv-x="2467" />
<glyph glyph-name="yizhifu" unicode="&#59201;" d="M398.108444 618.496h215.950223c66.787556 0 117.76 152.348444 117.76 152.348444 0 45.624889-4.323556 80.213333-78.506667 82.602667-74.183111 2.389333-91.932444-54.499556-145.294222-54.499555-54.613333 0-81.92 44.828444-149.162667 54.613333-67.242667 9.671111-78.506667-36.977778-78.506667-82.602667 0-0.113778 50.858667-152.462222 117.76-152.462222zM625.891556 571.392H398.108444c-252.245333 0-314.140444-520.988444-314.140444-520.988444 0-68.494222 52.679111-137.216 117.76-137.216h620.430222c65.080889 0 117.76 68.721778 117.76 137.216 0.113778 0-61.895111 520.988444-314.026666 520.988444zM645.12 302.990222c19.911111 0 36.067556-16.156444 36.067556-36.067555s-16.156444-36.067556-36.067556-36.067556h-77.710222v-35.384889H645.12c19.911111 0 36.067556-16.156444 36.067556-36.067555s-16.156444-36.067556-36.067556-36.067556h-77.710222v-99.783111c0-19.911111-16.156444-36.067556-36.067556-36.067556s-36.067556 16.156444-36.067555 36.067556v99.783111H417.564444c-19.911111 0-36.067556 16.156444-36.067555 36.067556s16.156444 36.067556 36.067555 36.067555h77.710223v35.384889H417.564444c-19.911111 0-36.067556 16.156444-36.067555 36.067556s16.156444 36.067556 36.067555 36.067555h29.582223l-55.068445 55.523556c-13.994667 14.108444-13.880889 36.977778 0.227556 50.972444 14.108444 13.994667 36.977778 13.880889 50.972444-0.227555l88.632889-89.315556 88.632889 89.315556c13.994667 14.108444 36.864 14.222222 50.972444 0.227555 14.108444-13.994667 14.222222-36.864 0.227556-50.972444L616.675556 302.990222h28.444444z m192.739556-324.152889a48.822044 48.822044 0 0 0-48.924445 0c-15.132444 8.760889-24.462222 24.917333-24.462222 42.325334 0 17.521778 9.329778 33.564444 24.462222 42.325333 15.132444 8.760889 33.792 8.760889 48.924445 0s24.462222-24.917333 24.462222-42.325333c-0.113778-17.521778-9.329778-33.564444-24.462222-42.325334z" horiz-adv-x="1024" />

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,35 @@
import {AccessInput, BaseAccess, IsAccess} from '@certd/pipeline';
/**
*
* certd
*/
@IsAccess({
name: 'upyun',
title: '又拍云',
desc: '',
icon: 'svg:icon-upyun',
})
export class UpyunAccess extends BaseAccess {
@AccessInput({
title: '账号',
component: {
placeholder: '又拍云账号',
},
required: true,
})
username = '';
@AccessInput({
title: '密码',
component: {
placeholder: '又拍云密码',
},
required: true,
encrypt: true,
})
password = '';
}
new UpyunAccess();

View File

@ -0,0 +1,2 @@
export * from './plugins/index.js';
export * from './access.js';

View File

@ -0,0 +1 @@
export * from './plugin-depoy-to-cdn.js';

View File

@ -0,0 +1,185 @@
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
import { CertInfo } from '@certd/plugin-cert';
import { AbstractPlusTaskPlugin } from '@certd/plugin-plus';
import { UpyunAccess } from '../access.js';
import {createCertDomainGetterInputDefine, createRemoteSelectInputDefine} from '@certd/plugin-lib';
import { CertApplyPluginNames} from '@certd/plugin-cert';
import {optionsUtils} from "@certd/basic/dist/utils/util.options.js";
@IsTaskPlugin({
//命名规范,插件名称+功能就是目录plugin-demo中的demo大写字母开头驼峰命名
name: 'UpyunDeployToCdn',
title: '又拍云-部署证书到CDN',
icon: 'svg:icon-upyun',
//插件分组
group: pluginGroups.other.key,
needPlus: true,
default: {
//默认值配置照抄即可
strategy: {
runStrategy: RunStrategy.SkipWhenSucceed,
},
},
})
//类名规范跟上面插件名称name一致
export class UpyunDeployToCdn extends AbstractPlusTaskPlugin {
//证书选择,此项必须要有
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
component: {
name: 'output-selector',
from: [...CertApplyPluginNames],
},
// required: true, // 必填
})
cert!: CertInfo;
@TaskInput(createCertDomainGetterInputDefine({ props: { required: false } }))
certDomains!: string[];
//授权选择框
@TaskInput({
title: 'Upyun授权',
component: {
name: 'access-selector',
type: 'upyun', //固定授权类型
},
required: true, //必填
})
accessId!: string;
//
@TaskInput(
createRemoteSelectInputDefine({
title: 'CDN加速域名',
helper: '选择CDN加速域名可以手动输入',
typeName: 'UpyunDeployToCdn',
action: UpyunDeployToCdn.prototype.onGetCdnList.name,
watches: ['accessId'],
})
)
cdnList!: string[];
//插件实例化时执行的方法
async onInstance() {}
//插件执行方法
async execute(): Promise<void> {
const cookie = await this.getLoginToken();
this.logger.info(`登录成功`);
const certId = await this.uploadCert(cookie);
this.logger.info(`上传证书成功:${certId}`);
for (const item of this.cdnList) {
this.logger.info(`开始部署证书:${item}`);
const res = await this.doRequest({
cookie:cookie,
url: 'https://console.upyun.com/api/https/migrate/domain',
method: 'POST',
data:{
crt_id: certId,
domain_name : item
}
})
this.logger.info(`部署成功:${JSON.stringify(res)}`);
}
this.logger.info('部署成功');
}
async uploadCert(cookie:string){
// https://console.upyun.com/api/https/certificate/
const res = await this.doRequest({
cookie:cookie,
url: 'https://console.upyun.com/api/https/certificate/',
method: 'POST',
data:{
certificate: this.cert.crt,
private_key: this.cert.key
}
})
return res.data.result.certificate_id
}
async getLoginToken(){
const access = await this.accessService.getById<UpyunAccess>(this.accessId)
const res = await this.http.request({
url: 'https://console.upyun.com/accounts/signin/',
method: 'POST',
data:{
username: access.username,
password: access.password
},
logRes:false,
returnResponse:true
});
if (res.data?.errors?.length>0) {
throw new Error(JSON.stringify(res.data.msg));
}
const cookie = res.headers['set-cookie'];
return cookie;
}
async doRequest(req:{
cookie:string,
url:string,
method:string,
data:any
}){
const res = await this.http.request({
url: req.url,
method: req.method,
data:req.data,
headers:{
Cookie: req.cookie
}
})
if (res.msg.errors.length>0) {
throw new Error(JSON.stringify(res.msg));
}
return res
}
async onGetCdnList() {
if(!this.accessId){
throw new Error('accessId不能为空');
}
const cookie = await this.getLoginToken();
const req = {
cookie,
url: 'https://console.upyun.com/api/v2/buckets/?bucket_name=&with_domains=true&business_type=file&perPage=100&page=1&tag=all&state=all&type=ucdn&security_cdn=false',
method: 'GET',
data:{}
}
const res = await this.doRequest(req);
const buckets = res.data?.buckets;
if(!buckets || buckets.length === 0){
throw new Error('没有找到CDN加速域名');
}
const list= []
for (const item of buckets) {
for (const domain of item.domains) {
list.push({
domain:domain.domain,
bucket:item.bucket_name
});
}
}
const options = list.map((item: any) => {
return {
value: item.domain,
label: `${item.domain}<${item.bucket}>`,
domain: item.domain,
};
});
return optionsUtils.buildGroupOptions(options, this.certDomains);
}
}
//实例化一下,注册插件
new UpyunDeployToCdn();