mirror of https://github.com/certd/certd
chore: clear file
parent
f30afac47e
commit
620d1d4092
|
@ -8,7 +8,8 @@ services: # 要拉起的服务们
|
||||||
image: registry.cn-shenzhen.aliyuncs.com/handsfree/certd:${TAG}
|
image: registry.cn-shenzhen.aliyuncs.com/handsfree/certd:${TAG}
|
||||||
container_name: certd # 容器名
|
container_name: certd # 容器名
|
||||||
restart: unless-stopped # 重启
|
restart: unless-stopped # 重启
|
||||||
volumes: # 挂载目录
|
volumes:
|
||||||
|
# ↓↓↓↓↓ 修改数据库以及证书存储路径
|
||||||
- /data/certd:/app/data
|
- /data/certd:/app/data
|
||||||
ports: # 端口映射
|
ports: # 端口映射
|
||||||
- "7001:7001"
|
- "7001:7001"
|
||||||
|
|
|
@ -34,10 +34,17 @@ export class FileStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildFilePath(filename: string) {
|
private buildFilePath(filename: string) {
|
||||||
const parentDir = path.join(this.rootDir, this.scope + "", dayjs().format("YYYY-MM-DD"), this.parent + "");
|
const parentDir = path.join(this.rootDir, this.scope + "", this.parent + "", dayjs().format("YYYY-MM-DD"));
|
||||||
if (!fs.existsSync(parentDir)) {
|
if (!fs.existsSync(parentDir)) {
|
||||||
fs.mkdirSync(parentDir, { recursive: true });
|
fs.mkdirSync(parentDir, { recursive: true });
|
||||||
}
|
}
|
||||||
return path.join(parentDir, filename);
|
return path.join(parentDir, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteByParent(scope: string, parent: string) {
|
||||||
|
const dir = path.join(this.rootDir, scope, parent);
|
||||||
|
if (fs.existsSync(dir)) {
|
||||||
|
fs.unlinkSync(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@ export * from "./executor";
|
||||||
export * from "./run-history";
|
export * from "./run-history";
|
||||||
export * from "./context";
|
export * from "./context";
|
||||||
export * from "./storage";
|
export * from "./storage";
|
||||||
|
export * from "./file-store";
|
||||||
|
|
|
@ -78,6 +78,12 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkFile(file: FileItem) {
|
||||||
|
this._result.files!.push({
|
||||||
|
...file,
|
||||||
|
id: uuidv4(),
|
||||||
|
});
|
||||||
|
}
|
||||||
saveFile(filename: string, file: Buffer) {
|
saveFile(filename: string, file: Buffer) {
|
||||||
const filePath = this.ctx.fileStore.writeFile(filename, file);
|
const filePath = this.ctx.fileStore.writeFile(filename, file);
|
||||||
this._result.files!.push({
|
this._result.files!.push({
|
||||||
|
|
|
@ -71,6 +71,9 @@ const development = {
|
||||||
expire: 7 * 24 * 60, //单位秒
|
expire: 7 * 24 * 60, //单位秒
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
certd: {
|
||||||
|
fileRootDir: '/app/data/files',
|
||||||
|
},
|
||||||
} as MidwayConfig;
|
} as MidwayConfig;
|
||||||
mergeConfig(development, 'development');
|
mergeConfig(development, 'development');
|
||||||
export default development;
|
export default development;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { BaseService } from '../../../basic/base-service';
|
import { BaseService } from '../../../basic/base-service';
|
||||||
|
@ -7,6 +7,8 @@ import { PipelineEntity } from '../entity/pipeline';
|
||||||
import { HistoryDetail } from '../entity/vo/history-detail';
|
import { HistoryDetail } from '../entity/vo/history-detail';
|
||||||
import { HistoryLogService } from './history-log-service';
|
import { HistoryLogService } from './history-log-service';
|
||||||
import { FileItem, Pipeline, RunnableCollection } from '@certd/pipeline';
|
import { FileItem, Pipeline, RunnableCollection } from '@certd/pipeline';
|
||||||
|
import { FileStore } from '@certd/pipeline';
|
||||||
|
import { logger } from '../../../utils/logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 证书申请
|
* 证书申请
|
||||||
|
@ -18,6 +20,10 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||||
repository: Repository<HistoryEntity>;
|
repository: Repository<HistoryEntity>;
|
||||||
@Inject()
|
@Inject()
|
||||||
logService: HistoryLogService;
|
logService: HistoryLogService;
|
||||||
|
|
||||||
|
@Config('certd')
|
||||||
|
private certdConfig: any;
|
||||||
|
|
||||||
getRepository() {
|
getRepository() {
|
||||||
return this.repository;
|
return this.repository;
|
||||||
}
|
}
|
||||||
|
@ -60,6 +66,11 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||||
}
|
}
|
||||||
let shouldDeleteCount = count - keepCount;
|
let shouldDeleteCount = count - keepCount;
|
||||||
const deleteCountBatch = 100;
|
const deleteCountBatch = 100;
|
||||||
|
const fileStore = new FileStore({
|
||||||
|
rootDir: this.certdConfig.fileRootDir,
|
||||||
|
scope: pipelineId + '',
|
||||||
|
parent: '0',
|
||||||
|
});
|
||||||
while (shouldDeleteCount > 0) {
|
while (shouldDeleteCount > 0) {
|
||||||
const list = await this.repository.find({
|
const list = await this.repository.find({
|
||||||
select: {
|
select: {
|
||||||
|
@ -76,6 +87,15 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||||
});
|
});
|
||||||
await this.repository.remove(list);
|
await this.repository.remove(list);
|
||||||
|
|
||||||
|
for (const historyEntity of list) {
|
||||||
|
const id = historyEntity.id;
|
||||||
|
try {
|
||||||
|
fileStore.deleteByParent(pipelineId + '', id + '');
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('删除文件失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shouldDeleteCount -= deleteCountBatch;
|
shouldDeleteCount -= deleteCountBatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';
|
||||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { In, Repository } from 'typeorm';
|
import { In, Repository } from 'typeorm';
|
||||||
import { BaseService } from '../../../basic/base-service';
|
import { BaseService } from '../../../basic/base-service';
|
||||||
|
@ -38,6 +38,9 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
@Inject()
|
@Inject()
|
||||||
cron: Cron;
|
cron: Cron;
|
||||||
|
|
||||||
|
@Config('certd')
|
||||||
|
private certdConfig: any;
|
||||||
|
|
||||||
getRepository() {
|
getRepository() {
|
||||||
return this.repository;
|
return this.repository;
|
||||||
}
|
}
|
||||||
|
@ -213,6 +216,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||||
accessService: this.accessService,
|
accessService: this.accessService,
|
||||||
storage: new DbStorage(userId, this.storageService),
|
storage: new DbStorage(userId, this.storageService),
|
||||||
emailService: this.emailService,
|
emailService: this.emailService,
|
||||||
|
fileRootDir: this.certdConfig.fileRootDir,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await executor.init();
|
await executor.init();
|
||||||
|
|
Loading…
Reference in New Issue