Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list pagination and proofs conflict #3

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
# part of the url
S3_URL=
S3_REGION=
# don't use the same bucket as the properties don't expect a file and a
# directory to have the same name (which can be generated by other proofs)
S3_PROPERTIES_URL=
S3_PROPERTIES_REGION=
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
env:
S3_URL: ${{ secrets.S3_URL_PROOFS }}
S3_REGION: ${{ secrets.S3_REGION_PROOFS }}
S3_PROPERTIES_URL: ${{ secrets.S3_PROPERTIES_URL_PROOFS }}
S3_PROPERTIES_REGION: ${{ secrets.S3_PROPERTIES_REGION_PROOFS }}
blackbox_coverage:
runs-on: ${{ matrix.os }}
concurrency:
Expand Down Expand Up @@ -58,6 +60,8 @@ jobs:
ENABLE_COVERAGE: 'true'
S3_URL: ${{ secrets.S3_URL_COVERAGE }}
S3_REGION: ${{ secrets.S3_REGION_COVERAGE }}
S3_PROPERTIES_URL: ${{ secrets.S3_PROPERTIES_URL_COVERAGE }}
S3_PROPERTIES_REGION: ${{ secrets.S3_PROPERTIES_REGION_COVERAGE }}
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/periodic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jobs:
env:
S3_URL: ${{ secrets.S3_URL_PROOFS }}
S3_REGION: ${{ secrets.S3_REGION_PROOFS }}
S3_PROPERTIES_URL: ${{ secrets.S3_PROPERTIES_URL_PROOFS }}
S3_PROPERTIES_REGION: ${{ secrets.S3_PROPERTIES_REGION_PROOFS }}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ $data
static fn() => null, // do something if there is no images
);
```

> [!WARNING]
> A bucket can contain a file and a directory with the same name. This is not supported by `innmind/filesystem` adapters. This means that if you use `Innmind\S3\Filesystem\Adapter` on a bucket where there is a file and a directory with the same name it will result in unexpected behaviour or an exception.
4 changes: 2 additions & 2 deletions proofs/adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

$os = Resilient::of(OSFactory::build());
$bucket = Factory::of($os)->build(
Url::of(\getenv('S3_URL') ?? throw new Exception('Env var missing')),
Region::of(\getenv('S3_REGION') ?? throw new Exception('Env var missing')),
Url::of(\getenv('S3_PROPERTIES_URL') ?? throw new Exception('Env var missing')),
Region::of(\getenv('S3_PROPERTIES_REGION') ?? throw new Exception('Env var missing')),
);

yield properties(
Expand Down
29 changes: 21 additions & 8 deletions src/Bucket/OverHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ public function list(Path $path): Sequence
throw new LogicException("Only a directory can be listed, got '{$path->toString()}'");
}

if ($path->equals(Path::none())) {
$query = 'delimiter=%2F&list-type=2';
$prefixLength = 0;
} else {
$query = 'delimiter=%2F&list-type=2&prefix='.\rawurlencode($path->toString());
$query = [
'delimiter' => '/',
'list-type' => 2,
];
$prefixLength = 0;

if (!$path->equals(Path::none())) {
$query['prefix'] = $path->toString();
$prefixLength = Str::of($path->toString(), Str\Encoding::ascii)->length();
}

Expand All @@ -144,18 +147,28 @@ public function list(Path $path): Sequence
*/
private function paginate(
Path $path,
string $query,
array $query,
string $next = null,
): Sequence {
if (\is_string($next)) {
$next = '&continuation-token='.$next;
$next = ['continuation-token' => $next];
} else {
$next = [];
}

return ($this->fulfill)($this->request(
Method::get,
$this->bucket->path(),
null,
Query::of($query.(string) $next),
Query::of(\http_build_query(
[
...$next,
...$query,
],
'',
'&',
\PHP_QUERY_RFC3986,
)),
))
->maybe()
->map(static fn($success) => $success->response()->body())
Expand Down
Loading