@@ -45,7 +45,6 @@ const _rest_endpoint : String = "/storage/v1/object/"
4545
4646var _config : Dictionary
4747var _header : PackedStringArray = ["Content-Type: %s " , "Content-Disposition: attachment" ]
48- var _bearer : PackedStringArray = ["Authorization: Bearer %s " ]
4948
5049var _pooled_tasks : Array = []
5150
@@ -63,23 +62,23 @@ var _response_code : int
6362var id : String
6463
6564
66- func _init (id : String , config : Dictionary , bearer : PackedStringArray ) -> void :
65+ func _init (id : String , config : Dictionary ) -> void :
6766 _config = config
6867 self .id = id
69- _bearer = bearer
7068 name = "Bucket_" + id
7169 set_process_internal (false )
7270
7371
7472func list (prefix : String = "" , limit : int = 100 , offset : int = 0 , sort_by : Dictionary = {column = "name" , order = "asc" } ) -> StorageTask :
75- var endpoint : String = _config .supabaseUrl + _rest_endpoint + "list/" + id
73+ var endpoint : String = _config .supabaseUrl + _rest_endpoint + "/ list/" + id
7674 var task : StorageTask = StorageTask .new ()
7775 var header : PackedStringArray = [_header [0 ] % "application/json" ]
7876 task ._setup (
7977 task .METHODS .LIST_OBJECTS ,
8078 endpoint ,
81- header + _bearer ,
82- JSON .stringify ({prefix = prefix , limit = limit , offset = offset , sort_by = sort_by }))
79+ header + get_parent ().get_parent ().get_parent ().auth .__get_session_header (),
80+ JSON .stringify ({ prefix = prefix , limit = limit , offset = offset , sortBy = sort_by })
81+ )
8382 _process_task (task )
8483 return task
8584
@@ -94,15 +93,15 @@ func upload(object : String, file_path : String, upsert : bool = false) -> Stora
9493 task .complete ({})
9594 return task
9695 var header : PackedStringArray = [_header [0 ] % MIME_TYPES .get (file_path .get_extension (), "application/octet-stream" )]
97- header .append ("Content-Length: %s " % file .get_len ())
96+ header .append ("Content-Length: %s " % file .get_length ())
9897 header .append ("x-upsert: %s " % upsert )
9998 task .completed .connect (_on_task_completed )
10099 task ._setup (
101100 task .METHODS .UPLOAD_OBJECT ,
102101 endpoint ,
103- header + _bearer
102+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header ()
104103 )
105- task .bytepayload = file .get_buffer (file .get_len ())
104+ task .bytepayload = file .get_buffer (file .get_length ())
106105
107106 _current_task = task
108107 set_process_internal (requesting_raw )
@@ -127,7 +126,7 @@ func update(bucket_path : String, file_path : String) -> StorageTask:
127126 task ._setup (
128127 task .METHODS .UPDATE_OBJECT ,
129128 endpoint ,
130- header + _bearer
129+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header ()
131130 )
132131 task .bytepayload = file .get_buffer (file .get_len ())
133132
@@ -144,7 +143,7 @@ func move(source_path : String, destination_path : String) -> StorageTask:
144143 task ._setup (
145144 task .METHODS .MOVE_OBJECT ,
146145 endpoint ,
147- header + _bearer ,
146+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header () ,
148147 JSON .stringify ({bucketId = id , sourceKey = source_path , destinationKey = destination_path }))
149148 _process_task (task )
150149 return task
@@ -157,7 +156,7 @@ func create_signed_url(object : String, expires_in : int = 60000) -> StorageTask
157156 task ._setup (
158157 task .METHODS .CREATE_SIGNED_URL ,
159158 endpoint ,
160- header + _bearer ,
159+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header () ,
161160 JSON .stringify ({expiresIn = expires_in })
162161 )
163162 _process_task (task )
@@ -172,7 +171,7 @@ func download(object : String, to_path : String = "", private : bool = false) ->
172171 task ._setup (
173172 task .METHODS .DOWNLOAD ,
174173 endpoint ,
175- header + _bearer
174+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header ()
176175 )
177176 _process_task (task , {download_file = to_path })
178177 return task
@@ -183,7 +182,7 @@ func download(object : String, to_path : String = "", private : bool = false) ->
183182 task ._setup (
184183 task .METHODS .DOWNLOAD ,
185184 endpoint ,
186- header + _bearer
185+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header ()
187186 )
188187 _process_task (task , {download_file = to_path })
189188 return task
@@ -200,7 +199,7 @@ func remove(objects : PackedStringArray) -> StorageTask:
200199 task ._setup (
201200 task .METHODS .REMOVE ,
202201 endpoint ,
203- header + _bearer ,
202+ header + get_parent (). get_parent (). get_parent (). auth . __get_session_header () ,
204203 JSON .stringify ({prefixes = objects }) if objects .size () > 1 else "" )
205204 _process_task (task )
206205 return task
@@ -225,7 +224,7 @@ func _internal_process(_delta : float) -> void:
225224 _http_client .poll ()
226225
227226 HTTPClient .STATUS_CONNECTED :
228- var err : int = _http_client .request_raw (task ._method , task ._endpoint .replace (_config .supabaseUrl , "" ), task ._headers , task ._bytepayload )
227+ var err : int = _http_client .request_raw (task ._method , task ._endpoint .replace (_config .supabaseUrl , "" ), task ._headers , task .bytepayload )
229228 if err :
230229 task .error = SupabaseStorageError .new ({statusCode = HTTPRequest .RESULT_CONNECTION_ERROR })
231230 _on_task_completed (task )
@@ -280,10 +279,9 @@ func _process_task(task : StorageTask, _params : Dictionary = {}) -> void:
280279
281280# .............. HTTPRequest completed
282281func _on_task_completed (task : StorageTask ) -> void :
283- if task ._handler : task ._handler .queue_free ()
284282 if requesting_raw :
285283 _clear_raw_request ()
286- if task .data != null and not task .data .empty ():
284+ if task .data != null and not task .data .is_empty ():
287285 match task ._code :
288286 task .METHODS .LIST_OBJECTS : emit_signal ("listed_objects" , task .data )
289287 task .METHODS .UPLOAD_OBJECT : emit_signal ("uploaded_object" , task .data )
0 commit comments