🔧 chore(.env.example): update example URLs for LANGFLOW_STORE_URL, LANGFLOW_DOWNLOAD_WEBHOOK_URL, and LANGFLOW_LIKE_WEBHOOK_URL to improve clarity and consistency
🔧 chore(store.py): add endpoint to like a component in the store API to enable users to like components 🔧 chore(base.py): add LIKE_WEBHOOK_URL to the settings to allow configuration of the webhook URL for liking components 🔧 chore(service.py): rename webhook_url variable to download_webhook_url for clarity and add like_webhook_url variable to store the LIKE_WEBHOOK_URL from the settings. Update call_webhook method to use download_webhook_url for downloading components and add like_component method to handle liking a component.
This commit is contained in:
parent
343e6e3bfc
commit
d34b551677
4 changed files with 44 additions and 4 deletions
12
.env.example
12
.env.example
|
|
@ -73,5 +73,13 @@ LANGFLOW_SUPERUSER=
|
|||
LANGFLOW_SUPERUSER_PASSWORD=
|
||||
|
||||
# STORE_URL
|
||||
# Example: LANGFLOW_STORE_URL=https://langflow.store
|
||||
LANGFLOW_STORE_URL=
|
||||
# Example: LANGFLOW_STORE_URL=https://api.langflow.store
|
||||
LANGFLOW_STORE_URL=
|
||||
|
||||
# DOWNLOAD_WEBHOOK_URL
|
||||
#
|
||||
LANGFLOW_DOWNLOAD_WEBHOOK_URL=
|
||||
|
||||
# LIKE_WEBHOOK_URL
|
||||
#
|
||||
LANGFLOW_LIKE_WEBHOOK_URL=
|
||||
|
|
@ -189,3 +189,15 @@ def get_list_of_components_liked_by_user(
|
|||
return store_service.get_user_likes(store_api_Key)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=str(exc))
|
||||
|
||||
|
||||
@router.post("/users/likes/{component_id}", response_model=UsersLikesResponse)
|
||||
def like_component(
|
||||
component_id: UUID,
|
||||
store_service: StoreService = Depends(get_store_service),
|
||||
store_api_Key: str = Depends(get_user_store_api_key),
|
||||
):
|
||||
try:
|
||||
return store_service.like_component(store_api_Key, component_id)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=str(exc))
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class Settings(BaseSettings):
|
|||
STORE: Optional[bool] = True
|
||||
STORE_URL: Optional[str] = None
|
||||
DOWNLOAD_WEBHOOK_URL: Optional[str] = None
|
||||
LIKE_WEBHOOK_URL: Optional[str] = None
|
||||
|
||||
@validator("CONFIG_DIR", pre=True, allow_reuse=True)
|
||||
def set_langflow_dir(cls, value):
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ class StoreService(Service):
|
|||
def __init__(self, settings_service: "SettingsService"):
|
||||
self.settings_service = settings_service
|
||||
self.base_url = self.settings_service.settings.STORE_URL
|
||||
self.webhook_url = self.settings_service.settings.DOWNLOAD_WEBHOOK_URL
|
||||
self.download_webhook_url = self.settings_service.settings.DOWNLOAD_WEBHOOK_URL
|
||||
self.like_webhook_url = self.settings_service.settings.LIKE_WEBHOOK_URL
|
||||
self.components_url = f"{self.base_url}/items/components"
|
||||
|
||||
def _get(
|
||||
|
|
@ -200,7 +201,7 @@ class StoreService(Service):
|
|||
}
|
||||
|
||||
component = self._get(url, api_key, params)
|
||||
self.call_webhook(api_key, self.webhook_url, component_id)
|
||||
self.call_webhook(api_key, self.download_webhook_url, component_id)
|
||||
|
||||
return DownloadComponentResponse(**component)
|
||||
|
||||
|
|
@ -243,3 +244,21 @@ class StoreService(Service):
|
|||
}
|
||||
likes = self._get(url, api_key, params)
|
||||
return likes
|
||||
|
||||
def like_component(self, api_key: str, component_id: str) -> bool:
|
||||
# if it returns a list with one id, it means the like was successful
|
||||
# if it returns an int, it means the like was removed
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
response = httpx.post(
|
||||
self.like_webhook_url, json={"component_id": component_id}, headers=headers
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
|
||||
if isinstance(result, list):
|
||||
return True
|
||||
elif isinstance(result, int):
|
||||
return False
|
||||
else:
|
||||
raise ValueError(f"Unexpected result: {result}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue