Skip to content

Commit

Permalink
fix: wrong video path (#162)
Browse files Browse the repository at this point in the history
rewrite extrapolateBaseFolder function
  • Loading branch information
joakim-sch authored Oct 10, 2023
1 parent 6756c12 commit 416cfe1
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/enhanceReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,24 @@ function encodeMediaPath(p) {
}

function extrapolateBaseFolder(results) {
//Snatched from https://rosettacode.org/wiki/Find_common_directory_path#JavaScript
const splitStrings = (a, sep = path.sep) => a.map((i) => i.split(sep));
const elAt = (i) => (a) => a[i];
const rotate = (a) => a[0].map((e, i) => a.map(elAt(i)));
const allElementsEqual = (arr) => arr.every((e) => e === arr[0]);
const commonPath = (input, sep = path.sep) =>
rotate(splitStrings(input, sep)).filter(allElementsEqual).map(elAt(0)).join(sep);
const directoryArrays = results.map((result) =>
path.dirname(result.fullFile).split(path.sep)
);
const minLength = Math.min(...directoryArrays.map((arr) => arr.length));
let commonPathArray = [];

let directoryArray = [];
results.forEach((result) => {
directoryArray = directoryArray.concat(path.dirname(result.fullFile));
});
const baseFolder = commonPath(directoryArray);
for (let i = 0; i < minLength; i++) {
const elementsAtCurrentIndex = directoryArrays.map((arr) => arr[i]);

if (allElementsEqual(elementsAtCurrentIndex)) {
commonPathArray.push(elementsAtCurrentIndex[0]);
} else {
break;
}
}

const baseFolder = commonPathArray.join(path.sep);
debugLog(`baseFolder: ${baseFolder}`);
return baseFolder;
}
Expand Down

0 comments on commit 416cfe1

Please sign in to comment.