chore: remove debug logging, remove unused ivantiMultipartPost import
This commit is contained in:
@@ -3,7 +3,7 @@ const express = require('express');
|
|||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { requireGroup } = require('../middleware/auth');
|
const { requireGroup } = require('../middleware/auth');
|
||||||
const { ivantiFormPost, ivantiPost, ivantiMultipartPost } = require('../helpers/ivantiApi');
|
const { ivantiFormPost, ivantiPost } = require('../helpers/ivantiApi');
|
||||||
const logAudit = require('../helpers/auditLog');
|
const logAudit = require('../helpers/auditLog');
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -199,19 +199,10 @@ async function resolveWorkflowBatchUuid(db, submission, apiKey, clientId, skipTl
|
|||||||
else if (data.data) batches = data.data;
|
else if (data.data) batches = data.data;
|
||||||
else if (Array.isArray(data)) batches = data;
|
else if (Array.isArray(data)) batches = data;
|
||||||
|
|
||||||
console.log('[resolveUUID] Found', batches.length, 'batches for name:', workflowName);
|
|
||||||
|
|
||||||
// Find the batch matching our numeric ID, or take the first result
|
|
||||||
const batch = batches.find(b => String(b.id) === batchId) || batches[0];
|
const batch = batches.find(b => String(b.id) === batchId) || batches[0];
|
||||||
if (batch) {
|
if (batch) {
|
||||||
console.log('[resolveUUID] Batch keys:', Object.keys(batch).join(', '));
|
|
||||||
console.log('[resolveUUID] Batch id:', batch.id, 'name:', batch.name);
|
|
||||||
console.log('[resolveUUID] Batch sample:', JSON.stringify(batch).substring(0, 800));
|
|
||||||
// Try every possible UUID field
|
|
||||||
uuid = batch.uuid || batch.workflowBatchUuid || batch.batchUuid || batch.groupUuid
|
uuid = batch.uuid || batch.workflowBatchUuid || batch.batchUuid || batch.groupUuid
|
||||||
|| batch.group_uuid || batch.workflow_batch_uuid || batch.uid || null;
|
|| batch.group_uuid || batch.workflow_batch_uuid || batch.uid || null;
|
||||||
} else {
|
|
||||||
console.log('[resolveUUID] No batches found');
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[resolveUUID] Failed to parse search response:', e.message);
|
console.error('[resolveUUID] Failed to parse search response:', e.message);
|
||||||
@@ -913,16 +904,13 @@ function createIvantiFpWorkflowRouter(db, requireAuth) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mapResult.status !== 200 && mapResult.status !== 201 && mapResult.status !== 202) {
|
if (mapResult.status !== 200 && mapResult.status !== 201 && mapResult.status !== 202) {
|
||||||
console.error('[mapFindings] Ivanti map failed — status:', mapResult.status, 'body:', (mapResult.body || '').substring(0, 500));
|
|
||||||
console.error('[mapFindings] Request URL:', mapUrl);
|
|
||||||
console.error('[mapFindings] Request fields:', JSON.stringify(formFields));
|
|
||||||
const errorMap = {
|
const errorMap = {
|
||||||
401: 'Ivanti API key is invalid or missing. Contact your administrator.',
|
401: 'Ivanti API key is invalid or missing. Contact your administrator.',
|
||||||
419: 'API key lacks permissions for this operation.',
|
419: 'API key lacks permissions for this operation.',
|
||||||
429: 'Ivanti API rate limit reached. Please try again in a few minutes.'
|
429: 'Ivanti API rate limit reached. Please try again in a few minutes.'
|
||||||
};
|
};
|
||||||
const errorMsg = mapResult.status >= 500
|
const errorMsg = mapResult.status >= 500
|
||||||
? `Ivanti API error (${mapResult.status}). Response: ${(mapResult.body || '').substring(0, 200)}`
|
? 'Ivanti API is temporarily unavailable. Please try again later.'
|
||||||
: (errorMap[mapResult.status] || `Operation failed: ${mapResult.status}`);
|
: (errorMap[mapResult.status] || `Operation failed: ${mapResult.status}`);
|
||||||
return res.status(mapResult.status === 429 ? 429 : 502).json({ success: false, error: errorMsg });
|
return res.status(mapResult.status === 429 ? 429 : 502).json({ success: false, error: errorMsg });
|
||||||
}
|
}
|
||||||
@@ -1082,15 +1070,11 @@ function createIvantiFpWorkflowRouter(db, requireAuth) {
|
|||||||
|
|
||||||
const attachUrl = `/client/${encodeURIComponent(clientId)}/workflowBatch/falsePositive/${encodeURIComponent(attachUuid)}/attach`;
|
const attachUrl = `/client/${encodeURIComponent(clientId)}/workflowBatch/falsePositive/${encodeURIComponent(attachUuid)}/attach`;
|
||||||
const attachmentResults = [];
|
const attachmentResults = [];
|
||||||
console.log('[attachFiles] Uploading', files.length, 'files to', attachUrl);
|
|
||||||
|
|
||||||
for (const f of files) {
|
for (const f of files) {
|
||||||
console.log('[attachFiles] Uploading:', f.originalname, 'size:', f.size, 'mimetype:', f.mimetype);
|
|
||||||
try {
|
try {
|
||||||
// Use ivantiFormPost with field name 'file' and proper MIME type
|
|
||||||
const formFiles = [{ name: 'file', buffer: f.buffer, filename: f.originalname, contentType: f.mimetype || 'application/octet-stream' }];
|
const formFiles = [{ name: 'file', buffer: f.buffer, filename: f.originalname, contentType: f.mimetype || 'application/octet-stream' }];
|
||||||
const result = await ivantiFormPost(attachUrl, [], formFiles, apiKey, skipTls);
|
const result = await ivantiFormPost(attachUrl, [], formFiles, apiKey, skipTls);
|
||||||
console.log('[attachFiles] Result for', f.originalname, '— status:', result.status, 'body:', (result.body || '').substring(0, 200));
|
|
||||||
const success = result.status === 200 || result.status === 201 || result.status === 202;
|
const success = result.status === 200 || result.status === 201 || result.status === 202;
|
||||||
attachmentResults.push({ filename: f.originalname, success, ...(success ? {} : { error: `Upload failed: ${result.status}` }) });
|
attachmentResults.push({ filename: f.originalname, success, ...(success ? {} : { error: `Upload failed: ${result.status}` }) });
|
||||||
} catch (uploadErr) {
|
} catch (uploadErr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user