Skip to content

Commit 14b216e

Browse files
author
Alexandar Plamenov Mechev
committed
feat: Add option to populate file metadata
1 parent f873eda commit 14b216e

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

BunnyCDN/Storage.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,56 @@ def DeleteFile(self, storage_path=""):
200200
"msg": "Object Successfully Deleted",
201201
}
202202

203-
def GetStoragedObjectsList(self, storage_path=None):
203+
def _populate_metadata(self, source_dict, target_dict, field_mappings=None):
204+
"""
205+
Helper function to populate target dictionary with values from source dictionary
206+
207+
Parameters
208+
----------
209+
source_dict : dict
210+
The source dictionary containing the data
211+
target_dict : dict
212+
The target dictionary to populate
213+
field_mappings : dict, optional
214+
Dictionary mapping source keys to target keys
215+
If None, uses direct key mapping
216+
217+
Returns
218+
-------
219+
dict : The populated target dictionary
220+
"""
221+
if field_mappings is None:
222+
field_mappings = {
223+
'Guid': 'guid',
224+
'StorageZoneName': 'storage_zone_name',
225+
'Path': 'path',
226+
'Length': 'length',
227+
'LastChanged': 'last_changed',
228+
'ServerId': 'server_id',
229+
'ArrayNumber': 'array_number',
230+
'IsDirectory': 'is_directory',
231+
'UserId': 'user_id',
232+
'ContentType': 'content_type',
233+
'DateCreated': 'date_created',
234+
'StorageZoneId': 'storage_zone_id',
235+
'Checksum': 'checksum',
236+
'ReplicatedZones': 'replicated_zones'
237+
}
238+
239+
for source_key, target_key in field_mappings.items():
240+
if source_key in source_dict:
241+
target_dict[target_key] = source_dict[source_key]
242+
243+
return target_dict
244+
245+
def GetStoragedObjectsList(self, storage_path=None, include_metadata=False):
204246
"""
205247
This functions returns a list of files and directories located in given storage_path.
206248
Parameters
207249
----------
208250
storage_path : The directory path that you want to list.
251+
include_metadata : bool, optional
252+
If True, includes additional metadata fields in the response
209253
"""
210254
# to build correct url
211255
if storage_path is not None:
@@ -234,5 +278,9 @@ def GetStoragedObjectsList(self, storage_path=None):
234278
temp_dict["File_Name"] = dictionary[key]
235279
if key == "ObjectName" and dictionary["IsDirectory"]:
236280
temp_dict["Folder_Name"] = dictionary[key]
281+
282+
if include_metadata:
283+
temp_dict = self._populate_metadata(dictionary, temp_dict)
284+
237285
storage_list.append(temp_dict)
238286
return storage_list

0 commit comments

Comments
 (0)