diff --git a/src/backend/langflow/api/v1/store.py b/src/backend/langflow/api/v1/store.py index 19cabe3df..12fa47944 100644 --- a/src/backend/langflow/api/v1/store.py +++ b/src/backend/langflow/api/v1/store.py @@ -4,6 +4,7 @@ from uuid import UUID from fastapi import APIRouter, Depends, HTTPException, Query from httpx import HTTPStatusError + from langflow.services.auth import utils as auth_utils from langflow.services.database.models.user.user import User from langflow.services.deps import get_settings_service, get_store_service @@ -227,7 +228,7 @@ async def like_component( ): try: result = await store_service.like_component(store_api_Key, str(component_id)) - likes_count = await store_service.get_component_likes_count(store_api_Key, str(component_id)) + likes_count = await store_service.get_component_likes_count(str(component_id)) return UsersLikesResponse(likes_count=likes_count, liked_by_user=result) except Exception as exc: diff --git a/src/backend/langflow/services/store/service.py b/src/backend/langflow/services/store/service.py index 66fd0895d..99528c80c 100644 --- a/src/backend/langflow/services/store/service.py +++ b/src/backend/langflow/services/store/service.py @@ -1,5 +1,5 @@ import json -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional from uuid import UUID import httpx @@ -77,7 +77,7 @@ class StoreService(Service): async def _get( self, url: str, api_key: Optional[str] = None, params: Optional[Dict[str, Any]] = None - ) -> Union[List[Dict[str, Any]], Dict[str, Any]]: + ) -> List[Dict[str, Any]]: """Utility method to perform GET requests.""" if api_key: headers = {"Authorization": f"Bearer {api_key}"} @@ -91,7 +91,10 @@ class StoreService(Service): raise exc except Exception as exc: raise ValueError(f"GET failed: {exc}") - return response.json()["data"] + result = response.json()["data"] + if isinstance(result, dict): + return [result] + return result async def call_webhook(self, api_key: str, webhook_url: str, component_id: UUID) -> None: # The webhook is a POST request with the data in the body @@ -317,16 +320,16 @@ class StoreService(Service): likes = await self._get(url, api_key, params) return likes - async def get_component_likes_count(self, api_key: str, component_id: str) -> int: + async def get_component_likes_count(self, component_id: str) -> int: url = f"{self.components_url}/{component_id}" params = { "fields": ",".join(["id", "count(liked_by)"]), } - result = await self._get(url, api_key, params) + result = await self._get(url, api_key=None, params=params) if len(result) == 0: raise ValueError("Component not found") - likes = result["liked_by_count"] + likes = result[0]["liked_by_count"] # likes_by_count is a string # try to convert it to int try: