diff --git a/src/CosAdapter.php b/src/CosAdapter.php index 1f5fcce..35ae42f 100644 --- a/src/CosAdapter.php +++ b/src/CosAdapter.php @@ -2,6 +2,7 @@ namespace Overtrue\Flysystem\Cos; +use DateTimeInterface; use GuzzleHttp\Psr7\Uri; use JetBrains\PhpStorm\Pure; use League\Flysystem\Config; @@ -12,16 +13,19 @@ use League\Flysystem\UnableToCopyFile; use League\Flysystem\UnableToDeleteDirectory; use League\Flysystem\UnableToDeleteFile; +use League\Flysystem\UnableToGenerateTemporaryUrl; use League\Flysystem\UnableToReadFile; use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToWriteFile; +use League\Flysystem\UrlGeneration\TemporaryUrlGenerator; use League\Flysystem\Visibility; use Overtrue\CosClient\BucketClient; use Overtrue\CosClient\Exceptions\ClientException; +use Overtrue\CosClient\Exceptions\InvalidConfigException; use Overtrue\CosClient\ObjectClient; use TheNorthMemory\Xml\Transformer; -class CosAdapter implements FilesystemAdapter +class CosAdapter implements FilesystemAdapter, TemporaryUrlGenerator { protected ?ObjectClient $objectClient; @@ -337,18 +341,17 @@ public function getUrl(string $path): string return $this->config['signed_url'] ? $this->getSignedUrl($path) : $this->getObjectClient()->getObjectUrl($prefixedPath); } - /** - * For laravel FilesystemAdapter. - * - * @throws \Overtrue\CosClient\Exceptions\InvalidConfigException - */ - public function getTemporaryUrl($path, int|string|\DateTimeInterface $expiration): string + public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string { - if ($expiration instanceof \DateTimeInterface) { - $expiration = $expiration->getTimestamp(); + if ($expiresAt instanceof \DateTimeInterface) { + $expiration = $expiresAt->getTimestamp(); } - return $this->getSignedUrl($path, $expiration); + try { + return $this->getSignedUrl($path, $expiration); + } catch (\Throwable $exception) { + throw UnableToGenerateTemporaryUrl::dueToError($path, $exception); + } } /**