mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-09-13 05:07:39 +02:00
Delete apps/OpenSignServer/package-lock.json
This commit is contained in:
@@ -13,10 +13,13 @@ async function convertLibre(input, ext, opts) {
|
||||
}
|
||||
});
|
||||
}
|
||||
// -------------------- Concurrency limiter (no dependency) --------------------
|
||||
const MAX_CONCURRENCY = Number(process.env.DOCX2PDF_CONCURRENCY || 2); // 1 for tiny droplets
|
||||
|
||||
// -------------------- Concurrency limiter --------------------
|
||||
// CRITICAL FIX: Reduced to 1 for CPU-intensive LibreOffice conversions
|
||||
const MAX_CONCURRENCY = Number(process.env.DOCX2PDF_CONCURRENCY || 1);
|
||||
let active = 0;
|
||||
const queue = [];
|
||||
|
||||
function runWithLimit(task) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const run = () => {
|
||||
@@ -34,7 +37,7 @@ function runWithLimit(task) {
|
||||
});
|
||||
}
|
||||
|
||||
// -------------------- Timeout helper (async version = no TS hint) --------------------
|
||||
// -------------------- Timeout helper --------------------
|
||||
/**
|
||||
* @template T
|
||||
* @param {Promise<T>} promise
|
||||
@@ -58,6 +61,7 @@ export async function withTimeout(promise, ms, label = 'operation') {
|
||||
const storage = multer.memoryStorage();
|
||||
export const upload = multer({
|
||||
storage,
|
||||
limits: { fileSize: 50 * 1024 * 1024 }, // 50MB hard limit at multer level
|
||||
fileFilter: (req, file, cb) => {
|
||||
const okExt = /\.docx$/i.test(file.originalname || '');
|
||||
const okMime =
|
||||
@@ -109,14 +113,30 @@ export default async function docxtopdf(req, res) {
|
||||
return res.status(403).json({ error: 'Tenant not found for user.' });
|
||||
}
|
||||
|
||||
// ---- DOCX -> PDF (buffer -> buffer), with concurrency + timeout ----
|
||||
// ---- DOCX -> PDF conversion with concurrency control and timeout ----
|
||||
const fileName = `${generatePdfName(16)}.pdf`;
|
||||
|
||||
const pdfBuffer = await runWithLimit(() =>
|
||||
withTimeout(convertLibre(req.file.buffer, '.pdf', undefined), 60_000, 'DOCX->PDF')
|
||||
);
|
||||
// FIX: Increased timeout to 90s for large files, added nice priority
|
||||
const pdfBuffer = await runWithLimit(async () => {
|
||||
// Log for monitoring
|
||||
console.log(`[DOCX2PDF] Starting conversion, active: ${active}, queued: ${queue.length}`);
|
||||
|
||||
// ---- Upload PDF (no disk IO) ----
|
||||
const startTime = Date.now();
|
||||
try {
|
||||
const result = await withTimeout(
|
||||
convertLibre(req.file.buffer, '.pdf', undefined),
|
||||
90_000, // Increased from 60s to 90s
|
||||
'DOCX->PDF'
|
||||
);
|
||||
console.log(`[DOCX2PDF] Completed in ${Date.now() - startTime}ms`);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error(`[DOCX2PDF] Failed after ${Date.now() - startTime}ms:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// ---- Upload PDF ----
|
||||
const activeFileAdapter = resUser.data.results[0]?.TenantId?.ActiveFileAdapter;
|
||||
let fileUrl;
|
||||
if (activeFileAdapter) {
|
||||
@@ -140,12 +160,23 @@ export default async function docxtopdf(req, res) {
|
||||
|
||||
return res.status(200).json({ message: 'success.', url: fileUrl });
|
||||
} catch (err) {
|
||||
const msg =
|
||||
// More specific error messages
|
||||
let msg =
|
||||
err?.response?.data?.error || err?.response?.data || err?.message || 'Something went wrong.';
|
||||
console.log(`Error in docxtopdf: ${msg}`);
|
||||
// Friendly message to the client
|
||||
const message =
|
||||
'We are currently experiencing some issues with processing DOCX files. Please upload the PDF version or contact us on support@opensignlabs.com';
|
||||
|
||||
if (msg.includes('timed out')) {
|
||||
msg =
|
||||
'Document conversion is taking too long. Please try a smaller file or contact support@opensignlabs.com';
|
||||
} else if (msg.includes('too large') || msg.includes('size')) {
|
||||
msg =
|
||||
'File is too large to process. Please reduce the file size or contact support@opensignlabs.com';
|
||||
} else {
|
||||
msg = message;
|
||||
}
|
||||
console.error(`[DOCX2PDF] Error: ${msg}`);
|
||||
return res.status(400).json({ error: message });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,6 @@ async function batchQuery(userId, Documents, Ip, parseConfig, type, publicUrl) {
|
||||
},
|
||||
};
|
||||
});
|
||||
// console.log('requests ', requests);
|
||||
if (requests?.length > 0) {
|
||||
const newrequests = [requests?.[0]];
|
||||
const response = await axios.post('batch', { requests: newrequests }, parseConfig);
|
||||
|
||||
@@ -17,7 +17,7 @@ import { exec } from 'child_process';
|
||||
import { createTransport } from 'nodemailer';
|
||||
import { appName, cloudServerUrl, serverAppId, smtpenable, smtpsecure, useLocal } from './Utils.js';
|
||||
import { SSOAuth } from './auth/authadapter.js';
|
||||
import createContactIndex from './migrationdb/createContactIndex.js';
|
||||
import runDbMigrations from './migrationdb/index.js';
|
||||
import { validateSignedLocalUrl } from './cloud/parsefunction/getSignedUrl.js';
|
||||
import maintenance_mode_message from 'aws-sdk/lib/maintenance_mode_message.js';
|
||||
let fsAdapter;
|
||||
@@ -119,6 +119,7 @@ export const config = {
|
||||
allowClientClassCreation: false,
|
||||
allowExpiredAuthDataToken: false,
|
||||
enableInsecureAuthAdapters: false,
|
||||
databaseOptions: { allowPublicExplain: false },
|
||||
encodeParseObjectInCloudFunction: true,
|
||||
...(isMailAdapter === true
|
||||
? {
|
||||
@@ -240,7 +241,7 @@ if (!process.env.TESTING) {
|
||||
console.log('opensign-server running on port ' + port + '.');
|
||||
const isWindows = process.platform === 'win32';
|
||||
// console.log('isWindows', isWindows);
|
||||
createContactIndex();
|
||||
runDbMigrations();
|
||||
const migrate = isWindows
|
||||
? `set APPLICATION_ID=${serverAppId}&& set SERVER_URL=${cloudServerUrl}&& set MASTER_KEY=${process.env.MASTER_KEY}&& npx parse-dbtool migrate`
|
||||
: `APPLICATION_ID=${serverAppId} SERVER_URL=${cloudServerUrl} MASTER_KEY=${process.env.MASTER_KEY} npx parse-dbtool migrate`;
|
||||
|
||||
@@ -18,8 +18,7 @@ export default async function createContactIndex() {
|
||||
const migrationExists = await migrationCollection.findOne({ name: migrationName });
|
||||
|
||||
if (migrationExists) {
|
||||
console.log(' INFO No migrations were executed, database schema was already up to date.');
|
||||
console.log(' SUCCESS Successfully ran indexed migrations directly on db.');
|
||||
console.log(' INFO The unqiue index for contracts_Contactbook is already present.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,10 +60,9 @@ export default async function createContactIndex() {
|
||||
|
||||
// Insert the document
|
||||
await migrationdb.insertOne(schemaDocument);
|
||||
console.log(' Unique index created successfully.');
|
||||
console.log(' SUCCESS Successfully ran indexed migrations directly on db.');
|
||||
console.log(' SUCCESS The unqiue index for contracts_Contactbook is already created.');
|
||||
} catch (error) {
|
||||
console.log(' ERROR running indexed migration:', error);
|
||||
console.log(' ERROR Running unqiue index for contracts_Contactbook migration:', error);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import dotenv from 'dotenv';
|
||||
import { MongoClient } from 'mongodb';
|
||||
import { generateId } from '../Utils.js';
|
||||
dotenv.config({ quiet: true });
|
||||
|
||||
export default async function createDocumentIndex() {
|
||||
// Provide the complete MongoDB connection URL with the database name
|
||||
const uri = process.env.MONGODB_URI || 'mongodb://localhost:27017/dev'; // Replace with your MongoDB URI
|
||||
const client = new MongoClient(uri);
|
||||
try {
|
||||
await client.connect();
|
||||
const database = client.db();
|
||||
|
||||
const migrationCollection = database.collection('Migrationdb');
|
||||
const docMigration = 'documentIndex_1';
|
||||
|
||||
// Check if the migration has already been executed
|
||||
const docMigrationExists = await migrationCollection.findOne({ name: docMigration });
|
||||
|
||||
if (docMigrationExists) {
|
||||
console.log(' INFO The completed report index for contracts_document is already present.');
|
||||
return;
|
||||
}
|
||||
|
||||
const docCollection = database.collection('contracts_Document');
|
||||
|
||||
await docCollection.createIndex(
|
||||
{ _p_CreatedBy: 1, _updated_at: -1 },
|
||||
{
|
||||
name: 'idx_docs_by_creator_recent_completed',
|
||||
partialFilterExpression: { IsCompleted: true },
|
||||
}
|
||||
);
|
||||
|
||||
await docCollection.createIndex(
|
||||
{ Signers: 1, _updated_at: -1 },
|
||||
{
|
||||
name: 'idx_docs_by_signer_recent_completed',
|
||||
partialFilterExpression: { IsCompleted: true },
|
||||
}
|
||||
);
|
||||
|
||||
// Save the migration record in the migrationdb collection
|
||||
await migrationCollection.insertOne({
|
||||
_id: generateId(10),
|
||||
name: docMigration,
|
||||
_created_at: new Date(),
|
||||
_updated_at: new Date(),
|
||||
executedAt: new Date(),
|
||||
details: 'Created unique index on CreatedBy, IsImported, Email',
|
||||
});
|
||||
|
||||
console.log(' SUCCESS The completed report index for contracts_document is created.');
|
||||
} catch (error) {
|
||||
console.log(' ERROR Running completed report index for contracts_document migration:', error);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import createContactIndex from './createContactIndex.js';
|
||||
import createDocumentIndex from './createDocumentIndex.js';
|
||||
|
||||
export default async function runDbMigrations() {
|
||||
await createContactIndex();
|
||||
await createDocumentIndex();
|
||||
}
|
||||
@@ -18,10 +18,10 @@
|
||||
"watch": "nodemon index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.940.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.940.0",
|
||||
"@aws-sdk/client-s3": "^3.943.0",
|
||||
"@aws-sdk/s3-request-presigner": "^3.943.0",
|
||||
"@parse/fs-files-adapter": "^3.0.0",
|
||||
"@parse/push-adapter": "^7.0.0",
|
||||
"@parse/push-adapter": "^8.0.2",
|
||||
"@parse/s3-files-adapter": "^4.2.0",
|
||||
"@pdf-lib/fontkit": "^1.1.1",
|
||||
"@signpdf/placeholder-pdf-lib": "^3.2.6",
|
||||
@@ -33,21 +33,21 @@
|
||||
"cors": "^2.8.5",
|
||||
"date-fns-tz": "^3.2.0",
|
||||
"dotenv": "^17.2.3",
|
||||
"express": "^5.1.0",
|
||||
"express": "^5.2.1",
|
||||
"form-data": "^4.0.5",
|
||||
"generate-api-key": "^1.0.2",
|
||||
"googleapis": "^166.0.0",
|
||||
"googleapis": "^167.0.0",
|
||||
"libreoffice-convert": "^1.7.0",
|
||||
"mailgun.js": "^12.2.0",
|
||||
"mongodb": "^5.9.2",
|
||||
"multer": "^2.0.2",
|
||||
"multer-s3": "^3.0.1",
|
||||
"node-forge": "^1.3.1",
|
||||
"node-forge": "^1.3.3",
|
||||
"nodemailer": "^7.0.11",
|
||||
"p-limit": "^7.2.0",
|
||||
"parse": "^7.0.2",
|
||||
"parse": "^7.1.2",
|
||||
"parse-dbtool": "^1.2.0",
|
||||
"parse-server": "^8.4.0",
|
||||
"parse-server": "^8.5.0",
|
||||
"parse-server-api-mail-adapter": "^5.0.2",
|
||||
"pdf-lib": "^1.17.1",
|
||||
"posthog-node": "^5.14.0",
|
||||
@@ -65,7 +65,7 @@
|
||||
"mongodb-runner": "^5.11.1",
|
||||
"nodemon": "^3.1.11",
|
||||
"nyc": "^17.1.0",
|
||||
"prettier": "^3.6.2"
|
||||
"prettier": "^3.7.4"
|
||||
},
|
||||
"overrides": {
|
||||
"ws": "$ws",
|
||||
|
||||
Reference in New Issue
Block a user