Update index.js

This commit is contained in:
nguyentrungthat 2025-10-22 11:28:07 +07:00
parent 93985a6837
commit e5ea735a3d
1 changed files with 8 additions and 10 deletions

View File

@ -166,7 +166,7 @@ async function scrapeWithCheerio(url) {
return items;
}
async function sendMail(subject, body, isError = false) {
async function sendMail(subject, body) {
try {
await axios({
url: process.env.API_DISTI_HOST + "/api/export/items-sold-out",
@ -201,9 +201,7 @@ async function sendMail(subject, body, isError = false) {
to: EMAILS.join(","),
subject,
text: body,
attachments: isError
? []
: [
attachments: [
{
filename: fileName,
content: response.data, // attach from memory
@ -270,7 +268,7 @@ async function main() {
if (errors.length > 3) {
const msg = errors.map((e) => `URL: ${e.url}\nMessage: ${e.message}`).join("\n\n");
await sendMail("[New Items] - Scraping Sold Out Error Report", msg, true);
await sendMail("[New Items] - Scraping Sold Out Error Report", msg);
} else {
const msg = inserted.map((i) => `Shop: ${i.name}\nSold: ${i.count} items`).join("\n\n");
await sendMail("[New Items] - Scraping Sold Out Success", msg);