From 46026fc452b72e67fc694841736bfe5252960de6 Mon Sep 17 00:00:00 2001 From: hepeichun Date: Tue, 23 Jul 2024 00:17:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E8=BF=9E=E6=8E=A5=E7=9A=84=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CosAdapter.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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); + } } /**