🐛 fix(store.py): change variable name 'liked' to 'use_api_key' for better clarity and semantics
🔧 refactor(store.py): remove unnecessary condition for 'status' variable in build_search_filter_conditions method 🔧 refactor(store.py): remove unnecessary condition for 'liked' variable in build_liked_filter method 🔧 refactor(store.py): remove unnecessary condition for 'liked' variable in query_components method 🔧 refactor(store.py): remove unnecessary condition for 'use_api_key' variable in query_components method 🔧 refactor(store.py): remove unnecessary condition for 'store_api_Key' variable in query_components method 🔧 refactor(store.py): add default value for 'use_api_key' parameter in query_components method 🔧 refactor(store.py): remove unnecessary condition for 'liked' variable in query_components method 🔧 🔧 refactor(store
This commit is contained in:
parent
9c78d0afd9
commit
750a24521a
2 changed files with 15 additions and 16 deletions
|
|
@ -4,6 +4,7 @@ from uuid import UUID
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
from httpx import HTTPStatusError
|
from httpx import HTTPStatusError
|
||||||
|
|
||||||
from langflow.services.auth import utils as auth_utils
|
from langflow.services.auth import utils as auth_utils
|
||||||
from langflow.services.database.models.user.user import User
|
from langflow.services.database.models.user.user import User
|
||||||
from langflow.services.deps import get_settings_service, get_store_service
|
from langflow.services.deps import get_settings_service, get_store_service
|
||||||
|
|
@ -127,7 +128,7 @@ async def get_components(
|
||||||
limit=limit,
|
limit=limit,
|
||||||
sort=sort,
|
sort=sort,
|
||||||
filter_conditions=filter_conditions,
|
filter_conditions=filter_conditions,
|
||||||
liked=liked,
|
use_api_key=liked or filter_by_user,
|
||||||
)
|
)
|
||||||
except HTTPStatusError as exc:
|
except HTTPStatusError as exc:
|
||||||
if exc.response.status_code == 403:
|
if exc.response.status_code == 403:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ from uuid import UUID
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from httpx import HTTPError, HTTPStatusError
|
from httpx import HTTPError, HTTPStatusError
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from langflow.services.base import Service
|
from langflow.services.base import Service
|
||||||
from langflow.services.store.schema import (
|
from langflow.services.store.schema import (
|
||||||
CreateComponentResponse,
|
CreateComponentResponse,
|
||||||
|
|
@ -12,7 +14,6 @@ from langflow.services.store.schema import (
|
||||||
StoreComponentCreate,
|
StoreComponentCreate,
|
||||||
)
|
)
|
||||||
from langflow.services.store.utils import process_tags_for_post
|
from langflow.services.store.utils import process_tags_for_post
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from langflow.services.settings.service import SettingsService
|
from langflow.services.settings.service import SettingsService
|
||||||
|
|
@ -150,7 +151,7 @@ class StoreService(Service):
|
||||||
search_conditions = self.build_search_filter_conditions(search)
|
search_conditions = self.build_search_filter_conditions(search)
|
||||||
filter_conditions.append(search_conditions)
|
filter_conditions.append(search_conditions)
|
||||||
|
|
||||||
if status:
|
if status is not None:
|
||||||
filter_conditions.append({"status": {"_eq": status}})
|
filter_conditions.append({"status": {"_eq": status}})
|
||||||
|
|
||||||
if tags:
|
if tags:
|
||||||
|
|
@ -171,20 +172,17 @@ class StoreService(Service):
|
||||||
filter_conditions.append({"user_created": {"_eq": user_data["id"]}})
|
filter_conditions.append({"user_created": {"_eq": user_data["id"]}})
|
||||||
elif filter_by_user and not store_api_Key:
|
elif filter_by_user and not store_api_Key:
|
||||||
raise ValueError("You must provide an API key to filter your components")
|
raise ValueError("You must provide an API key to filter your components")
|
||||||
|
else:
|
||||||
|
filter_conditions.append({"status": {"_in": ["public", "Public"]}})
|
||||||
|
|
||||||
return filter_conditions
|
return filter_conditions
|
||||||
|
|
||||||
def build_liked_filter(self, liked: bool, api_key: Optional[str] = None):
|
def build_liked_filter(self, liked: bool, api_key: Optional[str] = None):
|
||||||
if liked and not api_key:
|
user_data = user_data_var.get()
|
||||||
raise ValueError("No API key provided")
|
# params["filter"] = json.dumps({"user_created": {"_eq": user_data["id"]}})
|
||||||
|
if not user_data:
|
||||||
if liked and api_key:
|
raise ValueError("No user data")
|
||||||
user_data = user_data_var.get()
|
return {"liked_by": {"_eq": user_data["id"]}}
|
||||||
# params["filter"] = json.dumps({"user_created": {"_eq": user_data["id"]}})
|
|
||||||
if not user_data:
|
|
||||||
raise ValueError("No user data")
|
|
||||||
return {"liked_by": {"_eq": user_data["id"]}}
|
|
||||||
else:
|
|
||||||
return {"status": {"_in": ["public", "Public"]}}
|
|
||||||
|
|
||||||
async def query_components(
|
async def query_components(
|
||||||
self,
|
self,
|
||||||
|
|
@ -194,7 +192,7 @@ class StoreService(Service):
|
||||||
limit: int = 15,
|
limit: int = 15,
|
||||||
fields: Optional[List[str]] = None,
|
fields: Optional[List[str]] = None,
|
||||||
filter_conditions: Optional[List[Dict[str, Any]]] = None,
|
filter_conditions: Optional[List[Dict[str, Any]]] = None,
|
||||||
liked: Optional[bool] = False,
|
use_api_key: Optional[bool] = False,
|
||||||
) -> List[ListComponentResponse]:
|
) -> List[ListComponentResponse]:
|
||||||
params: Dict[str, Any] = {
|
params: Dict[str, Any] = {
|
||||||
"page": page,
|
"page": page,
|
||||||
|
|
@ -211,7 +209,7 @@ class StoreService(Service):
|
||||||
|
|
||||||
if filter_conditions:
|
if filter_conditions:
|
||||||
params["filter"] = json.dumps({"_and": filter_conditions})
|
params["filter"] = json.dumps({"_and": filter_conditions})
|
||||||
if not liked:
|
if not use_api_key:
|
||||||
# If not liked, this means we are getting public components
|
# If not liked, this means we are getting public components
|
||||||
# so we don't need to risk passing an invalid api_key
|
# so we don't need to risk passing an invalid api_key
|
||||||
# and getting 401
|
# and getting 401
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue