1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Resolve scoping issue to get values of probeResult

This commit is contained in:
yashpalgoyal1304 2022-11-27 02:06:01 +05:30 committed by GitHub
parent 225f69b75b
commit 7c1d06e023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,6 +55,7 @@ module.exports = async ({github, context}) => {
return match;
}
let probeAspectRatio = 0;
let shouldModify = false;
try {
console.log(`Probing ${g2}`);
@ -76,7 +77,8 @@ module.exports = async ({github, context}) => {
}
console.log(`Probing resulted in ${probeResult.width}x${probeResult.height}px`);
shouldModify = probeResult.height > IMG_MAX_HEIGHT_PX && (probeResult.width / probeResult.height) < MIN_ASPECT_RATIO;
probeAspectRatio = probeResult.width / probeResult.height;
shouldModify = probeResult.height > IMG_MAX_HEIGHT_PX && probeAspectRatio < MIN_ASPECT_RATIO;
} catch(e) {
console.log('Probing failed:', e);
// Immediately abort
@ -86,7 +88,7 @@ module.exports = async ({github, context}) => {
if (shouldModify) {
wasMatchModified = true;
console.log(`Modifying match '${match}'`);
return `<img alt="${g1}" src="${g2}" width=${((IMG_MAX_HEIGHT_PX * probeResult.width) / probeResult.height).toFixed(0)} />`;
return `<img alt="${g1}" src="${g2}" width=${(IMG_MAX_HEIGHT_PX * probeAspectRatio).toFixed(0)} />`;
}
console.log(`Match '${match}' is ok/will not be modified`);