mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-31 04:09:46 +02:00
v2.29.0
This commit is contained in:
@@ -3,6 +3,7 @@ import { format, toZonedTime } from 'date-fns-tz';
|
||||
import getPresignedUrl, { getSignedLocalUrl } from './cloud/parsefunction/getSignedUrl.js';
|
||||
import crypto from 'node:crypto';
|
||||
import { PDFDocument, rgb } from 'pdf-lib';
|
||||
import { parseUploadFile } from './utils/fileUtils.js';
|
||||
|
||||
dotenv.config({ quiet: true });
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ export const app = express();
|
||||
|
||||
dotenv.config({ quiet: true });
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
app.use(express.urlencoded({ limit: '50mb', extended: true }));
|
||||
app.use(express.json({ limit: '100mb' }));
|
||||
app.use(express.urlencoded({ limit: '100mb', extended: true }));
|
||||
|
||||
app.post('/file_upload', uploadFile);
|
||||
app.post('/docxtopdf', docxUpload.single('file'), docxtopdf);
|
||||
|
||||
@@ -7,6 +7,7 @@ import fs from 'node:fs';
|
||||
import dotenv from 'dotenv';
|
||||
import GenerateCertificate from './pdf/GenerateCertificate.js';
|
||||
import { getSecureUrl } from '../../Utils.js';
|
||||
import { parseUploadFile } from '../../utils/fileUtils.js';
|
||||
dotenv.config({ quiet: true });
|
||||
const eSignName = 'OpenSign';
|
||||
const eSigncontact = 'hello@opensignlabs.com';
|
||||
@@ -16,10 +17,14 @@ async function uploadFile(pdfName, filepath) {
|
||||
try {
|
||||
const filedata = fs.readFileSync(filepath);
|
||||
let fileUrl;
|
||||
const file = new Parse.File(pdfName, [...filedata], 'application/pdf');
|
||||
await file.save({ useMasterKey: true });
|
||||
const fileRes = getSecureUrl(file.url());
|
||||
fileUrl = fileRes.url;
|
||||
|
||||
// const file = new Parse.File(pdfName, [...filedata], 'application/pdf');
|
||||
// await file.save({ useMasterKey: true });
|
||||
// const fileRes = getSecureUrl(file.url());
|
||||
// fileUrl = fileRes.url;
|
||||
|
||||
const fileRes = await parseUploadFile(pdfName, filedata, 'application/pdf');
|
||||
fileUrl = getSecureUrl(fileRes?.url)?.url;
|
||||
return { imageUrl: fileUrl };
|
||||
} catch (err) {
|
||||
console.log('Err ', err);
|
||||
@@ -52,7 +57,9 @@ export default async function generateCertificatebydocId(req) {
|
||||
const certificatePath = `./exports/certificate_${docId}.pdf`;
|
||||
try {
|
||||
const getDocument = new Parse.Query('contracts_Document');
|
||||
getDocument.include('ExtUserPtr,Signers,AuditTrail.UserPtr,Placeholders,ExtUserPtr.TenantId');
|
||||
getDocument.include(
|
||||
'ExtUserPtr,Signers,AuditTrail.UserPtr,Placeholders,ExtUserPtr.TenantId,ExtUserPtr.UserId'
|
||||
);
|
||||
const docRes = await getDocument.get(docId, { useMasterKey: true });
|
||||
|
||||
if (docRes && docRes?.get('IsCompleted') && !docRes?.get('CertificateUrl')) {
|
||||
|
||||
@@ -20,22 +20,23 @@ async function getTenantByUserId(userId, contactId) {
|
||||
}
|
||||
} else {
|
||||
const query = new Parse.Query('contracts_Users');
|
||||
query.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: userId,
|
||||
});
|
||||
query.equalTo('UserId', { __type: 'Pointer', className: '_User', objectId: userId });
|
||||
const extuser = await query.first({ useMasterKey: true });
|
||||
if (extuser) {
|
||||
const tenantId = extuser?.get('TenantId')?.id || '';
|
||||
const user = extuser?.get('CreatedBy')?.id || userId;
|
||||
const tenantCreditsQuery = new Parse.Query('partners_Tenant');
|
||||
tenantCreditsQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: user,
|
||||
});
|
||||
tenantCreditsQuery.exclude('FileAdapters,PfxFile');
|
||||
const res = await tenantCreditsQuery.first({ useMasterKey: true });
|
||||
const tenantQuery = new Parse.Query('partners_Tenant');
|
||||
if (tenantId) {
|
||||
tenantQuery.equalTo('objectId', tenantId);
|
||||
} else {
|
||||
tenantQuery.equalTo('UserId', {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: user,
|
||||
});
|
||||
}
|
||||
tenantQuery.exclude('FileAdapters,PfxFile');
|
||||
const res = await tenantQuery.first({ useMasterKey: true });
|
||||
return res;
|
||||
} else {
|
||||
return {};
|
||||
|
||||
@@ -14,7 +14,7 @@ import { pdflibAddPlaceholder } from '@signpdf/placeholder-pdf-lib';
|
||||
import { Placeholder } from './Placeholder.js';
|
||||
import { SignPdf } from '@signpdf/signpdf';
|
||||
import { P12Signer } from '@signpdf/signer-p12';
|
||||
import { buildDownloadFilename } from '../../../utils/fileUtils.js';
|
||||
import { buildDownloadFilename, parseUploadFile } from '../../../utils/fileUtils.js';
|
||||
|
||||
const serverUrl = cloudServerUrl; // process.env.SERVER_URL;
|
||||
const APPID = serverAppId;
|
||||
@@ -43,10 +43,14 @@ async function uploadFile(pdfName, filepath) {
|
||||
try {
|
||||
const filedata = fs.readFileSync(filepath);
|
||||
let fileUrl;
|
||||
const file = new Parse.File(pdfName, [...filedata], 'application/pdf');
|
||||
await file.save({ useMasterKey: true });
|
||||
const fileRes = getSecureUrl(file.url());
|
||||
fileUrl = fileRes.url;
|
||||
|
||||
// const file = new Parse.File(pdfName, [...filedata], 'application/pdf');
|
||||
// await file.save({ useMasterKey: true });
|
||||
// const fileRes = getSecureUrl(file.url());
|
||||
// fileUrl = fileRes.url;
|
||||
|
||||
const fileRes = await parseUploadFile(pdfName, filedata, 'application/pdf');
|
||||
fileUrl = getSecureUrl(fileRes?.url)?.url;
|
||||
|
||||
return { imageUrl: fileUrl };
|
||||
} catch (err) {
|
||||
@@ -350,7 +354,7 @@ async function PDF(req) {
|
||||
const publicUrl = req.headers.public_url;
|
||||
// below bode is used to get info of docId
|
||||
const docQuery = new Parse.Query('contracts_Document');
|
||||
docQuery.include('ExtUserPtr,Signers,ExtUserPtr.TenantId,Bcc');
|
||||
docQuery.include('ExtUserPtr,Signers,ExtUserPtr.TenantId,Bcc,CreatedBy');
|
||||
docQuery.equalTo('objectId', docId);
|
||||
const resDoc = await docQuery.first({ useMasterKey: true });
|
||||
if (!resDoc) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { flattenPdf, getSecureUrl } from '../../Utils.js';
|
||||
import { parseUploadFile } from '../../utils/fileUtils.js';
|
||||
|
||||
export default async function saveFile(request) {
|
||||
if (!request.params.fileBase64) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Please provide file.');
|
||||
@@ -10,6 +12,7 @@ export default async function saveFile(request) {
|
||||
const extCls = new Parse.Query('contracts_Users');
|
||||
extCls.equalTo('UserId', request.user);
|
||||
extCls.include('TenantId');
|
||||
extCls.include('UserId');
|
||||
const resExt = await extCls.first({ useMasterKey: true });
|
||||
if (resExt) {
|
||||
const _resExt = JSON.parse(JSON.stringify(resExt));
|
||||
@@ -20,17 +23,26 @@ export default async function saveFile(request) {
|
||||
if (ext === 'pdf') {
|
||||
mimeType = 'application/pdf';
|
||||
const flatPdf = await flattenPdf(fileBase64);
|
||||
file = [...flatPdf];
|
||||
// file = [...flatPdf];
|
||||
file = flatPdf;
|
||||
} else if (ext === 'png' || ext === 'jpeg' || ext === 'jpg') {
|
||||
mimeType = `image/${ext}`;
|
||||
file = { base64: fileBase64 };
|
||||
// file = { base64: fileBase64 };
|
||||
file = Buffer.from(fileBase64, 'base64');
|
||||
}
|
||||
// const pdfFile = new Parse.File(fileName, file, mimeType);
|
||||
// // Save the Parse File if needed
|
||||
// const pdfData = await pdfFile.save({ useMasterKey: true });
|
||||
// const presignedUrl = pdfData.url();
|
||||
// const fileRes = getSecureUrl(presignedUrl);
|
||||
// return { url: fileRes.url };
|
||||
try {
|
||||
const fileRes = await parseUploadFile(fileName, file, mimeType);
|
||||
fileUrl = getSecureUrl(fileRes?.url)?.url;
|
||||
return { url: fileUrl };
|
||||
} catch (err) {
|
||||
throw new Parse.Error(400, err?.message);
|
||||
}
|
||||
const pdfFile = new Parse.File(fileName, file, mimeType);
|
||||
// Save the Parse File if needed
|
||||
const pdfData = await pdfFile.save({ useMasterKey: true });
|
||||
const presignedUrl = pdfData.url();
|
||||
const fileRes = getSecureUrl(presignedUrl);
|
||||
return { url: fileRes.url };
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User not found.');
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ export const config = {
|
||||
appId: serverAppId,
|
||||
logLevel: ['error'],
|
||||
maxLimit: 500,
|
||||
maxUploadSize: '30mb',
|
||||
maxUploadSize: '100mb',
|
||||
masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret!
|
||||
masterKeyIps: ['0.0.0.0/0', '::/0'], // '::1'
|
||||
serverURL: cloudServerUrl, // Don't forget to change to https if needed
|
||||
@@ -156,8 +156,8 @@ export const config = {
|
||||
|
||||
export const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
app.use(express.urlencoded({ limit: '50mb', extended: true }));
|
||||
app.use(express.json({ limit: '100mb' }));
|
||||
app.use(express.urlencoded({ limit: '100mb', extended: true }));
|
||||
app.use(function (req, res, next) {
|
||||
req.headers['x-real-ip'] = getUserIP(req);
|
||||
const publicUrl = 'https://' + req?.get('host');
|
||||
|
||||
Generated
+678
-686
File diff suppressed because it is too large
Load Diff
@@ -18,8 +18,8 @@
|
||||
"watch": "nodemon index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.888.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.888.0",
|
||||
"@aws-sdk/client-s3": "^3.891.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.891.0",
|
||||
"@parse/fs-files-adapter": "^3.0.0",
|
||||
"@parse/s3-files-adapter": "^4.2.0",
|
||||
"@pdf-lib/fontkit": "^1.1.1",
|
||||
@@ -52,7 +52,7 @@
|
||||
"posthog-node": "^5.8.4",
|
||||
"qrcode": "^1.5.4",
|
||||
"rate-limiter-flexible": "^7.3.1",
|
||||
"sharp": "^0.34.3",
|
||||
"sharp": "^0.34.4",
|
||||
"speakeasy": "^2.0.0",
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { cloudServerUrl, serverAppId } from '../Utils.js';
|
||||
|
||||
function formatFixedDate(date = new Date()) {
|
||||
const dd = String(date.getDate()).padStart(2, '0');
|
||||
const months = [
|
||||
@@ -75,3 +78,23 @@ export function buildDownloadFilename(formatId, ctx) {
|
||||
const safeExt = ext.replace(/\.+/g, '').toLowerCase() || 'pdf';
|
||||
return `${stem}.${safeExt}`;
|
||||
}
|
||||
|
||||
export async function parseUploadFile(fileName, fileData, mimeType) {
|
||||
try {
|
||||
const res = await axios.post(`${cloudServerUrl}/files/${fileName}`, fileData, {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': serverAppId,
|
||||
'X-Parse-Master-Key': process.env.MASTER_KEY,
|
||||
'Content-Type': mimeType,
|
||||
},
|
||||
});
|
||||
|
||||
// console.log('File uploaded:', res.data);
|
||||
return res.data;
|
||||
} catch (err) {
|
||||
const errorMessage = err?.response?.data?.error || 'Unknown error';
|
||||
const statusCode = err?.response?.status || 500;
|
||||
console.log('Err in parseUploadFile', errorMessage);
|
||||
throw { message: errorMessage, code: statusCode };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user