From a41699cc32cce6191ced51aef5901ab1548a13bb Mon Sep 17 00:00:00 2001 From: surmon-china Date: Thu, 6 Jan 2022 02:54:36 +0800 Subject: [PATCH] feat: v3.7.8 --- package.json | 2 +- src/modules/comment/comment.service.ts | 2 +- src/modules/vote/vote.controller.ts | 94 +++++++++++++++----------- 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 936e630f..24fa4446 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodepress", - "version": "3.7.7", + "version": "3.7.8", "description": "RESTful API service for Surmon.me blog", "author": { "name": "Surmon", diff --git a/src/modules/comment/comment.service.ts b/src/modules/comment/comment.service.ts index 674144a9..b04057e7 100755 --- a/src/modules/comment/comment.service.ts +++ b/src/modules/comment/comment.service.ts @@ -66,7 +66,7 @@ export class CommentService { if (comment.pid) { this.commentModel.findOne({ id: comment.pid }).then((parentComment) => { if (parentComment?.author.email) { - const subject = `Your comment ${parentComment.id} has a new reply` + const subject = `Your comment #${parentComment.id} has a new reply` this.emailService.sendMailAs(APP_CONFIG.APP.FE_NAME, { to: parentComment.author.email, subject, diff --git a/src/modules/vote/vote.controller.ts b/src/modules/vote/vote.controller.ts index 85faf71d..1b0df185 100755 --- a/src/modules/vote/vote.controller.ts +++ b/src/modules/vote/vote.controller.ts @@ -68,17 +68,17 @@ export class VoteController { const userInfo = await this.disqusPublicService.getUserInfo(token) const isAdmin = userInfo.username === APP_CONFIG.DISQUS.adminUsername const moderator = isAdmin ? ` / Moderator` : '' - return [`(Disqus user${moderator})`, `${userInfo.name}`, userInfo.url, userInfo.profileUrl] + return [`${userInfo.name} (Disqus user${moderator})`, userInfo.url, userInfo.profileUrl] .filter(Boolean) .join(' ยท ') } catch (error) {} } // local user if (author) { - return `(Guest user) ${author.name}` + return `${author.name} (Guest user)` } // guest user - return `Anonymous user` + return null } private async getTargetTitle(post_id: number) { @@ -148,14 +148,18 @@ export class VoteController { // Disqus this.voteDisqusThread(CommentPostID.Guestbook, 1, token?.access_token).catch(() => {}) // email to admin - this.emailToTargetVoteMessage({ - to: APP_CONFIG.EMAIL.admin, - subject: `You have a new site vote`, - on: await this.getTargetTitle(CommentPostID.Guestbook), - vote: '+1', - author: await this.getAuthor(voteBody.author, token?.access_token), - location: await this.ipService.queryLocation(visitor.ip), - link: getPermalinkByID(CommentPostID.Guestbook), + this.getAuthor(voteBody.author, token?.access_token).then(async (author) => { + if (author) { + this.emailToTargetVoteMessage({ + to: APP_CONFIG.EMAIL.admin, + subject: `You have a new site vote`, + on: await this.getTargetTitle(CommentPostID.Guestbook), + vote: '+1', + author, + location: await this.ipService.queryLocation(visitor.ip), + link: getPermalinkByID(CommentPostID.Guestbook), + }) + } }) return likes @@ -173,14 +177,18 @@ export class VoteController { // Disqus this.voteDisqusThread(voteBody.article_id, voteBody.vote, token?.access_token).catch(() => {}) // email to admin - this.emailToTargetVoteMessage({ - to: APP_CONFIG.EMAIL.admin, - subject: `You have a new article vote`, - on: await this.getTargetTitle(voteBody.article_id), - vote: '+1', - author: await this.getAuthor(voteBody.author, token?.access_token), - location: await this.ipService.queryLocation(visitor.ip), - link: getPermalinkByID(voteBody.article_id), + this.getAuthor(voteBody.author, token?.access_token).then(async (author) => { + if (author) { + this.emailToTargetVoteMessage({ + to: APP_CONFIG.EMAIL.admin, + subject: `You have a new article vote`, + on: await this.getTargetTitle(voteBody.article_id), + vote: '+1', + author, + location: await this.ipService.queryLocation(visitor.ip), + link: getPermalinkByID(voteBody.article_id), + }) + } }) return likes @@ -209,28 +217,32 @@ export class VoteController { } } catch (error) {} } - // email - this.commentService.getDetailByNumberID(voteBody.comment_id).then(async (comment) => { - const tagetTitle = await this.getTargetTitle(comment.post_id) - const mailParams = { - vote: voteBody.vote > 0 ? '+1' : '-1', - on: `${tagetTitle} #${comment.id}`, - author: await this.getAuthor(voteBody.author, token?.access_token), - location: await this.ipService.queryLocation(visitor.ip), - link: getPermalinkByID(comment.post_id), - } - // email to admin - this.emailToTargetVoteMessage({ - to: APP_CONFIG.EMAIL.admin, - subject: `You have a new comment vote`, - ...mailParams, - }) - // email to author - if (comment.author.email) { - this.emailToTargetVoteMessage({ - to: comment.author.email, - subject: `Your comment ${comment.id} has a new vote`, - ...mailParams, + // email to user and admin + this.getAuthor(voteBody.author, token?.access_token).then((author) => { + if (author) { + this.commentService.getDetailByNumberID(voteBody.comment_id).then(async (comment) => { + const tagetTitle = await this.getTargetTitle(comment.post_id) + const mailParams = { + vote: voteBody.vote > 0 ? '+1' : '-1', + on: `${tagetTitle} #${comment.id}`, + author, + location: await this.ipService.queryLocation(visitor.ip), + link: getPermalinkByID(comment.post_id), + } + // email to admin + this.emailToTargetVoteMessage({ + to: APP_CONFIG.EMAIL.admin, + subject: `You have a new comment vote`, + ...mailParams, + }) + // email to author + if (comment.author.email) { + this.emailToTargetVoteMessage({ + to: comment.author.email, + subject: `Your comment #${comment.id} has a new vote`, + ...mailParams, + }) + } }) } })