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

Update api/r2* to use KJ_IF_SOME #1205

Merged
merged 1 commit into from
Sep 22, 2023
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
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
Loading