Removed unused function
Some checks failed
Deploy FitLien services to Dev / Deploy to Dev (push) Failing after 29s

This commit is contained in:
Benoy Bose 2025-05-26 20:01:19 +05:30
parent e12cbf4148
commit a89168bb74
4 changed files with 0 additions and 126 deletions

View File

@ -27,9 +27,6 @@ jobs:
- name: Replace variables in .env
run: |
sed -i "s/#{MAILGUN_API_KEY}#/${{ secrets.MAILGUN_API_KEY }}/" functions/.env
sed -i "s/#{MAILGUN_SERVER}#/${{ secrets.MAILGUN_SERVER }}/" functions/.env
sed -i "s/#{MAILGUN_FROM_ADDRESS}#/${{ secrets.MAILGUN_FROM_ADDRESS }}/" functions/.env
sed -i "s/#{TWILIO_ACCOUNT_SID}#/${{ secrets.TWILIO_ACCOUNT_SID }}/" functions/.env
sed -i "s/#{TWILIO_AUTH_TOKEN}#/${{ secrets.TWILIO_AUTH_TOKEN }}/" functions/.env
sed -i "s/#{TWILIO_PHONE_NUMBER}#/${{ secrets.TWILIO_PHONE_NUMBER }}/" functions/.env

View File

@ -1,3 +1 @@
export { sendEmailMessage } from './sendEmail';
export { sendEmailWithAttachment } from './sendEmailWithAttachment';
export { sendEmailSES } from './sendEmailSES';

View File

@ -1,40 +0,0 @@
import { onRequest } from "firebase-functions/v2/https";
import { Request } from "firebase-functions/v2/https";
import { getCorsHandler } from "../shared/middleware";
import { getLogger } from "../shared/config";
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const { convert } = require('html-to-text');
const mailgun = new Mailgun(formData);
const logger = getLogger();
const corsHandler = getCorsHandler();
export const sendEmailMessage = onRequest({
region: '#{SERVICES_RGN}#'
}, (request: Request, response) => {
return corsHandler(request, response, async () => {
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY! });
const toAddress = request.body.toAddress;
const subject = request.body.subject;
const message = request.body.message;
const options = {
wordwrap: 130,
};
const textMessage = convert(message, options);
mailGunClient.messages.create(process.env.MAILGUN_SERVER!, {
from: process.env.MAILGUN_FROM_ADDRESS,
to: toAddress,
subject: subject,
text: textMessage,
html: message
}).then((res: any) => {
logger.info(res);
response.send(res);
}).catch((err: any) => {
logger.error(err);
response.send(err);
});
});
});

View File

@ -1,81 +0,0 @@
import { onRequest } from "firebase-functions/v2/https";
import { Request } from "firebase-functions/v2/https";
import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs';
import * as https from 'https';
import { getCorsHandler } from "../shared/middleware";
import { getLogger } from "../shared/config";
import formData from 'form-data';
import Mailgun from 'mailgun.js';
const { convert } = require('html-to-text');
const mailgun = new Mailgun(formData);
const logger = getLogger();
const corsHandler = getCorsHandler();
export const sendEmailWithAttachment = onRequest({
region: '#{SERVICES_RGN}#'
}, async (request: Request, response) => {
return corsHandler(request, response, async () => {
try {
const { toAddress, subject, message, fileUrl, fileName } = request.body;
if (!toAddress || !subject || !message || !fileUrl) {
response.status(400).json({
error: 'Missing required fields (toAddress, subject, message, fileUrl)'
});
return;
}
const tempFilePath = path.join(os.tmpdir(), fileName || 'attachment.pdf');
await new Promise<void>((resolve, reject) => {
const file = fs.createWriteStream(tempFilePath);
https.get(fileUrl, (res) => {
res.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
}).on('error', (err) => {
fs.unlink(tempFilePath, () => { });
reject(err);
});
});
try {
const client = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY! });
const options = {
wordwrap: 130,
};
const textMessage = convert(message, options);
const fileBuffer = fs.readFileSync(tempFilePath);
const attachmentFilename = fileName || path.basename(fileUrl.split('?')[0]);
const data = {
from: process.env.MAILGUN_FROM_ADDRESS,
to: toAddress,
subject: subject,
text: textMessage,
html: message,
attachment: {
data: fileBuffer,
filename: attachmentFilename,
contentType: 'application/pdf',
}
};
const result = await client.messages.create(process.env.MAILGUN_SERVER!, data);
fs.unlinkSync(tempFilePath);
logger.info('Email with attachment from URL sent successfully');
response.json({ success: true, result });
} catch (e) {
console.error(`Error while sending E-mail. Error: ${e}`);
}
} catch (error) {
logger.error('Error sending email with attachment from URL:', error);
response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });
}
});
});