Skip to content

Commit

Permalink
Apps endpoint minor improvements (#1321)
Browse files Browse the repository at this point in the history
- [x] Increase/decrease install count only if not private
- [x] Clear apps cache if public approved app is updated
  • Loading branch information
beastoin authored Nov 15, 2024
2 parents e6d948d + f0de739 commit 79f8916
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions backend/routers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def update_app(app_id: str, app_data: str = Form(...), file: UploadFile = File(N
data['image'] = img_url
data['updated_at'] = datetime.now(timezone.utc)
update_app_in_db(data)
if plugin['approved'] and (plugin['private'] is None or plugin['private'] is False):
delete_generic_cache('get_public_approved_apps_data')
return {'status': 'ok'}


Expand Down Expand Up @@ -189,7 +191,8 @@ def enable_app(app_id: str, uid: str = Depends(auth.get_current_user_uid)):
print('enable_app_endpoint', res.status_code, res.content)
if res.status_code != 200 or not res.json().get('is_setup_completed', False):
raise HTTPException(status_code=400, detail='App setup is not completed')
increase_plugin_installs_count(app_id)
if app.private is None or app.private is False:
increase_plugin_installs_count(app_id)
enable_plugin(uid, app_id)
return {'status': 'ok'}

Expand All @@ -204,7 +207,8 @@ def disable_app(app_id: str, uid: str = Depends(auth.get_current_user_uid)):
if app.private and app.uid != uid:
raise HTTPException(status_code=403, detail='You are not authorized to perform this action')
disable_plugin(uid, app_id)
decrease_plugin_installs_count(app_id)
if app.private is None or app.private is False:
decrease_plugin_installs_count(app_id)
return {'status': 'ok'}


Expand Down
6 changes: 4 additions & 2 deletions backend/routers/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def enable_plugin_endpoint(plugin_id: str, uid: str = Depends(auth.get_current_u
print('enable_plugin_endpoint', res.status_code, res.content)
if res.status_code != 200 or not res.json().get('is_setup_completed', False):
raise HTTPException(status_code=400, detail='Plugin setup is not completed')
increase_plugin_installs_count(plugin_id)
if plugin.private is not None and plugin.private is False:
increase_plugin_installs_count(plugin_id)
enable_plugin(uid, plugin_id)
return {'status': 'ok'}

Expand All @@ -48,7 +49,8 @@ def disable_plugin_endpoint(plugin_id: str, uid: str = Depends(auth.get_current_
if not plugin:
raise HTTPException(status_code=404, detail='App not found')
disable_plugin(uid, plugin_id)
decrease_plugin_installs_count(plugin_id)
if plugin.private is not None and plugin.private is False:
decrease_plugin_installs_count(plugin_id)
return {'status': 'ok'}


Expand Down

0 comments on commit 79f8916

Please sign in to comment.