Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(conversion): missing target file extension #50219

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions lib/private/Files/Conversion/ConversionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use OC\AppFramework\Bootstrap\Coordinator;
use OC\SystemConfig;
use OCP\Files\Conversion\ConversionMimeProvider;
use OCP\Files\Conversion\IConversionManager;
use OCP\Files\Conversion\IConversionProvider;
use OCP\Files\File;
Expand Down Expand Up @@ -61,22 +60,6 @@ public function getProviders(): array {
return $providers;
}

/**
* @param string $mime
* @return list<ConversionMimeProvider>
*/
private function getProvidersForMime(string $mime): array {
$mimeTypes = $this->getProviders();
$filtered = array_filter(
$mimeTypes,
function (ConversionMimeProvider $mimeProvider) use ($mime) {
return $mimeProvider->getFrom() === $mime;
}
);

return array_values($filtered);
}

public function convert(File $file, string $targetMimeType, ?string $destination = null): string {
if (!$this->hasProviders()) {
throw new PreConditionNotMetException('No file conversion providers available');
Expand All @@ -92,16 +75,16 @@ public function convert(File $file, string $targetMimeType, ?string $destination
$fileMimeType = $file->getMimetype();
$validProvider = $this->getValidProvider($fileMimeType, $targetMimeType);

$targetExtension = '';
foreach ($this->getProvidersForMime($fileMimeType) as $mimeProvider) {
if ($mimeProvider->getTo() === $targetMimeType) {
$targetExtension = $mimeProvider->getExtension();
break;
}
}

if ($validProvider !== null) {
$convertedFile = $validProvider->convertFile($file, $targetMimeType);

$targetExtension = '';
foreach ($validProvider->getSupportedMimeTypes() as $mimeProvider) {
if ($mimeProvider->getTo() === $targetMimeType) {
$targetExtension = $mimeProvider->getExtension();
break;
}
}

// If destination not provided, we use the same path
// as the original file, but with the new extension
Expand All @@ -122,10 +105,6 @@ public function convert(File $file, string $targetMimeType, ?string $destination
* @return list<IConversionProvider>
*/
private function getRegisteredProviders(): array {
if (count($this->providers) > 0) {
return $this->providers;
}

$context = $this->coordinator->getRegistrationContext();
foreach ($context->getFileConversionProviders() as $providerRegistration) {
$class = $providerRegistration->getService();
Expand Down
Loading