Skip to content

Commit

Permalink
Merge pull request #746 from fabalexsie/master
Browse files Browse the repository at this point in the history
Add key support for Imaginary
  • Loading branch information
matiasdelellis authored May 2, 2024
2 parents d5478c5 + 7bec65a commit a54043c
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lib/Helper/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public function getUrl(): ?string {
return rtrim($imaginaryUrl, '/');
}

public function hasKey(): ?string {
$imaginaryKey = $this->config->getSystemValueString('preview_imaginary_key', 'invalid');
return ($imaginaryKey !== 'invalid');
}

public function getKey(): ?string {
$imaginaryKey = $this->config->getSystemValueString('preview_imaginary_key', 'invalid');
if ($imaginaryKey === 'invalid')
return null;

return $imaginaryKey;
}

/**
* @return string imaginary version
*/
Expand All @@ -67,7 +80,13 @@ public function getVersion(): ?string {
$httpClient = $this->service->newClient();

try {
$response = $httpClient->get($imaginaryUrl . '/');
$options = [];
if ($this->hasKey()) {
$options['query'] = [
'key' => $this->getKey(),
];
}
$response = $httpClient->get($imaginaryUrl . '/', $options);
} catch (\Exception $e) {
return null;
}
Expand Down Expand Up @@ -99,6 +118,12 @@ public function getInfo(string $filepath): array {
'filename' => basename($filepath),
]];

if ($this->hasKey()) {
$options['query'] = [
'key' => $this->getKey(),
];
}

$response = $httpClient->post($imaginaryUrl . '/info', $options);

if ($response->getStatusCode() !== 200) {
Expand Down Expand Up @@ -160,9 +185,15 @@ public function getResized(string $filepath, int $width, int $height, bool $auto
]
];

$query = [];
$query['operations'] = json_encode($operations);
if ($this->hasKey()) {
$query['key'] = $this->getKey();
}

$response = $httpClient->post(
$imaginaryUrl . '/pipeline', [
'query' => ['operations' => json_encode($operations)],
'query' => $query,
'body' => file_get_contents($filepath),
'nextcloud' => ['allow_local_address' => true],
]);
Expand Down

0 comments on commit a54043c

Please sign in to comment.