Exemple #1
0
    def validate_url(self, short_url: str, long_url: str, custom_salt: str = None):
        random_id = short_url.split("/")[-1]

        url = Url()
        url.random_id = random_id

        url_transactions = self.node_manager.retrieve_transactions(address=url.address)

        if not url_transactions:
            return False

        for url_transaction in url_transactions:
            url_to_validate = Url(custom_salt=custom_salt)
            url_to_validate.from_message(url_transaction.message)
            if url_to_validate.long_url == long_url:
                if url_to_validate.is_valid:
                    return True

        return False
Exemple #2
0
    def get_url(self, short_url: str):
        random_id = short_url.strip('/').split("/")[-1]

        url = Url(long_url=None, metadata=None)
        url.random_id = random_id

        url_transactions = self.node_manager.retrieve_transactions(address=url.address)

        if not url_transactions:
            return None

        message = dict()

        for url in url_transactions:
            if url.is_valid:
                message = url.message
            else:
                message = url.message

        return message