mirror of https://github.com/certd/certd
perf: 新增代理设置功能
parent
9b68009eb3
commit
273ab6139f
|
@ -47,6 +47,21 @@ export class HttpError extends Error {
|
|||
}
|
||||
|
||||
export const HttpCommonError = HttpError;
|
||||
|
||||
let defaultAgents = createAgent();
|
||||
|
||||
export function setGlobalProxy(opts: { httpProxy?: string; httpsProxy?: string }) {
|
||||
logger.info('setGlobalProxy:', opts);
|
||||
if (opts.httpProxy) {
|
||||
process.env.HTTP_PROXY = opts.httpProxy;
|
||||
}
|
||||
if (opts.httpsProxy) {
|
||||
process.env.HTTPS_PROXY = opts.httpsProxy;
|
||||
}
|
||||
|
||||
defaultAgents = createAgent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 创建请求实例
|
||||
*/
|
||||
|
@ -54,7 +69,6 @@ export function createAxiosService({ logger }: { logger: Logger }) {
|
|||
// 创建一个 axios 实例
|
||||
const service = axios.create();
|
||||
|
||||
const defaultAgents = createAgent();
|
||||
// 请求拦截
|
||||
service.interceptors.request.use(
|
||||
(config: any) => {
|
||||
|
|
|
@ -24,13 +24,21 @@ export class SysPrivateSettings extends BaseSettings {
|
|||
static __key__ = 'sys.private';
|
||||
jwtKey?: string;
|
||||
encryptSecret?: string;
|
||||
|
||||
httpsProxy? = '';
|
||||
httpProxy? = '';
|
||||
|
||||
removeSecret() {
|
||||
delete this.jwtKey;
|
||||
delete this.encryptSecret;
|
||||
}
|
||||
}
|
||||
|
||||
export class SysInstallInfo extends BaseSettings {
|
||||
static __title__ = '系统安装信息';
|
||||
static __key__ = 'sys.install';
|
||||
static __access__ = 'private';
|
||||
installTime: number;
|
||||
installTime?: number;
|
||||
siteId?: string;
|
||||
bindUserId?: number;
|
||||
bindUrl?: string;
|
||||
|
|
|
@ -7,6 +7,7 @@ import { BaseSettings, SysPrivateSettings, SysPublicSettings } from './models.js
|
|||
import * as _ from 'lodash-es';
|
||||
import { BaseService } from '../../../basic/index.js';
|
||||
import { isComm } from '@certd/pipeline';
|
||||
import { setGlobalProxy } from '@certd/basic';
|
||||
|
||||
/**
|
||||
* 设置
|
||||
|
@ -118,8 +119,25 @@ export class SysSettingsService extends BaseService<SysSettingsEntity> {
|
|||
await this.saveSetting(bean);
|
||||
}
|
||||
|
||||
async getPrivateSettings(): Promise<SysPrivateSettings> {
|
||||
return await this.getSetting(SysPrivateSettings);
|
||||
}
|
||||
|
||||
async savePrivateSettings(bean: SysPrivateSettings) {
|
||||
this.saveSetting(bean);
|
||||
await this.saveSetting(bean);
|
||||
|
||||
//让设置生效
|
||||
await this.reloadPrivateSettings();
|
||||
}
|
||||
|
||||
async reloadPrivateSettings() {
|
||||
const bean = await this.getPrivateSettings();
|
||||
if (bean.httpProxy || bean.httpsProxy) {
|
||||
setGlobalProxy({
|
||||
httpProxy: bean.httpProxy,
|
||||
httpsProxy: bean.httpsProxy,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async updateByKey(key: string, setting: any) {
|
||||
|
|
|
@ -195,6 +195,7 @@ export abstract class CertApplyBasePlugin extends AbstractTaskPlugin {
|
|||
async condition() {
|
||||
if (this.forceUpdate) {
|
||||
this.logger.info("强制更新证书选项已勾选,准备申请新证书");
|
||||
this.logger.warn("申请完之后,切记取消强制更新,避免申请过多证书。");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ export type SiteEnv = {
|
|||
};
|
||||
};
|
||||
export type SiteInfo = {
|
||||
title: string;
|
||||
slogan: string;
|
||||
logo: string;
|
||||
loginLogo: string;
|
||||
icpNo: string;
|
||||
title?: string;
|
||||
slogan?: string;
|
||||
logo?: string;
|
||||
loginLogo?: string;
|
||||
icpNo?: string;
|
||||
licenseTo?: string;
|
||||
licenseToUrl?: string;
|
||||
};
|
||||
|
|
|
@ -77,10 +77,10 @@
|
|||
<a :href="siteInfo.licenseToUrl || ''">{{ siteInfo.licenseTo }}</a>
|
||||
</template>
|
||||
|
||||
<template v-if="siteInfo.icpNo">
|
||||
<template v-if="sysPublic.icpNo">
|
||||
<a-divider type="vertical" />
|
||||
<span>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">{{ siteInfo.icpNo }}</a>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">{{ sysPublic.icpNo }}</a>
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
|
@ -140,6 +140,9 @@ const userStore = useUserStore();
|
|||
|
||||
const settingStore = useSettingStore();
|
||||
|
||||
const sysPublic = computed(() => {
|
||||
return settingStore.sysPublic;
|
||||
});
|
||||
const siteInfo = computed(() => {
|
||||
return settingStore.siteInfo;
|
||||
});
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
<a-divider type="vertical" />
|
||||
<a :href="siteInfo.licenseToUrl" target="_blank">{{ siteInfo.licenseTo }}</a>
|
||||
</span>
|
||||
<span v-if="siteInfo.icpNo">
|
||||
<span v-if="sysPublic.icpNo">
|
||||
<a-divider type="vertical" />
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">{{ siteInfo.icpNo }}</a>
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">{{ sysPublic.icpNo }}</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -40,13 +40,17 @@
|
|||
<script lang="ts" setup>
|
||||
import { env } from "/@/utils/util.env";
|
||||
import { computed, ref, Ref } from "vue";
|
||||
import { SiteInfo, useSettingStore } from "/@/store/modules/settings";
|
||||
import { useSettingStore } from "/@/store/modules/settings";
|
||||
import { SiteInfo, SysPublicSetting } from "/@/api/modules/api.basic";
|
||||
|
||||
const envRef = ref(env);
|
||||
const settingStore = useSettingStore();
|
||||
const siteInfo: Ref<SiteInfo> = computed(() => {
|
||||
return settingStore.siteInfo;
|
||||
});
|
||||
const sysPublic: Ref<SysPublicSetting> = computed(() => {
|
||||
return settingStore.sysPublic;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
|
|
|
@ -44,12 +44,11 @@ const defaultThemeConfig = {
|
|||
mode: "light"
|
||||
};
|
||||
const SETTING_THEME_KEY = "SETTING_THEME";
|
||||
const defaultSiteInfo = {
|
||||
const defaultSiteInfo: SiteInfo = {
|
||||
title: env.TITLE || "Certd",
|
||||
slogan: env.SLOGAN || "让你的证书永不过期",
|
||||
logo: env.LOGO || "/static/images/logo/logo.svg",
|
||||
loginLogo: env.LOGIN_LOGO || "/static/images/logo/rect-block.svg",
|
||||
icpNo: env.ICP_NO,
|
||||
licenseTo: "",
|
||||
licenseToUrl: ""
|
||||
};
|
||||
|
@ -69,7 +68,7 @@ export const useSettingStore = defineStore({
|
|||
sysPublic: {
|
||||
registerEnabled: false,
|
||||
managerOtherUserPipeline: false,
|
||||
icpNo: ""
|
||||
icpNo: env.ICP_NO || ""
|
||||
},
|
||||
installInfo: {
|
||||
siteId: "",
|
||||
|
@ -148,11 +147,6 @@ export const useSettingStore = defineStore({
|
|||
siteInfo.loginLogo = `/api/basic/file/download?key=${siteInfo.loginLogo}`;
|
||||
}
|
||||
}
|
||||
|
||||
const sysPublic = this.getSysPublic;
|
||||
if (sysPublic.icpNo) {
|
||||
siteInfo.icpNo = sysPublic.icpNo;
|
||||
}
|
||||
this.siteInfo = _.merge({}, defaultSiteInfo, siteInfo);
|
||||
},
|
||||
async checkUrlBound() {
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
// @ts-ignore
|
||||
import { request } from "/@/api/service";
|
||||
const apiPrefix = "/sys/settings";
|
||||
export type SysSettings = { public: SysPublicSetting; private: SysPrivateSetting };
|
||||
|
||||
export type SysPublicSetting = {
|
||||
registerEnabled?: boolean;
|
||||
managerOtherUserPipeline?: boolean;
|
||||
icpNo?: string;
|
||||
};
|
||||
|
||||
export type SysPrivateSetting = {
|
||||
httpProxy?: string;
|
||||
httpsProxy?: string;
|
||||
};
|
||||
|
||||
export const SettingKeys = {
|
||||
SysPublic: "sys.public",
|
||||
|
@ -8,13 +20,17 @@ export const SettingKeys = {
|
|||
SysEmail: "sys.email"
|
||||
};
|
||||
export async function SettingsGet(key: string) {
|
||||
return await request({
|
||||
const res = await request({
|
||||
url: apiPrefix + "/get",
|
||||
method: "post",
|
||||
params: {
|
||||
key
|
||||
}
|
||||
});
|
||||
if (!res) {
|
||||
return {};
|
||||
}
|
||||
return JSON.parse(res.setting);
|
||||
}
|
||||
|
||||
export async function SettingsSave(key: string, setting: any) {
|
||||
|
@ -35,17 +51,24 @@ export async function EmailSettingsGet() {
|
|||
});
|
||||
}
|
||||
|
||||
export async function PublicSettingsSave(setting: any) {
|
||||
return await request({
|
||||
url: apiPrefix + "/savePublicSettings",
|
||||
method: "post",
|
||||
data: setting
|
||||
});
|
||||
}
|
||||
|
||||
export async function stopOtherUserTimer() {
|
||||
return await request({
|
||||
url: apiPrefix + "/stopOtherUserTimer",
|
||||
method: "post"
|
||||
});
|
||||
}
|
||||
|
||||
export async function SysSettingsGet(): Promise<SysSettings> {
|
||||
return await request({
|
||||
url: apiPrefix + "/getSysSettings",
|
||||
method: "post"
|
||||
});
|
||||
}
|
||||
|
||||
export async function SysSettingsSave(data: SysSettings) {
|
||||
return await request({
|
||||
url: apiPrefix + "/saveSysSettings",
|
||||
method: "post",
|
||||
data: data
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,29 +13,28 @@
|
|||
@finish="onFinish"
|
||||
@finish-failed="onFinishFailed"
|
||||
>
|
||||
<a-form-item label="开启自助注册" name="registerEnabled">
|
||||
<a-switch v-model:checked="formState.registerEnabled" />
|
||||
<a-form-item label="开启自助注册" :name="['public', 'registerEnabled']">
|
||||
<a-switch v-model:checked="formState.public.registerEnabled" />
|
||||
</a-form-item>
|
||||
<a-form-item label="管理其他用户流水线" name="managerOtherUserPipeline">
|
||||
<a-switch v-model:checked="formState.managerOtherUserPipeline" />
|
||||
<a-form-item label="管理其他用户流水线" :name="['public', 'managerOtherUserPipeline']">
|
||||
<a-switch v-model:checked="formState.public.managerOtherUserPipeline" />
|
||||
</a-form-item>
|
||||
<a-form-item label="ICP备案号" name="icpNo">
|
||||
<a-input v-model:value="formState.icpNo" />
|
||||
<a-form-item label="ICP备案号" :name="['public', 'icpNo']">
|
||||
<a-input v-model:value="formState.public.icpNo" placeholder="粤ICP备xxxxxxx号" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="HTTP代理" :name="['private', 'httpProxy']" :rules="urlRules">
|
||||
<a-input v-model:value="formState.private.httpProxy" placeholder="http://192.168.1.2:18010/" />
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item label="HTTPS代理" :name="['private', 'httpsProxy']" :rules="urlRules">
|
||||
<a-input v-model:value="formState.private.httpsProxy" placeholder="http://192.168.1.2:18010/" />
|
||||
<div class="helper">一般这两个代理填一样的</div>
|
||||
</a-form-item>
|
||||
<!-- <a-form-item label="启动后触发流水线" name="triggerOnStartup">-->
|
||||
<!-- <a-switch v-model:checked="formState.triggerOnStartup" />-->
|
||||
<!-- <div class="helper">启动后自动触发一次所有已启用的流水线</div>-->
|
||||
<!-- </a-form-item>-->
|
||||
<a-form-item :wrapper-col="{ offset: 8, span: 16 }">
|
||||
<a-button :loading="saveLoading" type="primary" html-type="submit">保存</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
||||
<!-- <a-descriptions label="系统维护操作">-->
|
||||
<!-- <a-descriptions-item label="自动化任务">-->
|
||||
<!-- <a-button @click="stopOtherUserTimer">停止所有其他用户的定时任务</a-button>-->
|
||||
<!-- </a-descriptions-item>-->
|
||||
<!-- </a-descriptions>-->
|
||||
</div>
|
||||
</fs-page>
|
||||
</template>
|
||||
|
@ -43,42 +42,41 @@
|
|||
<script setup lang="ts">
|
||||
import { reactive, ref } from "vue";
|
||||
import * as api from "./api";
|
||||
import { PublicSettingsSave, SettingKeys } from "./api";
|
||||
import { SysSettings } from "./api";
|
||||
import { notification } from "ant-design-vue";
|
||||
import { useSettingStore } from "/@/store/modules/settings";
|
||||
import { merge } from "lodash-es";
|
||||
|
||||
defineOptions({
|
||||
name: "SysSettings"
|
||||
});
|
||||
|
||||
interface FormState {
|
||||
registerEnabled: boolean;
|
||||
managerOtherUserPipeline: boolean;
|
||||
icpNo: string;
|
||||
}
|
||||
|
||||
const formState = reactive<Partial<FormState>>({
|
||||
registerEnabled: false,
|
||||
managerOtherUserPipeline: false,
|
||||
icpNo: ""
|
||||
const formState = reactive<Partial<SysSettings>>({
|
||||
public: {
|
||||
registerEnabled: false,
|
||||
managerOtherUserPipeline: false,
|
||||
icpNo: ""
|
||||
},
|
||||
private: {}
|
||||
});
|
||||
|
||||
async function loadSysPublicSettings() {
|
||||
const data: any = await api.SettingsGet(SettingKeys.SysPublic);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
const setting = JSON.parse(data.setting);
|
||||
Object.assign(formState, setting);
|
||||
const urlRules = ref({
|
||||
type: "url",
|
||||
message: "请输入正确的URL"
|
||||
});
|
||||
|
||||
async function loadSysSettings() {
|
||||
const data: any = await api.SysSettingsGet();
|
||||
merge(formState, data);
|
||||
}
|
||||
|
||||
const saveLoading = ref(false);
|
||||
loadSysPublicSettings();
|
||||
loadSysSettings();
|
||||
const settingsStore = useSettingStore();
|
||||
const onFinish = async (form: any) => {
|
||||
try {
|
||||
saveLoading.value = true;
|
||||
await api.PublicSettingsSave(form);
|
||||
await api.SysSettingsSave(form);
|
||||
await settingsStore.loadSysSettings();
|
||||
notification.success({
|
||||
message: "保存成功"
|
||||
|
|
|
@ -53,6 +53,8 @@ export class AutoInitSite {
|
|||
await this.sysSettingsService.saveSetting(privateInfo);
|
||||
}
|
||||
|
||||
await this.sysSettingsService.reloadPrivateSettings();
|
||||
|
||||
// 授权许可
|
||||
try {
|
||||
await this.plusService.verify();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ALL, Body, Controller, Get, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController, Constants, PlusService, SysInstallInfo, SysSettingsService } from '@certd/lib-server';
|
||||
import { AppKey, logger, PlusRequestService, verify } from '@certd/pipeline';
|
||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController, PlusService, SysInstallInfo, SysSettingsService } from '@certd/lib-server';
|
||||
import { AppKey, logger } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -51,42 +51,42 @@ export class SysPlusController extends BaseController {
|
|||
|
||||
return this.ok(true);
|
||||
}
|
||||
|
||||
@Get('/test', { summary: Constants.per.guest })
|
||||
async test() {
|
||||
const subjectId = 'vpyoZb6fDBjzzSZp67OBP';
|
||||
const license = '';
|
||||
const timestamps = 1728365013899;
|
||||
const bindUrl = 'http://89.21.0.171:7001/';
|
||||
const service = new PlusRequestService({
|
||||
subjectId: subjectId,
|
||||
plusServerBaseUrls: ['https://api.ai.handsfree.work'],
|
||||
});
|
||||
const body = { subjectId, appKey: 'kQth6FHM71IPV3qdWc', url: bindUrl };
|
||||
|
||||
async function test() {
|
||||
await verify({
|
||||
subjectId: subjectId,
|
||||
license: license,
|
||||
plusRequestService: service,
|
||||
});
|
||||
|
||||
const res = await service.sign(body, timestamps);
|
||||
console.log('sign:', res);
|
||||
|
||||
const res2 = await service.request({
|
||||
url: '/activation/subject/vip/check',
|
||||
data: {
|
||||
url: 'http://127.0.0.1:7001/',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('res2:', res2);
|
||||
}
|
||||
console.log('2222');
|
||||
await test();
|
||||
console.log('3333');
|
||||
|
||||
return this.ok(true);
|
||||
}
|
||||
//
|
||||
// @Get('/test', { summary: Constants.per.guest })
|
||||
// async test() {
|
||||
// const subjectId = 'xxxxxx';
|
||||
// const license = '';
|
||||
// const timestamps = 1728365013899;
|
||||
// const bindUrl = 'http://127.0.0.1:7001/';
|
||||
// const service = new PlusRequestService({
|
||||
// subjectId: subjectId,
|
||||
// plusServerBaseUrls: ['https://api.ai.handsfree.work'],
|
||||
// });
|
||||
// const body = { subjectId, appKey: 'kQth6FHM71IPV3qdWc', url: bindUrl };
|
||||
//
|
||||
// async function test() {
|
||||
// await verify({
|
||||
// subjectId: subjectId,
|
||||
// license: license,
|
||||
// plusRequestService: service,
|
||||
// });
|
||||
//
|
||||
// const res = await service.sign(body, timestamps);
|
||||
// console.log('sign:', res);
|
||||
//
|
||||
// const res2 = await service.request({
|
||||
// url: '/activation/subject/vip/check',
|
||||
// data: {
|
||||
// url: 'http://127.0.0.1:7001/',
|
||||
// },
|
||||
// });
|
||||
//
|
||||
// console.log('res2:', res2);
|
||||
// }
|
||||
// console.log('2222');
|
||||
// await test();
|
||||
// console.log('3333');
|
||||
//
|
||||
// return this.ok(true);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { CrudController, SysPublicSettings, SysSettingsService } from '@certd/lib-server';
|
||||
import { CrudController, SysPrivateSettings, SysPublicSettings, SysSettingsService } from '@certd/lib-server';
|
||||
import { SysSettingsEntity } from '../entity/sys-settings.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import { PipelineService } from '../../../pipeline/service/pipeline-service.js';
|
||||
|
@ -77,12 +77,23 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
|
|||
return this.ok(conf);
|
||||
}
|
||||
|
||||
@Post('/getSysSettings', { summary: 'sys:settings:edit' })
|
||||
async getSysSettings() {
|
||||
const publicSettings = await this.service.getPublicSettings();
|
||||
const privateSettings = await this.service.getPrivateSettings();
|
||||
privateSettings.removeSecret();
|
||||
return this.ok({ public: publicSettings, private: privateSettings });
|
||||
}
|
||||
|
||||
// savePublicSettings
|
||||
@Post('/savePublicSettings', { summary: 'sys:settings:edit' })
|
||||
async savePublicSettings(@Body(ALL) body) {
|
||||
const setting = new SysPublicSettings();
|
||||
_.merge(setting, body);
|
||||
await this.service.savePublicSettings(setting);
|
||||
@Post('/saveSysSettings', { summary: 'sys:settings:edit' })
|
||||
async saveSysSettings(@Body(ALL) body: { public: SysPublicSettings; private: SysPrivateSettings }) {
|
||||
const publicSettings = await this.service.getPublicSettings();
|
||||
const privateSettings = await this.service.getPrivateSettings();
|
||||
_.merge(publicSettings, body.public);
|
||||
_.merge(privateSettings, body.private);
|
||||
await this.service.savePublicSettings(publicSettings);
|
||||
await this.service.savePrivateSettings(privateSettings);
|
||||
return this.ok({});
|
||||
}
|
||||
@Post('/stopOtherUserTimer', { summary: 'sys:settings:edit' })
|
||||
|
|
Loading…
Reference in New Issue