mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
fix: issue of request payload entity too large
This commit is contained in:
+20
-22
@@ -1,21 +1,18 @@
|
||||
import SignPDF from './SignPDF.min.cjs';
|
||||
import fs from 'node:fs';
|
||||
import axios from 'axios';
|
||||
import FormData from 'form-data';
|
||||
import { plainAddPlaceholder } from 'node-signpdf/dist/helpers/index.js';
|
||||
const serverUrl = process.env.SERVER_URL,
|
||||
APPID = process.env.APP_ID,
|
||||
masterKEY = process.env.MASTER_KEY;
|
||||
async function uploadFile(a) {
|
||||
async function uploadFile(e, a) {
|
||||
try {
|
||||
var e = new FormData(),
|
||||
t =
|
||||
(e.append('file', fs.createReadStream(a)),
|
||||
{ 'content-type': 'multipart/form-data', 'X-Parse-Application-Id': process.env.APP_ID }),
|
||||
s = process.env.SERVER_URL.slice(0, -4) + '/file_upload';
|
||||
return (await axios.post(s, e, { headers: t })).data;
|
||||
var t = fs.readFileSync(a),
|
||||
s = new Parse.File(e, [...t]),
|
||||
r = (await s.save({ useMasterKey: !0 }), s.url());
|
||||
return { imageUrl: r };
|
||||
} catch (e) {
|
||||
console.log('err ', e), fs.unlinkSync(a);
|
||||
console.log('Err ', e), fs.unlinkSync(a);
|
||||
}
|
||||
}
|
||||
async function updateDoc(t, s, r, i, o, n) {
|
||||
@@ -224,8 +221,9 @@ async function PDF(i, o) {
|
||||
);
|
||||
var P,
|
||||
v,
|
||||
x = `./exports/exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
|
||||
b =
|
||||
x = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
|
||||
b = './exports/' + x,
|
||||
U =
|
||||
(t
|
||||
? ((P = n.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')),
|
||||
(e =
|
||||
@@ -243,13 +241,13 @@ async function PDF(i, o) {
|
||||
signatureLength: 1e4,
|
||||
})),
|
||||
(v = await new SignPDF(e, u).signPDF()),
|
||||
fs.writeFileSync(x, v))
|
||||
: fs.writeFileSync(x, e),
|
||||
await uploadFile(x));
|
||||
if (b && b.imageUrl) {
|
||||
fs.writeFileSync(b, v))
|
||||
: fs.writeFileSync(b, e),
|
||||
await uploadFile(x, b));
|
||||
if (U && U.imageUrl) {
|
||||
const o = await updateDoc(
|
||||
i.params.docId,
|
||||
b.imageUrl,
|
||||
U.imageUrl,
|
||||
s.data.results[0].objectId,
|
||||
i.headers['x-real-ip'],
|
||||
n.data,
|
||||
@@ -257,7 +255,7 @@ async function PDF(i, o) {
|
||||
);
|
||||
return (
|
||||
sendMail({
|
||||
url: b.imageUrl,
|
||||
url: U.imageUrl,
|
||||
sender: { Mail: n.data.ExtUserPtr.Email, Name: n.data.ExtUserPtr.Name },
|
||||
pdfName: n.data.Name,
|
||||
receiver: g,
|
||||
@@ -265,16 +263,16 @@ async function PDF(i, o) {
|
||||
o &&
|
||||
o.isCompleted &&
|
||||
(sendCompletedMail({
|
||||
url: b.imageUrl,
|
||||
url: U.imageUrl,
|
||||
sender: { Mail: n.data.ExtUserPtr.Email, Name: 'Open sign' },
|
||||
pdfName: n.data.Name,
|
||||
receiver: n.data.ExtUserPtr.Email,
|
||||
}),
|
||||
sendDoctoWebhook(n, b.imageUrl)),
|
||||
fs.unlinkSync(x),
|
||||
console.log('New Signed PDF created called: ' + x),
|
||||
sendDoctoWebhook(n, U.imageUrl)),
|
||||
fs.unlinkSync(b),
|
||||
console.log('New Signed PDF created called: ' + b),
|
||||
'success' === o.message
|
||||
? { status: 'success', data: b.imageUrl }
|
||||
? { status: 'success', data: U.imageUrl }
|
||||
: { status: 'error', message: 'please provide required parameters!' }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,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(function (req, res, next) {
|
||||
// console.log("req ", req.headers);
|
||||
// console.log("x-forwarded-for", req.headers["x-forwarded-for"]);
|
||||
|
||||
Reference in New Issue
Block a user