diff --git a/apps/OpenSignServer/Utils.js b/apps/OpenSignServer/Utils.js index 18d90138b..038f66aec 100644 --- a/apps/OpenSignServer/Utils.js +++ b/apps/OpenSignServer/Utils.js @@ -1,4 +1,6 @@ import axios from 'axios'; +import dotenv from 'dotenv'; +dotenv.config(); const appId = process.env.APP_ID; const serverUrl = process.env.SERVER_URL; @@ -243,3 +245,5 @@ export function sanitizeFileName(fileName) { const removedot = file.replace(/\.(?=.*\.)/g, ''); return removedot.replace(/[^a-zA-Z0-9._-]/g, ''); } + +export const useLocal = process.env.USE_LOCAL ? process.env.USE_LOCAL.toLowerCase() : 'false'; diff --git a/apps/OpenSignServer/cloud/customRoute/uploadFile.js b/apps/OpenSignServer/cloud/customRoute/uploadFile.js index 352f7711b..dd1e681a2 100644 --- a/apps/OpenSignServer/cloud/customRoute/uploadFile.js +++ b/apps/OpenSignServer/cloud/customRoute/uploadFile.js @@ -3,6 +3,7 @@ import multer from 'multer'; import multerS3 from 'multer-s3'; import aws from 'aws-sdk'; import dotenv from 'dotenv'; +import { useLocal } from '../../Utils.js'; dotenv.config(); function sanitizeFileName(fileName) { @@ -51,7 +52,7 @@ async function uploadFile(req, res) { const parseBaseUrl = process.env.SERVER_URL; const parseAppId = process.env.APP_ID; let fileStorage; - if (process.env.USE_LOCAL == 'TRUE') { + if (useLocal === 'true') { fileStorage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'files/files'); @@ -147,7 +148,7 @@ async function uploadFile(req, res) { const status = 'Success'; //res.header("Access-Control-Allow-Headers", "Content-Type"); //res.setHeader("Access-Control-Allow-Origin", "*"); - if (process.env.USE_LOCAL == 'TRUE') { + if (useLocal === 'true') { console.log(req.file); var fileUrl = `${parseBaseUrl}/files/${parseAppId}/${req.file.filename}`; } else { diff --git a/apps/OpenSignServer/cloud/parsefunction/DocumentAfterFind.js b/apps/OpenSignServer/cloud/parsefunction/DocumentAfterFind.js index f913b1e66..b38611320 100644 --- a/apps/OpenSignServer/cloud/parsefunction/DocumentAfterFind.js +++ b/apps/OpenSignServer/cloud/parsefunction/DocumentAfterFind.js @@ -1,22 +1,24 @@ +import { useLocal } from '../../Utils.js'; import getPresignedUrl from './getSignedUrl.js'; async function DocumentAfterFind(request) { - if (request.objects.length === 1) { - if (request.objects) { - const obj = request.objects[0]; - const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl'); - const Url = obj?.get('URL') && obj?.get('URL'); - const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl'); - if (SignedUrl) { - obj.set('SignedUrl', getPresignedUrl(SignedUrl)); + if (useLocal !== 'true') { + if (request.objects.length === 1) { + if (request.objects) { + const obj = request.objects[0]; + const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl'); + const Url = obj?.get('URL') && obj?.get('URL'); + const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl'); + 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]; } } diff --git a/apps/OpenSignServer/cloud/parsefunction/SignatureAfterFind.js b/apps/OpenSignServer/cloud/parsefunction/SignatureAfterFind.js index 45ca5a8b5..1d1174324 100644 --- a/apps/OpenSignServer/cloud/parsefunction/SignatureAfterFind.js +++ b/apps/OpenSignServer/cloud/parsefunction/SignatureAfterFind.js @@ -1,21 +1,21 @@ +import { useLocal } from '../../Utils.js'; import getPresignedUrl from './getSignedUrl.js'; async function SignatureAfterFind(request) { - if (request.objects.length === 1) { - if (request.objects) { - const obj = request.objects[0]; - const ImageURL = obj?.get('ImageURL') && obj?.get('ImageURL'); - const Initials = obj?.get('Initials') && obj?.get('Initials'); - - if (ImageURL) { - obj.set('ImageURL', getPresignedUrl(ImageURL)); + if (useLocal !== 'true') { + if (request.objects.length === 1) { + if (request.objects) { + const obj = request.objects[0]; + const ImageURL = obj?.get('ImageURL') && obj?.get('ImageURL'); + const Initials = obj?.get('Initials') && obj?.get('Initials'); + if (ImageURL) { + obj.set('ImageURL', getPresignedUrl(ImageURL)); + } + if (Initials) { + obj.set('Initials', getPresignedUrl(Initials)); + } + return [obj]; } - - if (Initials) { - obj.set('Initials', getPresignedUrl(Initials)); - } - - return [obj]; } } } diff --git a/apps/OpenSignServer/cloud/parsefunction/TemplateAfterFind.js b/apps/OpenSignServer/cloud/parsefunction/TemplateAfterFind.js index 10f730669..6fab363c8 100644 --- a/apps/OpenSignServer/cloud/parsefunction/TemplateAfterFind.js +++ b/apps/OpenSignServer/cloud/parsefunction/TemplateAfterFind.js @@ -1,23 +1,26 @@ +import { useLocal } from '../../Utils.js'; import getPresignedUrl from './getSignedUrl.js'; async function TemplateAfterFind(request) { - if (request.objects.length === 1) { - if (request.objects) { - const obj = request.objects[0]; - const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl'); - const Url = obj?.get('URL') && obj?.get('URL'); - const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl'); - if (SignedUrl) { - obj.set('SignedUrl', getPresignedUrl(SignedUrl)); - } - if (Url) { - obj.set('URL', getPresignedUrl(Url)); - } - if (certificateUrl) { - obj.set('CertificateUrl', getPresignedUrl(certificateUrl)); - } + if (useLocal !== 'true') { + if (request.objects.length === 1) { + if (request.objects) { + const obj = request.objects[0]; + const SignedUrl = obj?.get('SignedUrl') && obj?.get('SignedUrl'); + const Url = obj?.get('URL') && obj?.get('URL'); + const certificateUrl = obj.get('CertificateUrl') && obj.get('CertificateUrl'); + if (SignedUrl) { + obj.set('SignedUrl', getPresignedUrl(SignedUrl)); + } + if (Url) { + obj.set('URL', getPresignedUrl(Url)); + } + if (certificateUrl) { + obj.set('CertificateUrl', getPresignedUrl(certificateUrl)); + } - return [obj]; + return [obj]; + } } } } diff --git a/apps/OpenSignServer/cloud/parsefunction/TenantAfterFind.js b/apps/OpenSignServer/cloud/parsefunction/TenantAfterFind.js index 2af96c4d5..bb520928f 100644 --- a/apps/OpenSignServer/cloud/parsefunction/TenantAfterFind.js +++ b/apps/OpenSignServer/cloud/parsefunction/TenantAfterFind.js @@ -1,14 +1,17 @@ +import { useLocal } from '../../Utils.js'; import getPresignedUrl from './getSignedUrl.js'; async function TenantAterFind(request) { - if (request.objects.length === 1) { - if (request.objects) { - const obj = request.objects[0]; - const Logo = obj?.get('Logo') && obj?.get('Logo'); - if (Logo) { - obj.set('Logo', getPresignedUrl(Logo)); + if (useLocal !== 'true') { + if (request.objects.length === 1) { + if (request.objects) { + const obj = request.objects[0]; + const Logo = obj?.get('Logo') && obj?.get('Logo'); + if (Logo) { + obj.set('Logo', getPresignedUrl(Logo)); + } + return [obj]; } - return [obj]; } } } diff --git a/apps/OpenSignServer/cloud/parsefunction/UserAfterFInd.js b/apps/OpenSignServer/cloud/parsefunction/UserAfterFInd.js index b27d2d272..5a414e1ac 100644 --- a/apps/OpenSignServer/cloud/parsefunction/UserAfterFInd.js +++ b/apps/OpenSignServer/cloud/parsefunction/UserAfterFInd.js @@ -1,16 +1,17 @@ +import { useLocal } from '../../Utils.js'; import getPresignedUrl from './getSignedUrl.js'; async function UserAfterFind(request) { - if (request.objects.length === 1) { - if (request.objects) { - const obj = request.objects[0]; - const ProfilePic = obj?.get('ProfilePic') && obj?.get('ProfilePic'); - - if (ProfilePic) { - obj.set('ProfilePic', getPresignedUrl(ProfilePic)); + if (useLocal !== 'true') { + if (request.objects.length === 1) { + if (request.objects) { + const obj = request.objects[0]; + const ProfilePic = obj?.get('ProfilePic') && obj?.get('ProfilePic'); + if (ProfilePic) { + obj.set('ProfilePic', getPresignedUrl(ProfilePic)); + } + return [obj]; } - - return [obj]; } } } diff --git a/apps/OpenSignServer/index.js b/apps/OpenSignServer/index.js index 43a4bd591..a9432da6b 100644 --- a/apps/OpenSignServer/index.js +++ b/apps/OpenSignServer/index.js @@ -1,9 +1,5 @@ -// Example express application adding the parse-server module to expose Parse -// compatible API routes. - import dotenv from 'dotenv'; dotenv.config(); - import express from 'express'; import cors from 'cors'; import { ParseServer } from 'parse-server'; @@ -21,9 +17,10 @@ import { exec } from 'child_process'; import { createTransport } from 'nodemailer'; import { app as v1 } from './cloud/customRoute/v1/apiV1.js'; import { PostHog } from 'posthog-node'; -// console.log("configuration ", configuration); +import { useLocal } from './Utils.js'; + let fsAdapter; -if (process.env.USE_LOCAL !== 'TRUE') { +if (useLocal !== 'true') { try { const spacesEndpoint = new AWS.Endpoint(process.env.DO_ENDPOINT); const s3Options = { @@ -98,6 +95,7 @@ export const config = { import('./cloud/main.js'); }, appId: process.env.APP_ID || 'myAppId', + logLevel: ['error'], maxLimit: 500, maxUploadSize: '30mb', masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret!