Skip to content

Commit 57a9e02

Browse files
committed
Added temporaryUrl method
1 parent bca6f05 commit 57a9e02

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/ObsAdapter.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@
2121
use League\Flysystem\UnableToDeleteDirectory;
2222
use League\Flysystem\UnableToDeleteFile;
2323
use League\Flysystem\UnableToGeneratePublicUrl;
24+
use League\Flysystem\UnableToGenerateTemporaryUrl;
2425
use League\Flysystem\UnableToMoveFile;
2526
use League\Flysystem\UnableToProvideChecksum;
2627
use League\Flysystem\UnableToReadFile;
2728
use League\Flysystem\UnableToRetrieveMetadata;
2829
use League\Flysystem\UnableToSetVisibility;
2930
use League\Flysystem\UnableToWriteFile;
3031
use League\Flysystem\UrlGeneration\PublicUrlGenerator;
32+
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator;
3133
use League\MimeTypeDetection\FinfoMimeTypeDetector;
3234
use League\MimeTypeDetection\MimeTypeDetector;
3335
use Obs\ObsClient;
3436
use Obs\ObsException;
3537
use Psr\Http\Message\StreamInterface;
3638
use Psr\Http\Message\UriInterface;
3739

38-
class ObsAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider
40+
class ObsAdapter implements FilesystemAdapter, PublicUrlGenerator, ChecksumProvider, TemporaryUrlGenerator
3941
{
4042
/**
4143
* @var string[]
@@ -697,4 +699,22 @@ public function checksum(string $path, Config $config): string
697699

698700
return trim($metadata['ETag'], '"');
699701
}
702+
703+
public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string
704+
{
705+
try {
706+
/** @var array{SignedUrl: string} $model */
707+
$model = $this->obsClient->createSignedUrl([
708+
'Bucket' => $this->bucket,
709+
'Key' => $this->pathPrefixer->prefixPath($path),
710+
'Expires' => $expiresAt->getTimestamp() - time(),
711+
'Method' => 'GET',
712+
'QueryParams' => (array) $config->get('gcp_signing_options', []),
713+
]);
714+
715+
return $model['SignedUrl'];
716+
} catch (\Throwable $throwable) {
717+
throw UnableToGenerateTemporaryUrl::dueToError($path, $throwable);
718+
}
719+
}
700720
}

0 commit comments

Comments
 (0)