mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
feat: 支持postgresql
This commit is contained in:
@@ -5,6 +5,7 @@ import { MidwayConfig } from '@midwayjs/core';
|
||||
// // const __filename = fileURLToPath(import.meta.url);
|
||||
// const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// eslint-disable-next-line node/no-extraneous-import
|
||||
import { FlywayHistory } from '@certd/midway-flyway-js';
|
||||
import { UserEntity } from '../modules/authority/entity/user.js';
|
||||
import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
|
||||
@@ -13,6 +14,8 @@ import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
|
||||
import { mergeConfig } from './loader.js';
|
||||
import { Keys } from './keys.js';
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
const keys = Keys.load();
|
||||
const development = {
|
||||
keys: keys.cookieKeys,
|
||||
@@ -81,6 +84,6 @@ const development = {
|
||||
resetAdminPasswd: false,
|
||||
},
|
||||
} as MidwayConfig;
|
||||
mergeConfig(development, 'development');
|
||||
mergeConfig(development, env);
|
||||
|
||||
export default development;
|
||||
|
||||
@@ -2,6 +2,7 @@ import path from 'path';
|
||||
import * as _ from 'lodash-es';
|
||||
import yaml from 'js-yaml';
|
||||
import fs from 'fs';
|
||||
import { logger } from '../utils/logger.js';
|
||||
|
||||
function parseEnv(defaultConfig: any) {
|
||||
const config = {};
|
||||
@@ -28,6 +29,7 @@ function parseEnv(defaultConfig: any) {
|
||||
|
||||
export function load(config, env = '') {
|
||||
// Get document, or throw exception on error
|
||||
logger.info('load config', env);
|
||||
const yamlPath = path.join(process.cwd(), `.env.${env}.yaml`);
|
||||
const doc = yaml.load(fs.readFileSync(yamlPath, 'utf8'));
|
||||
_.merge(doc, parseEnv(config));
|
||||
|
||||
@@ -12,21 +12,11 @@ export class DbStorage implements IStorage {
|
||||
this.storageService = storageService;
|
||||
}
|
||||
|
||||
remove(
|
||||
scope: string,
|
||||
namespace: string,
|
||||
version: string,
|
||||
key: string
|
||||
): Promise<void> {
|
||||
remove(scope: string, namespace: string, version: string, key: string): Promise<void> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
async get(
|
||||
scope: string,
|
||||
namespace: string,
|
||||
version: string,
|
||||
key: string
|
||||
): Promise<string | null> {
|
||||
async get(scope: string, namespace: string, version: string, key: string): Promise<string | null> {
|
||||
const storageEntity = await this.storageService.get({
|
||||
userId: this.userId,
|
||||
scope: scope,
|
||||
@@ -41,13 +31,7 @@ export class DbStorage implements IStorage {
|
||||
return null;
|
||||
}
|
||||
|
||||
async set(
|
||||
scope: string,
|
||||
namespace: string,
|
||||
version: string,
|
||||
key: string,
|
||||
value: string
|
||||
): Promise<void> {
|
||||
async set(scope: string, namespace: string, version: string, key: string, value: string): Promise<void> {
|
||||
await this.storageService.set({
|
||||
userId: this.userId,
|
||||
scope: scope,
|
||||
|
||||
@@ -16,13 +16,7 @@ export class StorageService extends BaseService<StorageEntity> {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
async get(where: {
|
||||
scope: any;
|
||||
namespace: any;
|
||||
userId: number;
|
||||
version: string;
|
||||
key: string;
|
||||
}) {
|
||||
async get(where: { scope: any; namespace: any; userId: number; version: string; key: string }) {
|
||||
if (where.userId == null) {
|
||||
throw new Error('userId 不能为空');
|
||||
}
|
||||
@@ -31,15 +25,7 @@ export class StorageService extends BaseService<StorageEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
async set(entity: {
|
||||
id?: any;
|
||||
scope: any;
|
||||
namespace: any;
|
||||
userId: number;
|
||||
version: string;
|
||||
value: string;
|
||||
key: string;
|
||||
}) {
|
||||
async set(entity: { id?: any; scope: any; namespace: any; userId: number; version: string; value: string; key: string }) {
|
||||
entity.id = null;
|
||||
const query = { ...entity };
|
||||
delete query.value;
|
||||
|
||||
Reference in New Issue
Block a user