Skip to content

Commit

Permalink
feat: quality option, image transformation supabase/storage-js#145
Browse files Browse the repository at this point in the history
  • Loading branch information
fenix-hub committed Apr 10, 2023
1 parent 5da5517 commit ac34e9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions addons/supabase/Storage/storage_bucket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var _response_code : int

var id : String


func _init(id : String , config : Dictionary) -> void:
_config = config
self.id = id
Expand Down Expand Up @@ -150,7 +149,7 @@ func move(source_path : String, destination_path : String) -> 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 }
download = "file", 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()
Expand All @@ -162,6 +161,7 @@ func create_signed_url(object : String, expires_in : int = 60000, options: Dicti
JSON.stringify({expiresIn = expires_in, transform = options.get("transform", {}) })
)
task.set_meta("options", options)
task.set_meta("base_url", _config.supabaseUrl + _rest_endpoint.replace("/object/", ""))
_process_task(task)
return task

Expand Down Expand Up @@ -191,8 +191,15 @@ func download(object : String, to_path : String = "", private : bool = false) ->
return task


func get_public_url(object : String) -> String:
return _config.supabaseUrl + _rest_endpoint + "public/" + id + "/" + object
func get_public_url(object: String, transform: Dictionary = {
height = 100, width = 100, format = "origin", resize = "cover", quality = 80
} ) -> String:
var url: String = _config.supabaseUrl + _rest_endpoint + "public/" + id + "/" + object
if not transform.keys().is_empty():
url += "?"
for key in transform.keys():
url += "&%s=%s" % [key, transform.get(key)]
return url


func remove(objects : PackedStringArray) -> StorageTask:
Expand Down
2 changes: 1 addition & 1 deletion addons/supabase/Storage/storage_task.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func _on_task_completed(result : int, response_code : int, headers : PackedStrin
complete(body)
else:
if _code == METHODS.CREATE_SIGNED_URL:
result_body.signedURL += "&download=%s" % get_meta("options").get("download")
result_body.signedURL = get_meta("base_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 ac34e9a

Please sign in to comment.