Skip to content

Commit

Permalink
feat: added methods for signed-url upload supabase/storage-js#152
Browse files Browse the repository at this point in the history
  • Loading branch information
fenix-hub committed Apr 10, 2023
1 parent 09e557e commit 5da5517
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions addons/supabase/Storage/storage_bucket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ func move(source_path : String, destination_path : String) -> StorageTask:
return task


func create_signed_url(object : String, expires_in : int = 60000) -> StorageTask:
func create_signed_url(object : String, expires_in : int = 60000, options: Dictionary = {
download = false, transform = { format = "origin" , quality = 80 , resize = "cover" , height = 100, width = 100 }
}) -> StorageTask:
var endpoint : String = _config.supabaseUrl + _rest_endpoint + "sign/" + id + "/" + object
var task : StorageTask = StorageTask.new()
var header : PackedStringArray = [_header[0] % "application/json"]
task._setup(
task.METHODS.CREATE_SIGNED_URL,
endpoint,
header + get_parent().get_parent().get_parent().auth.__get_session_header(),
JSON.stringify({expiresIn = expires_in})
JSON.stringify({expiresIn = expires_in, transform = options.get("transform", {}) })
)
task.set_meta("options", options)
_process_task(task)
return task

Expand Down
2 changes: 2 additions & 0 deletions addons/supabase/Storage/storage_task.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func _on_task_completed(result : int, response_code : int, headers : PackedStrin
if _code == METHODS.DOWNLOAD:
complete(body)
else:
if _code == METHODS.CREATE_SIGNED_URL:
result_body.signedURL += "&download=%s" % get_meta("options").get("download")
complete(result_body)
else:
if result_body.is_empty():
Expand Down

0 comments on commit 5da5517

Please sign in to comment.