Skip to content

Commit ac34e9a

Browse files
committed
feat: quality option, image transformation supabase/storage-js#145
1 parent 5da5517 commit ac34e9a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

addons/supabase/Storage/storage_bucket.gd

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ var _response_code : int
6161

6262
var id : String
6363

64-
6564
func _init(id : String , config : Dictionary) -> void:
6665
_config = config
6766
self.id = id
@@ -150,7 +149,7 @@ func move(source_path : String, destination_path : String) -> StorageTask:
150149

151150

152151
func create_signed_url(object : String, expires_in : int = 60000, options: Dictionary = {
153-
download = false, transform = { format = "origin" , quality = 80 , resize = "cover" , height = 100, width = 100 }
152+
download = "file", transform = { format = "origin" , quality = 80 , resize = "cover" , height = 100, width = 100 }
154153
}) -> StorageTask:
155154
var endpoint : String = _config.supabaseUrl + _rest_endpoint + "sign/" + id + "/" + object
156155
var task : StorageTask = StorageTask.new()
@@ -162,6 +161,7 @@ func create_signed_url(object : String, expires_in : int = 60000, options: Dicti
162161
JSON.stringify({expiresIn = expires_in, transform = options.get("transform", {}) })
163162
)
164163
task.set_meta("options", options)
164+
task.set_meta("base_url", _config.supabaseUrl + _rest_endpoint.replace("/object/", ""))
165165
_process_task(task)
166166
return task
167167

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

193193

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

197204

198205
func remove(objects : PackedStringArray) -> StorageTask:

addons/supabase/Storage/storage_task.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func _on_task_completed(result : int, response_code : int, headers : PackedStrin
4141
complete(body)
4242
else:
4343
if _code == METHODS.CREATE_SIGNED_URL:
44-
result_body.signedURL += "&download=%s" % get_meta("options").get("download")
44+
result_body.signedURL = get_meta("base_url") + result_body.signedURL + "&download=%s" % get_meta("options").get("download")
4545
complete(result_body)
4646
else:
4747
if result_body.is_empty():

0 commit comments

Comments
 (0)