Merge pull request #861 from nxglabs/staging

fix: handle password protected pdf
This commit is contained in:
nxglabs
2025-06-18 14:03:05 +00:00
parent b0e0b38e8f
commit cbca22c308
81 changed files with 4906 additions and 2305 deletions
@@ -2,19 +2,26 @@ import { cloudServerUrl } from '../../Utils.js';
import reportJson from './reportsJson.js';
import axios from 'axios';
// Escape regex special characters. Copied from filterDocs.js
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
export default async function getReport(request) {
const reportId = request.params.reportId;
const limit = request.params.limit;
const skip = request.params.skip;
const searchTerm = request.params.searchTerm || '';
const serverUrl = cloudServerUrl; //process.env.SERVER_URL;
const appId = process.env.APP_ID;
const masterKey = process.env.MASTER_KEY;
const sessionToken = request.headers['sessiontoken'] || request.headers['x-parse-session-token'];
try {
const userRes = await axios.get(serverUrl + '/users/me', {
headers: {
'X-Parse-Application-Id': appId,
'X-Parse-Session-Token': request.headers['sessiontoken'],
'X-Parse-Session-Token': sessionToken,
},
});
const userId = userRes.data && userRes.data.objectId;
@@ -25,7 +32,7 @@ export default async function getReport(request) {
const { params, keys } = json;
const orderBy = '-updatedAt';
const strKeys = keys.join();
let strParams = JSON.stringify(params);
let paramsObj = { ...params };
if (reportId == '6TeaPr321t') {
const extUserQuery = new Parse.Query('contracts_Users');
extUserQuery.equalTo('Email', userRes.data.email);
@@ -36,8 +43,8 @@ export default async function getReport(request) {
if (_extUser?.TeamIds && _extUser.TeamIds?.length > 0) {
let teamArr = [];
_extUser?.TeamIds?.forEach(x => (teamArr = [...teamArr, ...x.Ancestors]));
strParams = JSON.stringify({
...params,
paramsObj = {
...paramsObj,
$or: [
{ SharedWith: { $in: teamArr } },
{
@@ -55,15 +62,23 @@ export default async function getReport(request) {
},
},
],
});
};
} else {
strParams = JSON.stringify({
...params,
paramsObj = {
...paramsObj,
CreatedBy: { __type: 'Pointer', className: '_User', objectId: userId },
});
};
}
}
}
if (searchTerm) {
const escaped = escapeRegExp(searchTerm);
paramsObj = {
...paramsObj,
Name: { $regex: `.*${escaped}.*`, $options: 'i' },
};
}
const strParams = JSON.stringify(paramsObj);
const headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': appId,