Skip to content

Commit

Permalink
S3.upload, S3.unlink, S3.presign
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Dec 21, 2024
1 parent ec564c0 commit da5bc33
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub const BunObject = struct {
pub const SHA384 = toJSGetter(Crypto.SHA384.getter);
pub const SHA512 = toJSGetter(Crypto.SHA512.getter);
pub const SHA512_256 = toJSGetter(Crypto.SHA512_256.getter);
pub const S3 = toJSGetter(JSC.WebCore.Blob.getJSS3FileConstructor);
pub const TOML = toJSGetter(Bun.getTOMLObject);
pub const Transpiler = toJSGetter(Bun.getTranspilerConstructor);
pub const argv = toJSGetter(Bun.getArgv);
Expand Down Expand Up @@ -109,12 +110,14 @@ pub const BunObject = struct {
@export(BunObject.FileSystemRouter, .{ .name = getterName("FileSystemRouter") });
@export(BunObject.MD4, .{ .name = getterName("MD4") });
@export(BunObject.MD5, .{ .name = getterName("MD5") });
@export(BunObject.S3, .{ .name = getterName("S3") });
@export(BunObject.SHA1, .{ .name = getterName("SHA1") });
@export(BunObject.SHA224, .{ .name = getterName("SHA224") });
@export(BunObject.SHA256, .{ .name = getterName("SHA256") });
@export(BunObject.SHA384, .{ .name = getterName("SHA384") });
@export(BunObject.SHA512, .{ .name = getterName("SHA512") });
@export(BunObject.SHA512_256, .{ .name = getterName("SHA512_256") });

@export(BunObject.TOML, .{ .name = getterName("TOML") });
@export(BunObject.Glob, .{ .name = getterName("Glob") });
@export(BunObject.Transpiler, .{ .name = getterName("Transpiler") });
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/BunObject+exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
macro(SHA512_256) \
macro(TOML) \
macro(Transpiler) \
macro(S3) \
macro(argv) \
macro(assetPrefix) \
macro(cwd) \
Expand Down
3 changes: 2 additions & 1 deletion src/bun.js/bindings/BunObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
Glob BunObject_getter_wrap_Glob DontDelete|PropertyCallback
MD4 BunObject_getter_wrap_MD4 DontDelete|PropertyCallback
MD5 BunObject_getter_wrap_MD5 DontDelete|PropertyCallback
S3 BunObject_getter_wrap_S3 DontDelete|PropertyCallback
SHA1 BunObject_getter_wrap_SHA1 DontDelete|PropertyCallback
SHA224 BunObject_getter_wrap_SHA224 DontDelete|PropertyCallback
SHA256 BunObject_getter_wrap_SHA256 DontDelete|PropertyCallback
Expand Down Expand Up @@ -637,7 +638,7 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
resolveSync BunObject_callback_resolveSync DontDelete|Function 1
revision constructBunRevision ReadOnly|DontDelete|PropertyCallback
semver BunObject_getter_wrap_semver ReadOnly|DontDelete|PropertyCallback
s3 BunObject_callback_s3 DontDelete|Function 1
s3 BunObject_callback_s3 DontDelete|Function 1
sql constructBunSQLObject DontDelete|PropertyCallback
serve BunObject_callback_serve DontDelete|Function 1
sha BunObject_callback_sha DontDelete|Function 1
Expand Down
32 changes: 32 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "root.h"
#include "JavaScriptCore/PropertySlot.h"
#include "ZigGlobalObject.h"
#include "helpers.h"
#include "JavaScriptCore/ArgList.h"
Expand Down Expand Up @@ -83,6 +84,7 @@
#include "JSDOMConvertUnion.h"
#include "JSDOMException.h"
#include "JSDOMFile.h"
#include "JSS3File.h"
#include "JSDOMFormData.h"
#include "JSDOMURL.h"
#include "JSEnvironmentVariableMap.h"
Expand Down Expand Up @@ -2808,6 +2810,25 @@ JSC_DEFINE_CUSTOM_SETTER(moduleNamespacePrototypeSetESModuleMarker, (JSGlobalObj
return true;
}

extern "C" JSC::EncodedJSValue JSS3File__upload(JSGlobalObject*, JSC::CallFrame*);
extern "C" JSC::EncodedJSValue JSS3File__presign(JSGlobalObject*, JSC::CallFrame*);
extern "C" JSC::EncodedJSValue JSS3File__unlink(JSGlobalObject*, JSC::CallFrame*);

JSC_DEFINE_HOST_FUNCTION(jsS3Upload, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
{
return JSS3File__upload(lexicalGlobalObject, callFrame);
}

JSC_DEFINE_HOST_FUNCTION(jsS3Presign, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
{
return JSS3File__presign(lexicalGlobalObject, callFrame);
}

JSC_DEFINE_HOST_FUNCTION(jsS3Unlink, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame))
{
return JSS3File__unlink(lexicalGlobalObject, callFrame);
}

void GlobalObject::finishCreation(VM& vm)
{
Base::finishCreation(vm);
Expand All @@ -2829,6 +2850,16 @@ void GlobalObject::finishCreation(VM& vm)
init.set(fileConstructor);
});

m_JSS3FileConstructor.initLater(
[](const Initializer<JSObject>& init) {
JSObject* s3Constructor = Bun::createJSS3FileConstructor(init.vm, init.owner);
s3Constructor->putDirectNativeFunction(init.vm, init.owner, JSC::Identifier::fromString(init.vm, "upload"_s), 3, jsS3Upload, ImplementationVisibility::Public, JSC::NoIntrinsic, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | 0);
s3Constructor->putDirectNativeFunction(init.vm, init.owner, JSC::Identifier::fromString(init.vm, "unlink"_s), 3, jsS3Unlink, ImplementationVisibility::Public, JSC::NoIntrinsic, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | 0);
s3Constructor->putDirectNativeFunction(init.vm, init.owner, JSC::Identifier::fromString(init.vm, "presign"_s), 3, jsS3Presign, ImplementationVisibility::Public, JSC::NoIntrinsic, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | 0);

init.set(s3Constructor);
});

m_cryptoObject.initLater(
[](const Initializer<JSObject>& init) {
JSC::JSGlobalObject* globalObject = init.owner;
Expand Down Expand Up @@ -3819,6 +3850,7 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_JSCryptoKey.visit(visitor);
thisObject->m_lazyStackCustomGetterSetter.visit(visitor);
thisObject->m_JSDOMFileConstructor.visit(visitor);
thisObject->m_JSS3FileConstructor.visit(visitor);
thisObject->m_JSFFIFunctionStructure.visit(visitor);
thisObject->m_JSFileSinkClassStructure.visit(visitor);
thisObject->m_JSFileSinkControllerPrototype.visit(visitor);
Expand Down
4 changes: 4 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ class GlobalObject : public Bun::GlobalScope {

JSObject* cryptoObject() const { return m_cryptoObject.getInitializedOnMainThread(this); }
JSObject* JSDOMFileConstructor() const { return m_JSDOMFileConstructor.getInitializedOnMainThread(this); }
JSObject* JSS3FileConstructor() const { return m_JSS3FileConstructor.getInitializedOnMainThread(this); }

Bun::CommonStrings& commonStrings() { return m_commonStrings; }
Bun::Http2CommonStrings& http2CommonStrings() { return m_http2_commongStrings; }
#include "ZigGeneratedClasses+lazyStructureHeader.h"
Expand Down Expand Up @@ -572,6 +574,8 @@ class GlobalObject : public Bun::GlobalScope {
LazyProperty<JSGlobalObject, Structure> m_importMetaObjectStructure;
LazyProperty<JSGlobalObject, Structure> m_asyncBoundFunctionStructure;
LazyProperty<JSGlobalObject, JSC::JSObject> m_JSDOMFileConstructor;
LazyProperty<JSGlobalObject, JSC::JSObject> m_JSS3FileConstructor;

LazyProperty<JSGlobalObject, Structure> m_JSCryptoKey;
LazyProperty<JSGlobalObject, Structure> m_NapiExternalStructure;
LazyProperty<JSGlobalObject, Structure> m_NapiPrototypeStructure;
Expand Down
Loading

0 comments on commit da5bc33

Please sign in to comment.