Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions BunnyCDN/Storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def PutFile(
storage_path=None,
local_upload_file_path=os.getcwd(),
):

"""
This function uploads files to your BunnyCDN storage zone
Parameters
Expand Down Expand Up @@ -200,12 +199,56 @@ def DeleteFile(self, storage_path=""):
"msg": "Object Successfully Deleted",
}

def GetStoragedObjectsList(self, storage_path=None):
def _populate_metadata(self, source_dict, target_dict, field_mappings=None):
"""
Helper function to populate target dictionary with values from source dictionary

Parameters
----------
source_dict : dict
The source dictionary containing the data
target_dict : dict
The target dictionary to populate
field_mappings : dict, optional
Dictionary mapping source keys to target keys
If None, uses direct key mapping

Returns
-------
dict : The populated target dictionary
"""
if field_mappings is None:
field_mappings = {
"Guid": "guid",
"StorageZoneName": "storage_zone_name",
"Path": "path",
"Length": "length",
"LastChanged": "last_changed",
"ServerId": "server_id",
"ArrayNumber": "array_number",
"IsDirectory": "is_directory",
"UserId": "user_id",
"ContentType": "content_type",
"DateCreated": "date_created",
"StorageZoneId": "storage_zone_id",
"Checksum": "checksum",
"ReplicatedZones": "replicated_zones",
}

for source_key, target_key in field_mappings.items():
if source_key in source_dict:
target_dict[target_key] = source_dict[source_key]

return target_dict

def GetStoragedObjectsList(self, storage_path=None, include_metadata=False):
"""
This functions returns a list of files and directories located in given storage_path.
Parameters
----------
storage_path : The directory path that you want to list.
include_metadata : bool, optional
If True, includes additional metadata fields in the response
"""
# to build correct url
if storage_path is not None:
Expand Down Expand Up @@ -234,5 +277,9 @@ def GetStoragedObjectsList(self, storage_path=None):
temp_dict["File_Name"] = dictionary[key]
if key == "ObjectName" and dictionary["IsDirectory"]:
temp_dict["Folder_Name"] = dictionary[key]

if include_metadata:
temp_dict = self._populate_metadata(dictionary, temp_dict)

storage_list.append(temp_dict)
return storage_list
Loading