@@ -148,8 +148,25 @@ func move(source_path : String, destination_path : String) -> StorageTask:
148148 return task
149149
150150
151+ func download (object : String , to_path : String = "" , private : bool = false , options : Dictionary = {
152+ transform = { height = 100 , width = 100 , format = "origin" , resize = "cover" , quality = 80 }
153+ } ) -> StorageTask :
154+ var endpoint : String = _config .supabaseUrl + _rest_endpoint + \
155+ ("authenticated/" if private else "public/" ) + id + "/" + object + \
156+ _get_transform_query (options .get ("transform" , {}))
157+ var task : StorageTask = StorageTask .new ()
158+ var header : PackedStringArray = [_header [0 ] % "application/json" ]
159+ task ._setup (
160+ task .METHODS .DOWNLOAD ,
161+ endpoint ,
162+ header + get_parent ().get_parent ().get_parent ().auth .__get_session_header ()
163+ )
164+ _process_task (task , {download_file = to_path })
165+ return task
166+
167+
151168func create_signed_url (object : String , expires_in : int = 60000 , options : Dictionary = {
152- download = "file" , transform = { format = "origin" , quality = 80 , resize = "cover" , height = 100 , width = 100 }
169+ download = true , transform = { format = "origin" , quality = 80 , resize = "cover" , height = 100 , width = 100 }
153170}) -> StorageTask :
154171 var endpoint : String = _config .supabaseUrl + _rest_endpoint + "sign/" + id + "/" + object
155172 var task : StorageTask = StorageTask .new ()
@@ -160,46 +177,19 @@ func create_signed_url(object : String, expires_in : int = 60000, options: Dicti
160177 header + get_parent ().get_parent ().get_parent ().auth .__get_session_header (),
161178 JSON .stringify ({expiresIn = expires_in , transform = options .get ("transform" , {}) })
162179 )
180+ task .set_meta ("object" , object )
163181 task .set_meta ("options" , options )
164182 task .set_meta ("base_url" , _config .supabaseUrl + _rest_endpoint .replace ("/object/" , "" ))
165183 _process_task (task )
166184 return task
167185
168186
169- func download (object : String , to_path : String = "" , private : bool = false ) -> StorageTask :
170- if not private :
171- var endpoint : String = _config .supabaseUrl + _rest_endpoint + "public/" + id + "/" + object
172- var task : StorageTask = StorageTask .new ()
173- var header : PackedStringArray = [_header [0 ] % "application/json" ]
174- task ._setup (
175- task .METHODS .DOWNLOAD ,
176- endpoint ,
177- header + get_parent ().get_parent ().get_parent ().auth .__get_session_header ()
178- )
179- _process_task (task , {download_file = to_path })
180- return task
181- else :
182- var endpoint : String = _config .supabaseUrl + _rest_endpoint + "authenticated/" + id + "/" + object
183- var task : StorageTask = StorageTask .new ()
184- var header : PackedStringArray = [_header [0 ] % "application/json" ]
185- task ._setup (
186- task .METHODS .DOWNLOAD ,
187- endpoint ,
188- header + get_parent ().get_parent ().get_parent ().auth .__get_session_header ()
189- )
190- _process_task (task , {download_file = to_path })
191- return task
192-
193-
194- func get_public_url (object : String , transform : Dictionary = {
187+
188+ func get_public_url (object : String , options : Dictionary = { transform = {
195189 height = 100 , width = 100 , format = "origin" , resize = "cover" , quality = 80
196- } ) -> String :
190+ } } ) -> String :
197191 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
192+ return url + _get_transform_query (options .get ("transform" , {}))
203193
204194
205195func remove (objects : PackedStringArray ) -> StorageTask :
@@ -215,6 +205,15 @@ func remove(objects : PackedStringArray) -> StorageTask:
215205 return task
216206
217207
208+
209+ func _get_transform_query (transform : Dictionary ) -> String :
210+ var query : String = ""
211+ if not transform .keys ().is_empty ():
212+ query += "?"
213+ for key in transform .keys ():
214+ query += "&%s =%s " % [key , transform .get (key )]
215+ return query
216+
218217func _notification (what : int ) -> void :
219218 if what == NOTIFICATION_INTERNAL_PROCESS :
220219 _internal_process (get_process_delta_time ())
0 commit comments