Skip to content

Commit

Permalink
Update api/r2* to use KJ_IF_SOME
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 22, 2023
1 parent 0b72b82 commit cb4735c
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 221 deletions.
24 changes: 12 additions & 12 deletions src/workerd/api/r2-admin.c++
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

namespace workerd::api::public_beta {
jsg::Ref<R2Bucket> R2Admin::get(jsg::Lock& js, kj::String bucketName) {
KJ_IF_MAYBE(j, jwt) {
KJ_IF_SOME(j, jwt) {
return jsg::alloc<R2Bucket>(featureFlags, subrequestChannel, kj::mv(bucketName),
kj::str(*j), R2Bucket::friend_tag_t{});
kj::str(j), R2Bucket::friend_tag_t{});
}
return jsg::alloc<R2Bucket>(featureFlags, subrequestChannel, kj::mv(bucketName), R2Bucket::friend_tag_t{});
}

jsg::Promise<jsg::Ref<R2Bucket>> R2Admin::create(jsg::Lock& js, kj::String name,
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
auto& context = IoContext::current();
auto client = context.getHttpClient(subrequestChannel, true, nullptr, "r2_delete"_kjc);
auto client = context.getHttpClient(subrequestChannel, true, kj::none, "r2_delete"_kjc);

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand All @@ -34,7 +34,7 @@ jsg::Promise<jsg::Ref<R2Bucket>> R2Admin::create(jsg::Lock& js, kj::String name,
createBucketBuilder.setBucket(name);

auto requestJson = json.encode(requestBuilder);
auto promise = doR2HTTPPutRequest(js, kj::mv(client), nullptr, nullptr,
auto promise = doR2HTTPPutRequest(js, kj::mv(client), kj::none, kj::none,
kj::mv(requestJson), nullptr, jwt);

return context.awaitIo(js, kj::mv(promise),
Expand All @@ -51,7 +51,7 @@ jsg::Promise<R2Admin::ListResult> R2Admin::list(jsg::Lock& js,
const jsg::TypeHandler<jsg::Ref<RetrievedBucket>>& retrievedBucketType,
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType, CompatibilityFlags::Reader flags) {
auto& context = IoContext::current();
auto client = context.getHttpClient(subrequestChannel, true, nullptr, "r2_delete"_kjc);
auto client = context.getHttpClient(subrequestChannel, true, kj::none, "r2_delete"_kjc);

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand All @@ -62,12 +62,12 @@ jsg::Promise<R2Admin::ListResult> R2Admin::list(jsg::Lock& js,
requestBuilder.setVersion(VERSION_PUBLIC_BETA);
auto payloadBuilder = requestBuilder.initPayload();
auto listBucketBuilder = payloadBuilder.initListBucket();
KJ_IF_MAYBE(o, options) {
KJ_IF_MAYBE(l, o->limit) {
listBucketBuilder.setLimit(*l);
KJ_IF_SOME(o, options) {
KJ_IF_SOME(l, o.limit) {
listBucketBuilder.setLimit(l);
}
KJ_IF_MAYBE(c, o->cursor) {
listBucketBuilder.setCursor(*c);
KJ_IF_SOME(c, o.cursor) {
listBucketBuilder.setCursor(c);
}
}

Expand Down Expand Up @@ -107,7 +107,7 @@ jsg::Promise<R2Admin::ListResult> R2Admin::list(jsg::Lock& js,
jsg::Promise<void> R2Admin::delete_(jsg::Lock& js, kj::String name,
const jsg::TypeHandler<jsg::Ref<R2Error>>& errorType) {
auto& context = IoContext::current();
auto client = context.getHttpClient(subrequestChannel, true, nullptr, "r2_delete"_kjc);
auto client = context.getHttpClient(subrequestChannel, true, kj::none, "r2_delete"_kjc);

capnp::JsonCodec json;
json.handleByAnnotation<R2BindingRequest>();
Expand All @@ -120,7 +120,7 @@ jsg::Promise<void> R2Admin::delete_(jsg::Lock& js, kj::String name,
deleteBucketBuilder.setBucket(name);

auto requestJson = json.encode(requestBuilder);
auto promise = doR2HTTPPutRequest(js, kj::mv(client), nullptr, nullptr,
auto promise = doR2HTTPPutRequest(js, kj::mv(client), kj::none, kj::none,
kj::mv(requestJson), nullptr, jwt);

return context.awaitIo(js, kj::mv(promise), [&errorType](jsg::Lock&, R2Result r2Result) mutable {
Expand Down
Loading

0 comments on commit cb4735c

Please sign in to comment.