Compare commits

..

3 Commits

Author SHA1 Message Date
b4a75f4968 Changed region 2025-04-05 14:58:52 +05:30
e553bd673a Time changed to one hour 2025-04-05 14:22:47 +05:30
f221f4850e Signed url complete 2025-04-05 12:13:49 +05:30

View File

@ -9,7 +9,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as https from 'https';
import axios from "axios";
import { getStorage } from 'firebase-admin/storage';
const formData = require('form-data');
const Mailgun = require('mailgun.js');
const { convert } = require('html-to-text');
@ -79,8 +79,44 @@ export const sendEmailWithAttachment = onRequest({
response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });
}
});
export const accessFile = onRequest({
region: '#{SERVICES_RGN}#'
}, async (request: Request, response: express.Response) => {
try {
const filePath = request.query.path as string;
if (!filePath) {
response.status(400).send('File path is required');
return;
}
const expirationMs = 60 * 60 * 1000;
const bucket = getStorage().bucket();
const file = bucket.file(filePath);
const [exists] = await file.exists();
if (!exists) {
response.status(404).send('File not found');
return;
}
const [signedUrl] = await file.getSignedUrl({
action: 'read',
expires: Date.now() + expirationMs,
responseDisposition: `attachment; filename="${path.basename(filePath)}"`,
});
response.redirect(signedUrl);
logger.info(`File access redirect for ${filePath}`);
} catch (error) {
logger.error('Error accessing file:', error);
response.status(500).send('Error accessing file');
}
});
export const sendEmailMessage = onRequest({
region: process.env.SERVICES_RGN
region: '#{SERVICES_RGN}#'
}, (request: Request, response: express.Response) => {
const mailgun = new Mailgun(formData);
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
@ -109,7 +145,7 @@ export const sendEmailMessage = onRequest({
});
export const sendSMSMessage = onRequest({
region: process.env.SERVICES_RGN
region: '#{SERVICES_RGN}#'
}, (request: Request, response: express.Response) => {
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
const { to, body } = request.body;
@ -138,7 +174,7 @@ interface Invitation {
export const notifyInvitation = onDocumentCreated({
document: 'notifications/{notificationId}',
region: process.env.SERVICES_RGN
region: '#{SERVICES_RGN}#'
}, async (event: any) => {
const invitation = event.data?.data() as Invitation;
const invitationId = event.params.invitationId;
@ -207,7 +243,7 @@ export const notifyInvitation = onDocumentCreated({
});
export const createCashfreeOrder = onRequest({
region: process.env.SERVICES_RGN
region: '#{SERVICES_RGN}#'
}, async (request: Request, response: express.Response) => {
try {
const authHeader = request.headers.authorization;
@ -298,7 +334,7 @@ export const createCashfreeOrder = onRequest({
});
export const verifyCashfreePayment = onRequest({
region: process.env.SERVICES_RGN
region: '#{SERVICES_RGN}#'
}, async (request: Request, response: express.Response) => {
try {
const orderId = request.body.order_id || request.query.order_id;