nhorvath / Pyrebase4

A simple python wrapper for the Firebase API. ⛺
248 stars 61 forks source link

fixed None path breaking in get_url() #72

Closed arham-sayyed closed 2 months ago

arham-sayyed commented 10 months ago

Fixed None Path breaking the code in get_url() function.


Title: Improved download and get_url methods in Storage class


Description:

This PR addresses issues with the download and get_url methods in the Storage class. The changes ensure more consistent behavior and cleaner code.

Changes:

  1. Download Method:

    • Simplified the path stripping logic.
    • Used lstrip for cleaner removal of leading slashes.
  2. Get URL Method:

    • Used ternary condition to simplify the logic.
    • Used lstrip to ensure consistent behavior.

Code Changes:

Before:

def download(self, path, filename, token=None):
    ...
    if path.startswith('/'):
        path = path[1:]
    ...
def get_url(self, token):
    ...
    if path.startswith('/'):
        path = path[1:]
    ...

After:

def download(self, path, filename, token=None):
    ...
    path = path.lstrip('/')
    ...
def get_url(self, token):
    ...
    path = self.path if self.path else ''
    path = path.lstrip('/')
    ...

Impact:

These changes result in a cleaner and more maintainable codebase. They also ensure consistent behavior when manipulating paths in the Storage class.


Credits: @ndesamuelmbah