From 59de3a7311506908d39ed86f5953a608d51a0acc Mon Sep 17 00:00:00 2001 From: overtrue Date: Wed, 18 Sep 2024 17:26:57 +0800 Subject: [PATCH] fixed: fixed Laravel temporary URL issue overtrue/laravel-filesystem-cos#18 --- src/CosAdapter.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/CosAdapter.php b/src/CosAdapter.php index 402c5d0..cd8f4d6 100644 --- a/src/CosAdapter.php +++ b/src/CosAdapter.php @@ -21,7 +21,6 @@ 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; @@ -341,6 +340,19 @@ public function getUrl(string $path): string return $this->config['signed_url'] ? $this->getSignedUrl($path) : $this->getObjectClient()->getObjectUrl($prefixedPath); } + public function getTemporaryUrl(string $path, $expiration) + { + if ($expiresAt instanceof \DateTimeInterface) { + $expiration = $expiresAt->getTimestamp(); + } + + try { + return $this->getSignedUrl($path, $expiration); + } catch (\Throwable $exception) { + throw UnableToGenerateTemporaryUrl::dueToError($path, $exception); + } + } + public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string { if ($expiresAt instanceof \DateTimeInterface) {