def services_operations(action): j = request.json if action == 'available': return jsonify(services.listServices()) if action == 'list': return jsonify(services.getServices()) if action == 'add' and j is not None: if 'name' in j and 'id' in j: old = services.hasReadyServices() svcid = services.addService(int(j['id']), j['name']) if old != services.hasReadyServices(): slideshow.trigger() return jsonify({'id': svcid}) if action == 'remove' and j is not None: if 'id' in j: services.deleteService(j['id']) slideshow.trigger( ) # Always trigger since we don't know who was on-screen return jsonify({'status': 'Done'}) if action == 'rename' and j is not None: if 'name' in j and 'id' in j: if services.renameService(j['id'], j['name']): return jsonify({'status': 'Done'}) if request.url.endswith('/config/fields'): return jsonify(services.getServiceConfigurationFields(id)) if request.url.endswith('/config'): if request.method == 'POST' and j is not None and 'config' in j: if services.setServiceConfiguration(id, j['config']): return 'Configuration saved', 200 elif request.method == 'GET': return jsonify(services.getServiceConfiguration(id)) abort(500)
def cfg_keywords(service, index=None): if request.method == 'GET': if 'source' in request.url: return redirect(services.sourceServiceKeywords(service, index)) else: return jsonify({'keywords': services.getServiceKeywords(service)}) elif request.method == 'POST' and request.json is not None: result = True if 'id' not in request.json: hadKeywords = services.hasKeywords() result = services.addServiceKeywords(service, request.json['keywords']) if result['error'] is not None: result['status'] = False else: result['status'] = True if hadKeywords != services.hasKeywords(): # Make slideshow show the change immediately, we have keywords slideshow.trigger() else: if not services.removeServiceKeywords(service, request.json['id']): result = {'status': False, 'error': 'Unable to remove keyword'} else: # Trigger slideshow, we have removed some keywords slideshow.trigger() return jsonify(result) abort(500)
def oauth_callback(): # Figure out who should get this result... old = services.hasReadyServices() if services.oauthCallback(request): # Request handled if old != services.hasReadyServices(): slideshow.trigger() return redirect('/') else: abort(500)