Skip to content

Commit

Permalink
fix: 修复 visibility 实现
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Apr 30, 2024
1 parent c93f025 commit 9a7b3be
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/CosAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public function setVisibility(string $path, string $visibility): void
}

/**
* @see https://cloud.tencent.com/document/product/436/7744
* @throws \Overtrue\CosClient\Exceptions\InvalidConfigException
*/
public function visibility(string $path): FileAttributes
Expand All @@ -199,8 +200,22 @@ public function visibility(string $path): FileAttributes

$meta = $this->getObjectClient()->getObjectACL($prefixedPath);

foreach ($meta['AccessControlPolicy']['AccessControlList']['Grant'] ?? [] as $grant) {
if ($grant['Permission'] === 'READ' && str_contains($grant['Grantee']['URI'] ?? '', 'global/AllUsers')) {
$grants = $meta['AccessControlList']['Grant'] ?? [];

if (array_key_exists('Grantee', $grants)) {
$grants = [$grants];
}

foreach ($grants as $grant) {
// <Grant>
// <Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
// <URI>http://cam.qcloud.com/groups/global/AllUsers</URI>
// </Grantee>
// <Permission>READ</Permission>
// </Grant>
$allowRead = $grant['Permission'] === 'READ' || $grant['Permission'] === 'FULL_CONTROL';

if ($allowRead && str_contains($grant['Grantee']['URI'] ?? '', 'global/AllUsers')) {
return new FileAttributes($path, null, Visibility::PUBLIC);
}
}
Expand Down

0 comments on commit 9a7b3be

Please sign in to comment.