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) {