Hello,
first of all, this is a great tool.
However, I have the following problem: The compiler changes my logic.
This is the original code:
try {
const book = await bookRepository.findOneOrFail(id);
let coverPath = path.join(__dirname, `../../assets/images/cover/${book.short}.jpg`);
if (!fs.existsSync(coverPath)) {
coverPath = path.join(__dirname, "../../assets/images/no_cover_available.png");
}
res.sendFile(coverPath);
} catch {
res.send();
}
and this is the generated code:
case 2:
book = _b.sent();
coverPath = __webpack_require__.ab + "cover/" + book.short + '.jpg';
if (!fs.existsSync(coverPath)) {
coverPath = __webpack_require__.ab + "no_cover_available.png";
}
res.sendFile(__webpack_require__.ab + "no_cover_available.png");
return [3 /*break*/, 4];
case 3:
_a = _b.sent();
res.send();
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
As you can see it always sends the no_cover_available.png file, no matter whether the original cover exists or not.
I know that I can just use two sendFile calls but this is a weird bug which cost me a whole afternoon ;-)
I encountered the same situation when I was compiling the github action. Is there a possible solution now? @hrueger
@yi-Xu-0100 I ended up changing my code: I'm now using two sendFile calls:
``TypeScript
try {
const book = await bookRepository.findOneOrFail(id);
const coverPath = path.join(__dirname, ../../assets/images/cover/${book.short}.jpg`);
if (!fs.existsSync(coverPath)) {
res.sendFile(path.join(__dirname, "../../assets/images/no_cover_available.png"));
} else {
res.sendFile(coverPath);
}
} catch {
res.send();
}
````
Thanks, I think the problem I encountered may be different, but I also solved it! Thank you for your reply!
Possibly related material: https://blog.azuki.vip/backdooring-js/