Compare commits
3 Commits
f9930b143c
...
b4a75f4968
| Author | SHA1 | Date | |
|---|---|---|---|
| b4a75f4968 | |||
| e553bd673a | |||
| f221f4850e |
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user