Skip to content

Commit

Permalink
fix: Read from local file stream to avoid locking during preview gene…
Browse files Browse the repository at this point in the history
…ration

Signed-off-by: Julius Knorr <[email protected]>
  • Loading branch information
juliusknorr committed Jan 30, 2025
1 parent f11bfb2 commit 450728d
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions lib/Service/RemoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,8 @@ public function fetchTargetThumbnail(File $file, string $target): ?string {
* @return resource|string
*/
public function convertFileTo(File $file, string $format) {
$useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal();
if ($useTempFile) {
$fileName = $file->getStorage()->getLocalFile($file->getInternalPath());
$stream = fopen($fileName, 'r');
} else {
$stream = $file->fopen('r');
}
$fileName = $file->getStorage()->getLocalFile($file->getInternalPath());
$stream = fopen($fileName, 'rb');

if ($stream === false) {
throw new Exception('Failed to open stream');
Expand Down Expand Up @@ -98,16 +93,11 @@ public function convertTo(string $filename, $stream, string $format) {
}

private function getRequestOptionsForFile(File $file, ?string $target = null): array {
$useTempFile = $file->isEncrypted() || !$file->getStorage()->isLocal();
if ($useTempFile) {
$localFile = $file->getStorage()->getLocalFile($file->getInternalPath());
if (!is_string($localFile)) {
throw new NotFoundException('Could not get local file');
}
$stream = fopen($localFile, 'rb');
} else {
$stream = $file->fopen('rb');
$localFile = $file->getStorage()->getLocalFile($file->getInternalPath());
if (!is_string($localFile)) {
throw new NotFoundException('Could not get local file');
}
$stream = fopen($localFile, 'rb');

$options = RemoteOptionsService::getDefaultOptions(25);
$options['multipart'] = [
Expand Down

0 comments on commit 450728d

Please sign in to comment.