Skip to content

Commit

Permalink
Merge pull request #43 from hepeichun/master
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Jul 23, 2024
2 parents a372a5b + 46026fc commit f8d4f96
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/CosAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Overtrue\Flysystem\Cos;

use DateTimeInterface;
use GuzzleHttp\Psr7\Uri;
use JetBrains\PhpStorm\Pure;
use League\Flysystem\Config;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit f8d4f96

Please sign in to comment.