Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,536 changes: 1,458 additions & 78 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"express": "^5.1.0",
"fluent-ffmpeg": "^2.1.3",
"http-errors": "^2.0.0",
"nodemailer": "^7.0.3"
"nodemailer": "^7.0.3",
"mjml": "^4.15.3"
},
"license": "MIT",
"devDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import createError from "http-errors";
import { HTTP_STATUS, MESSAGES } from "./config/constants.js";
import env from "./config/env.js";
import editRoutes from "./routes/editRoutes.js";
import emailRoutes from "./routes/emailRoutes.js";
import videoRoutes from "./routes/videoRoutes.js";

const app = express();

app.use("/images", express.static("public/images"));
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.use(`${env.API_PREFIX}/`, emailRoutes);
app.use(`${env.API_PREFIX}/video`, videoRoutes);
app.use(`${env.API_PREFIX}/edit`, editRoutes);

Expand Down
11 changes: 10 additions & 1 deletion src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const MESSAGES = {
},
};

const CODE = {
SUCCESS: {
SUCCESS_ANALYZE: "SUCCESS_ANALYZE",
},
ERROR: {
FAILED_ANALYZE: "FAILED_ANALYZE",
},
};

const HTTP_STATUS = {
OK: 200,
CREATED: 201,
Expand All @@ -52,4 +61,4 @@ const REGEX_PATTERNS = {
EMAIL: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i,
};

export { MESSAGES, HTTP_STATUS, GCS, REQUIRED_FIELDS, REGEX_PATTERNS };
export { MESSAGES, HTTP_STATUS, GCS, REQUIRED_FIELDS, REGEX_PATTERNS, CODE };
17 changes: 0 additions & 17 deletions src/controllers/emailController.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/routes/emailRoutes.js

This file was deleted.

27 changes: 17 additions & 10 deletions src/services/emailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { fileURLToPath } from "url";

import ejs from "ejs";
import createError from "http-errors";
import mjml2html from "mjml";
Comment thread
ChaJunWoo-dev marked this conversation as resolved.
import nodemailer from "nodemailer";

import { MESSAGES } from "../config/constants.js";
import { MESSAGES, CODE } from "../config/constants.js";
import env from "../config/env.js";

const filename = fileURLToPath(import.meta.url);
Expand All @@ -20,28 +21,34 @@ const transporter = nodemailer.createTransport({
},
});

const readEmailTemplate = async ({ message, url }) => {
const readEmailTemplate = async ({ code, message, url }) => {
try {
if (url === "") {
const filePath = path.join(dirname, "../views/errorTemplate.ejs");
if (code === CODE.ERROR.FAILED_ANALYZE) {
const filePath = path.join(dirname, "../views", "errorTemplate.mjml.ejs");
const template = await fs.readFile(filePath, "utf-8");
const htmlContent = ejs.render(template, { message });
const { html } = mjml2html(htmlContent, {
validationLevel: "strict",
});

return htmlContent;
return html;
}
const filePath = path.join(dirname, "../views/emailTemplate.ejs");
const filePath = path.join(dirname, "../views", "emailTemplate.mjml.ejs");
const template = await fs.readFile(filePath, "utf-8");
const htmlContent = ejs.render(template, { message, url });
const htmlContent = ejs.render(template, { url });
const { html } = mjml2html(htmlContent, {
validationLevel: "strict",
});

return htmlContent;
return html;
} catch (err) {
throw createError.InternalServerError(MESSAGES.ERROR.FAILED_READ_TEMPLATE);
}
};

const sendEmail = async ({ email, message, url }) => {
const sendEmail = async ({ email, code, message, url }) => {
try {
const html = await readEmailTemplate({ message, url });
const html = await readEmailTemplate({ code, message, url });
const mailOptions = {
from: env.email_user,
to: email,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/rabbitmqService.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const consumeEmailQueue = async () => {
return;
}

const { email, message, url } = JSON.parse(msg.content.toString());
const { email, code, message, url } = JSON.parse(msg.content.toString());

try {
await sendEmail({ email, message, url });
await sendEmail({ email, code, message, url });
channel.ack(msg);
} catch {
channel.nack(msg, false, false);
Expand Down
65 changes: 0 additions & 65 deletions src/views/emailTemplate.ejs

This file was deleted.

71 changes: 71 additions & 0 deletions src/views/emailTemplate.mjml.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<mjml>
<mj-head>
<mj-font
name="Pretendard"
href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css"
/>
<mj-attributes>
<mj-all font-family="Pretendard, Arial" color="#404040" />
</mj-attributes>
</mj-head>
<mj-body>
<mj-section
background-color="#ffffff"
border="1px solid #E5E7EB"
border-radius="8px"
padding="20px"
>
<mj-column>
<mj-image
width="90px"
height="40px"
src="https://raw.githubusercontent.com/cholulu99/commandTrackerImage/main/3f4-7420ead14100-removebg-preview.png"
></mj-image>
<mj-spacer height="20px"></mj-spacer>
<mj-text align="center" font-size="16px" line-height="1.5">
command Tracker 서비스를 사용해주셔서 감사합니다.
</mj-text>
<mj-text align="center" font-size="16px" line-height="1.5">
요청하신 캐릭터의 커맨드는 자막으로 보여집니다.
</mj-text>
<mj-divider border-color="#E5E7EB" border-width="1px"></mj-divider>
<mj-text align="center" font-size="16px">
아래는 스트리트파이터 6의 기본 공격 커맨드입니다:
</mj-text>
<mj-text align="center" font-size="14px">
<p>LP: 약펀치</p>
<p>MP: 중간펀치</p>
<p>HP: 강펀치</p>
<p>LK: 약발</p>
<p>MK: 중발</p>
<p>HK: 강발</p>
</mj-text>
<mj-button
align="center"
href="<%= url %>"
background-color="#007BFF"
color="#ffffff"
>
영상 다운로드
</mj-button>
<mj-divider border-color="#E5E7EB" border-width="1px"></mj-divider>
<mj-text align="center" font-size="12px" line-height="1.75">
<a
href="https://www.naver.com"
target="_blank"
rel="noopener noreferrer nofollow"
>웹사이트</a
>
</mj-text>
<mj-text
align="center"
font-family="Pretendard, Arial"
font-size="12px"
line-height="1"
>
© command Tracker. All Rights Reserved.
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
64 changes: 0 additions & 64 deletions src/views/errorTemplate.ejs

This file was deleted.

Loading