fix: add reset email template api

This commit is contained in:
Innei
2022-01-09 18:54:48 +08:00
parent 8b47aac02e
commit 395f237006
2 changed files with 39 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import {
BadRequestException,
Body,
Controller,
Delete,
Get,
Param,
Patch,
@@ -13,6 +14,7 @@ import { ApiTags } from '@nestjs/swagger'
import { Auth } from '~/common/decorator/auth.decorator'
import {
EmailService,
EmailTemplateRenderProps,
ReplyMailType,
} from '~/processors/helper/helper.email.service'
import { IConfig } from '../configs/configs.interface'
@@ -63,7 +65,19 @@ export class OptionController {
const template = await this.emailService.readTemplate(
type === 'guest' ? ReplyMailType.Guest : ReplyMailType.Owner,
)
return template
return {
template,
props: {
author: '作者 Author',
link: 'https://example.com',
mail: 'example@example.com',
text: '这是一段回复评论',
title: '标题',
time: '2020/01/01',
master: '你的名字',
ip: '0.0.0.0',
} as EmailTemplateRenderProps,
}
}
@Put('/email/template/reply')
@@ -79,4 +93,10 @@ export class OptionController {
source: body.source,
}
}
@Delete('/email/template/reply')
async deleteEmailReplyTemplate(@Query() { type }: ReplyEmailTypeDto) {
await this.emailService.deleteTemplate(type)
return
}
}

View File

@@ -59,6 +59,20 @@ export class EmailService {
}
}
async deleteTemplate(type: ReplyMailType) {
switch (type) {
case ReplyMailType.Guest:
await this.assetService.removeUserCustomAsset(
'/email-template/guest.template.ejs',
)
break
case ReplyMailType.Owner:
await this.assetService.removeUserCustomAsset(
'/email-template/owner.template.ejs',
)
break
}
}
init() {
this.getConfigFromConfigService()
.then((config) => {
@@ -161,7 +175,7 @@ export class EmailService {
type,
}: {
to: string
source: RenderProps
source: EmailTemplateRenderProps
type: ReplyMailType
}) {
const { seo, mailOptions } = await this.configsService.waitForConfigReady()
@@ -187,7 +201,7 @@ export class EmailService {
})
}
render(template: string, source: RenderProps) {
render(template: string, source: EmailTemplateRenderProps) {
return render(template, {
text: source.text,
time: source.time,
@@ -197,7 +211,7 @@ export class EmailService {
title: source.title,
master: source.master,
mail: source.mail,
} as RenderProps)
} as EmailTemplateRenderProps)
}
getInstance() {
@@ -205,7 +219,7 @@ export class EmailService {
}
}
interface RenderProps {
export interface EmailTemplateRenderProps {
author: string
ip?: string
text: string