Skip to content

Commit

Permalink
add option to download files for assets via guzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Nov 19, 2024
1 parent ce0fc26 commit 0e514fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/helpers/AssetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,25 @@ public static function downloadFile($srcName, $dstName, int $chunkSize = 1, bool
return fclose($fp);
}

$fp = fopen($dstName, 'wb');

$assetDownloadGuzzle = Plugin::$plugin->service->getConfig('assetDownloadGuzzle', $feedId);
if ($assetDownloadGuzzle) {
$response = null;
$client = Plugin::$plugin->service->createGuzzleClient();
try {
$response = $client->get($srcName, ['sink' => $fp]);
} catch (Throwable $e) {
}

fclose($fp);

return $response?->getStatusCode() === 200;
}

$newChunkSize = $chunkSize * (1024 * 1024);
$bytesCount = 0;
$handle = fopen($srcName, 'rb');
$fp = fopen($dstName, 'wb');

if ($handle === false) {
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ class Settings extends Model
* @var bool
*/
public bool $assetDownloadCurl = false;

/**
* @var bool
* @since 5.9.0
*/
public bool $assetDownloadGuzzle = false;
}

0 comments on commit 0e514fb

Please sign in to comment.