Skip to content

Commit

Permalink
Fix paths when extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Sep 20, 2023
1 parent 495cd7e commit 95211c3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Service/BookFileSystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,23 +369,28 @@ public function extractCover(Book $book): Book
}
$cover = current($entries);

shell_exec('unrar e "'.$bookFile->getRealPath().'" "'.$cover.'" /tmp -y');
$expl = explode('.', $cover);
$coverFile = explode('/', $cover);
$coverFile = end($coverFile);
$ext = end($expl);
$book->setImageExtension($ext);

shell_exec('unrar e -ep "'.$bookFile->getRealPath().'" "'.$cover.'" -op"/tmp/" -y');

$filesystem->mkdir($this->getCalculatedImagePath($book, true));
try {
$checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$cover));
$checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$coverFile));
} catch (\Exception $e) {
$this->logger->error('Could not calculate checksum', ['book' => $bookFile->getRealPath(), 'exception' => $e->getMessage()]);
$checksum = md5(''.time());
}
$filesystem->rename(
'/tmp/'.$cover,
'/tmp/'.$coverFile,
$this->getCalculatedImagePath($book, true).$this->getCalculatedImageName($book, $checksum),
true);

$book->setImagePath($this->getCalculatedImagePath($book, false));
$book->setImageFilename($this->getCalculatedImageName($book, $checksum));
$book->setImageExtension('jpg');

break;
case 'pdf':
Expand Down

0 comments on commit 95211c3

Please sign in to comment.