From 2f456736948c7af0cbcacfc4d84fec10904be4be Mon Sep 17 00:00:00 2001 From: Yansong Zhang <916125788@qq.com> Date: Mon, 13 Oct 2025 14:53:20 +0800 Subject: [PATCH] fix: linter --- api/controllers/console/explore/banner.py | 4 ++-- api/controllers/console/explore/trial.py | 16 ++++++++-------- api/controllers/console/explore/wraps.py | 2 ++ api/services/recommended_app_service.py | 9 +++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/api/controllers/console/explore/banner.py b/api/controllers/console/explore/banner.py index e44f8f8930..da306fbc9d 100644 --- a/api/controllers/console/explore/banner.py +++ b/api/controllers/console/explore/banner.py @@ -17,10 +17,10 @@ class BannerApi(Resource): # Build base query for enabled banners base_query = db.session.query(ExporleBanner).where(ExporleBanner.status == "enabled") - + # Try to get banners in the requested language banners = base_query.where(ExporleBanner.language == language).order_by(ExporleBanner.sort).all() - + # Fallback to en-US if no banners found and language is not en-US if not banners and language != "en-US": banners = base_query.where(ExporleBanner.language == "en-US").order_by(ExporleBanner.sort).all() diff --git a/api/controllers/console/explore/trial.py b/api/controllers/console/explore/trial.py index c3acd9db06..afa3dedf43 100644 --- a/api/controllers/console/explore/trial.py +++ b/api/controllers/console/explore/trial.py @@ -156,11 +156,11 @@ class TrialChatApi(TrialAppResource): try: if not isinstance(current_user, Account): raise ValueError("current_user must be an Account instance") - + # Get IDs before they might be detached from session app_id = app_model.id user_id = current_user.id - + response = AppGenerateService.generate( app_model=app_model, user=current_user, args=args, invoke_from=InvokeFrom.EXPLORE, streaming=True ) @@ -237,11 +237,11 @@ class TrialChatAudioApi(TrialAppResource): try: if not isinstance(current_user, Account): raise ValueError("current_user must be an Account instance") - + # Get IDs before they might be detached from session app_id = app_model.id user_id = current_user.id - + response = AudioService.transcript_asr(app_model=app_model, file=file, end_user=None) RecommendedAppService.add_trial_app_record(app_id, user_id) return response @@ -288,11 +288,11 @@ class TrialChatTextApi(TrialAppResource): voice = args.get("voice", None) if not isinstance(current_user, Account): raise ValueError("current_user must be an Account instance") - + # Get IDs before they might be detached from session app_id = app_model.id user_id = current_user.id - + response = AudioService.transcript_tts(app_model=app_model, text=text, voice=voice, message_id=message_id) RecommendedAppService.add_trial_app_record(app_id, user_id) return response @@ -343,11 +343,11 @@ class TrialCompletionApi(TrialAppResource): try: if not isinstance(current_user, Account): raise ValueError("current_user must be an Account instance") - + # Get IDs before they might be detached from session app_id = app_model.id user_id = current_user.id - + response = AppGenerateService.generate( app_model=app_model, user=current_user, args=args, invoke_from=InvokeFrom.EXPLORE, streaming=streaming ) diff --git a/api/controllers/console/explore/wraps.py b/api/controllers/console/explore/wraps.py index 150dd40b80..008a47028f 100644 --- a/api/controllers/console/explore/wraps.py +++ b/api/controllers/console/explore/wraps.py @@ -87,6 +87,8 @@ def trial_app_required(view: Callable[Concatenate[App, P], R] | None = None): if app is None: raise TrialAppNotAllowed() + assert isinstance(current_user, Account) + account_trial_app_record = ( db.session.query(AccountTrialAppRecord) .where(AccountTrialAppRecord.account_id == current_user.id, AccountTrialAppRecord.app_id == app_id) diff --git a/api/services/recommended_app_service.py b/api/services/recommended_app_service.py index be6e94a526..6b211a5632 100644 --- a/api/services/recommended_app_service.py +++ b/api/services/recommended_app_service.py @@ -60,10 +60,11 @@ class RecommendedAppService: :param app_id: app id :return: """ - account_trial_app_record = db.session.query(AccountTrialAppRecord).where( - AccountTrialAppRecord.app_id == app_id, - AccountTrialAppRecord.account_id == account_id - ).first() + account_trial_app_record = ( + db.session.query(AccountTrialAppRecord) + .where(AccountTrialAppRecord.app_id == app_id, AccountTrialAppRecord.account_id == account_id) + .first() + ) if account_trial_app_record: account_trial_app_record.count += 1 db.session.commit()