1/* 2 Script for converting audit log data into a CSV string ready for download. 3 `data` is array of processed audit log rows from the UI. 4 `columns` is array with shape [{ key: ('timestamp', 'login', 'device', 'success', 'action', 'camera', 'detail'), heading: 'Translated heading here' }]. 5 `timezone` is the timezone selected in the UI (may be undefined if default should be used). 6*/ 7onmessage = ({ data: { data: logs = [], columns = [], timezone, timeLocale } }) => { 8 if (!Array.isArray(columns) || columns.length === 0) { 9 postMessage(''); 10 return; 11 } 12 13 let csv = ''; 14 15 csv += columns[0].heading + columns.slice(1).reduce((acc, { heading }) => acc + `,${heading}`, '') + '\n'; 16 17 const dateOptions = timezone ? { timeZone: timezone } : {}; 18 const timeOptions = timezone ? { timeZone: timezone, hour: '2-digit', minute: '2-digit', second: '2-digit' } : { hour: '2-digit', minute: '2-digit', second: '2-digit' }; 19 20 logs.forEach((row = {}) => { 21 const line = columns.reduce((acc, { key }) => { 22 let value; 23 24 switch (key) { 25 case 'timestamp': { 26 const timestamp = row.timestamp; 27 if (typeof timestamp === 'number') { 28 const timeString = new Date(timestamp).toLocaleTimeString(timeLocale, timeOptions); 29 const dateString = new Date(timestamp).toLocaleDateString(undefined, dateOptions); 30 value = `${timeString} ${dateString}`; 31 } else { 32 value = ''; 33 } 34 break; 35 } 36 default: 37 value = row[key] ?? ''; 38 break; 39 } 40 41 if (typeof value === 'string') { 42 value = value.replace(/[\r\n]/g, ' ').replace(/,/g, ' ').replace(/\s+/g, ' ').trim(); 43 } 44 45 return acc + (acc.length > 0 ? ',' : '') + value; 46 }, ''); 47 48 csv += line + '\n'; 49 }); 50 51 postMessage(csv); 52};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.