Merge pull request #644 from OpenSignLabs/signPdf

This commit is contained in:
Andrew
2024-04-25 12:25:48 +05:30
committed by GitHub
8 changed files with 81 additions and 69 deletions
+4
View File
@@ -1,4 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config();
const appId = process.env.APP_ID; const appId = process.env.APP_ID;
const serverUrl = process.env.SERVER_URL; const serverUrl = process.env.SERVER_URL;
@@ -243,3 +245,5 @@ export function sanitizeFileName(fileName) {
const removedot = file.replace(/\.(?=.*\.)/g, ''); const removedot = file.replace(/\.(?=.*\.)/g, '');
return removedot.replace(/[^a-zA-Z0-9._-]/g, ''); return removedot.replace(/[^a-zA-Z0-9._-]/g, '');
} }
export const useLocal = process.env.USE_LOCAL ? process.env.USE_LOCAL.toLowerCase() : 'false';
@@ -3,6 +3,7 @@ import multer from 'multer';
import multerS3 from 'multer-s3'; import multerS3 from 'multer-s3';
import aws from 'aws-sdk'; import aws from 'aws-sdk';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import { useLocal } from '../../Utils.js';
dotenv.config(); dotenv.config();
function sanitizeFileName(fileName) { function sanitizeFileName(fileName) {
@@ -51,7 +52,7 @@ async function uploadFile(req, res) {
const parseBaseUrl = process.env.SERVER_URL; const parseBaseUrl = process.env.SERVER_URL;
const parseAppId = process.env.APP_ID; const parseAppId = process.env.APP_ID;
let fileStorage; let fileStorage;
if (process.env.USE_LOCAL == 'TRUE') { if (useLocal === 'true') {
fileStorage = multer.diskStorage({ fileStorage = multer.diskStorage({
destination: function (req, file, cb) { destination: function (req, file, cb) {
cb(null, 'files/files'); cb(null, 'files/files');
@@ -147,7 +148,7 @@ async function uploadFile(req, res) {
const status = 'Success'; const status = 'Success';
//res.header("Access-Control-Allow-Headers", "Content-Type"); //res.header("Access-Control-Allow-Headers", "Content-Type");
//res.setHeader("Access-Control-Allow-Origin", "*"); //res.setHeader("Access-Control-Allow-Origin", "*");
if (process.env.USE_LOCAL == 'TRUE') { if (useLocal === 'true') {
console.log(req.file); console.log(req.file);
var fileUrl = `${parseBaseUrl}/files/${parseAppId}/${req.file.filename}`; var fileUrl = `${parseBaseUrl}/files/${parseAppId}/${req.file.filename}`;
} else { } else {
@@ -1,22 +1,24 @@
import { useLocal } from '../../Utils.js';
import getPresignedUrl from './getSignedUrl.js'; import getPresignedUrl from './getSignedUrl.js';
async function DocumentAfterFind(request) { async function DocumentAfterFind(request) {
if (request.objects.length === 1) { if (useLocal !== 'true') {
if (request.objects) { if (request.objects.length === 1) {
const obj = request.objects[0]; if (request.objects) {
const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl'); const obj = request.objects[0];
const Url = obj?.get('URL') && obj?.get('URL'); const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl');
const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl'); const Url = obj?.get('URL') && obj?.get('URL');
if (SignedUrl) { const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl');
obj.set('SignedUrl', getPresignedUrl(SignedUrl)); if (SignedUrl) {
obj.set('SignedUrl', getPresignedUrl(SignedUrl));
}
if (Url) {
obj.set('URL', getPresignedUrl(Url));
}
if (certificateUrl) {
obj.set('CertificateUrl', getPresignedUrl(certificateUrl));
}
} }
if (Url) {
obj.set('URL', getPresignedUrl(Url));
}
if (certificateUrl) {
obj.set('CertificateUrl', getPresignedUrl(certificateUrl));
}
return [obj]; return [obj];
} }
} }
@@ -1,21 +1,21 @@
import { useLocal } from '../../Utils.js';
import getPresignedUrl from './getSignedUrl.js'; import getPresignedUrl from './getSignedUrl.js';
async function SignatureAfterFind(request) { async function SignatureAfterFind(request) {
if (request.objects.length === 1) { if (useLocal !== 'true') {
if (request.objects) { if (request.objects.length === 1) {
const obj = request.objects[0]; if (request.objects) {
const ImageURL = obj?.get('ImageURL') && obj?.get('ImageURL'); const obj = request.objects[0];
const Initials = obj?.get('Initials') && obj?.get('Initials'); const ImageURL = obj?.get('ImageURL') && obj?.get('ImageURL');
const Initials = obj?.get('Initials') && obj?.get('Initials');
if (ImageURL) { if (ImageURL) {
obj.set('ImageURL', getPresignedUrl(ImageURL)); obj.set('ImageURL', getPresignedUrl(ImageURL));
}
if (Initials) {
obj.set('Initials', getPresignedUrl(Initials));
}
return [obj];
} }
if (Initials) {
obj.set('Initials', getPresignedUrl(Initials));
}
return [obj];
} }
} }
} }
@@ -1,23 +1,26 @@
import { useLocal } from '../../Utils.js';
import getPresignedUrl from './getSignedUrl.js'; import getPresignedUrl from './getSignedUrl.js';
async function TemplateAfterFind(request) { async function TemplateAfterFind(request) {
if (request.objects.length === 1) { if (useLocal !== 'true') {
if (request.objects) { if (request.objects.length === 1) {
const obj = request.objects[0]; if (request.objects) {
const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl'); const obj = request.objects[0];
const Url = obj?.get('URL') && obj?.get('URL'); const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl');
const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl'); const Url = obj?.get('URL') && obj?.get('URL');
if (SignedUrl) { const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl');
obj.set('SignedUrl', getPresignedUrl(SignedUrl)); if (SignedUrl) {
} obj.set('SignedUrl', getPresignedUrl(SignedUrl));
if (Url) { }
obj.set('URL', getPresignedUrl(Url)); if (Url) {
} obj.set('URL', getPresignedUrl(Url));
if (certificateUrl) { }
obj.set('CertificateUrl', getPresignedUrl(certificateUrl)); if (certificateUrl) {
} obj.set('CertificateUrl', getPresignedUrl(certificateUrl));
}
return [obj]; return [obj];
}
} }
} }
} }
@@ -1,14 +1,17 @@
import { useLocal } from '../../Utils.js';
import getPresignedUrl from './getSignedUrl.js'; import getPresignedUrl from './getSignedUrl.js';
async function TenantAterFind(request) { async function TenantAterFind(request) {
if (request.objects.length === 1) { if (useLocal !== 'true') {
if (request.objects) { if (request.objects.length === 1) {
const obj = request.objects[0]; if (request.objects) {
const Logo = obj?.get('Logo') && obj?.get('Logo'); const obj = request.objects[0];
if (Logo) { const Logo = obj?.get('Logo') && obj?.get('Logo');
obj.set('Logo', getPresignedUrl(Logo)); if (Logo) {
obj.set('Logo', getPresignedUrl(Logo));
}
return [obj];
} }
return [obj];
} }
} }
} }
@@ -1,16 +1,17 @@
import { useLocal } from '../../Utils.js';
import getPresignedUrl from './getSignedUrl.js'; import getPresignedUrl from './getSignedUrl.js';
async function UserAfterFind(request) { async function UserAfterFind(request) {
if (request.objects.length === 1) { if (useLocal !== 'true') {
if (request.objects) { if (request.objects.length === 1) {
const obj = request.objects[0]; if (request.objects) {
const ProfilePic = obj?.get('ProfilePic') && obj?.get('ProfilePic'); const obj = request.objects[0];
const ProfilePic = obj?.get('ProfilePic') && obj?.get('ProfilePic');
if (ProfilePic) { if (ProfilePic) {
obj.set('ProfilePic', getPresignedUrl(ProfilePic)); obj.set('ProfilePic', getPresignedUrl(ProfilePic));
}
return [obj];
} }
return [obj];
} }
} }
} }
+4 -6
View File
@@ -1,9 +1,5 @@
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
import dotenv from 'dotenv'; import dotenv from 'dotenv';
dotenv.config(); dotenv.config();
import express from 'express'; import express from 'express';
import cors from 'cors'; import cors from 'cors';
import { ParseServer } from 'parse-server'; import { ParseServer } from 'parse-server';
@@ -21,9 +17,10 @@ import { exec } from 'child_process';
import { createTransport } from 'nodemailer'; import { createTransport } from 'nodemailer';
import { app as v1 } from './cloud/customRoute/v1/apiV1.js'; import { app as v1 } from './cloud/customRoute/v1/apiV1.js';
import { PostHog } from 'posthog-node'; import { PostHog } from 'posthog-node';
// console.log("configuration ", configuration); import { useLocal } from './Utils.js';
let fsAdapter; let fsAdapter;
if (process.env.USE_LOCAL !== 'TRUE') { if (useLocal !== 'true') {
try { try {
const spacesEndpoint = new AWS.Endpoint(process.env.DO_ENDPOINT); const spacesEndpoint = new AWS.Endpoint(process.env.DO_ENDPOINT);
const s3Options = { const s3Options = {
@@ -98,6 +95,7 @@ export const config = {
import('./cloud/main.js'); import('./cloud/main.js');
}, },
appId: process.env.APP_ID || 'myAppId', appId: process.env.APP_ID || 'myAppId',
logLevel: ['error'],
maxLimit: 500, maxLimit: 500,
maxUploadSize: '30mb', maxUploadSize: '30mb',
masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret! masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret!