add db migration
This commit is contained in:
@@ -1,33 +1,33 @@
|
||||
import { Optional } from '@nestjs/common';
|
||||
import { isNil } from 'lodash';
|
||||
import { DataSource, EventSubscriber, ObjectType } from 'typeorm';
|
||||
|
||||
import { Configure } from '@/modules/config/configure';
|
||||
import { PostBodyType } from '@/modules/content/constants';
|
||||
import { PostEntity } from '@/modules/content/entities/post.entity';
|
||||
import { PostRepository } from '@/modules/content/repositories/post.repository';
|
||||
import { SanitizeService } from '@/modules/content/services/SanitizeService';
|
||||
import { BaseSubscriber } from '@/modules/database/base/subscriber';
|
||||
|
||||
@EventSubscriber()
|
||||
export class PostSubscriber extends BaseSubscriber<PostEntity> {
|
||||
protected entity: ObjectType<PostEntity> = PostEntity;
|
||||
|
||||
constructor(
|
||||
protected dataSource: DataSource,
|
||||
protected postRepository: PostRepository,
|
||||
protected configure: Configure,
|
||||
@Optional() protected sanitizeService: SanitizeService,
|
||||
protected _configure: Configure,
|
||||
) {
|
||||
super(dataSource);
|
||||
super(dataSource, _configure);
|
||||
}
|
||||
|
||||
get configure(): Configure {
|
||||
return this._configure;
|
||||
}
|
||||
|
||||
async afterLoad(entity: PostEntity) {
|
||||
if (
|
||||
(await this.configure.get('content.htmlEnabled')) &&
|
||||
!isNil(this.sanitizeService) &&
|
||||
entity.type === PostBodyType.HTML
|
||||
) {
|
||||
entity.body = this.sanitizeService.sanitize(entity.body);
|
||||
const sanitizeService = (await this.configure.get('content.htmlEnabled'))
|
||||
? this.container.get(SanitizeService)
|
||||
: undefined;
|
||||
if (!isNil(sanitizeService) && entity.type === PostBodyType.HTML) {
|
||||
entity.body = sanitizeService.sanitize(entity.body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user