chore: project controller

This commit is contained in:
xiaojunnuo
2026-02-11 00:07:29 +08:00
parent 784bcb0aa5
commit 1e416b9f8a
33 changed files with 773 additions and 53 deletions
@@ -1,11 +1,17 @@
import { Inject } from '@midwayjs/core';
import { ApplicationContext, Inject } from '@midwayjs/core';
import type {IMidwayContainer} from '@midwayjs/core';
import * as koa from '@midwayjs/koa';
import { Constants } from './constants.js';
import { isEnterprise } from './mode.js';
export abstract class BaseController {
@Inject()
ctx: koa.Context;
@ApplicationContext()
applicationContext: IMidwayContainer;
/**
* 成功返回
* @param data 返回数据
@@ -55,4 +61,36 @@ export abstract class BaseController {
}
}
getProjectId(permission:string) {
if (!isEnterprise()) {
return null
}
const projectIdStr = this.ctx.headers["project-id"] as string;
if (!projectIdStr) {
throw new Error("projectId 不能为空")
}
const userId = this.getUserId()
const projectId = parseInt(projectIdStr)
this.checkProjectPermission(userId, projectId,permission)
return projectId;
}
getProjectUserId(permission:string){
let userId = this.getUserId()
const projectId = this.getProjectId(permission)
if(projectId){
userId = 0
}
return {
projectId,userId
}
}
async checkProjectPermission(userId: number, projectId: number,permission:string) {
const projectService:any = await this.applicationContext.getAsync("projectService");
await projectService.checkPermission({userId,projectId,permission})
}
}
@@ -5,3 +5,4 @@ export * from './enum-item.js';
export * from './exception/index.js';
export * from './result.js';
export * from './base-service.js';
export * from "./mode.js"
@@ -0,0 +1,12 @@
let adminMode = "saas"
export function setAdminMode(mode:string = "saas"){
adminMode = mode
}
export function getAdminMode(){
return adminMode
}
export function isEnterprise(){
return adminMode === "enterprise"
}
@@ -7,9 +7,9 @@ import { BaseSettings, SysInstallInfo, SysPrivateSettings, SysPublicSettings, Sy
import { getAllSslProviderDomains, setSslProviderReverseProxies } from '@certd/acme-client';
import { cache, logger, mergeUtils, setGlobalProxy } from '@certd/basic';
import * as dns from 'node:dns';
import { BaseService } from '../../../basic/index.js';
import { BaseService, setAdminMode } from '../../../basic/index.js';
import { executorQueue } from '../../basic/service/executor-queue.js';
const {merge} = mergeUtils;
const { merge } = mergeUtils;
/**
* 设置
*/
@@ -117,6 +117,8 @@ export class SysSettingsService extends BaseService<SysSettingsEntity> {
async savePublicSettings(bean: SysPublicSettings) {
await this.saveSetting(bean);
//让设置生效
await this.reloadPublicSettings();
}
async getPrivateSettings(): Promise<SysPrivateSettings> {
@@ -137,23 +139,33 @@ export class SysSettingsService extends BaseService<SysSettingsEntity> {
await this.reloadPrivateSettings();
}
async reloadSettings() {
await this.reloadPrivateSettings()
await this.reloadPublicSettings()
}
async reloadPublicSettings() {
const publicSetting = await this.getPublicSettings()
setAdminMode(publicSetting.adminMode)
}
async reloadPrivateSettings() {
const bean = await this.getPrivateSettings();
const privateSetting = await this.getPrivateSettings();
const opts = {
httpProxy: bean.httpProxy,
httpsProxy: bean.httpsProxy,
httpProxy: privateSetting.httpProxy,
httpsProxy: privateSetting.httpsProxy,
};
setGlobalProxy(opts);
if (bean.dnsResultOrder) {
dns.setDefaultResultOrder(bean.dnsResultOrder as any);
if (privateSetting.dnsResultOrder) {
dns.setDefaultResultOrder(privateSetting.dnsResultOrder as any);
}
if (bean.pipelineMaxRunningCount){
executorQueue.setMaxRunningCount(bean.pipelineMaxRunningCount);
if (privateSetting.pipelineMaxRunningCount) {
executorQueue.setMaxRunningCount(privateSetting.pipelineMaxRunningCount);
}
setSslProviderReverseProxies(bean.reverseProxies);
setSslProviderReverseProxies(privateSetting.reverseProxies);
}
async updateByKey(key: string, setting: any) {