void ScriptService::getImpl(const QByteArray& operation, const APIParameters ¶meters, APIServiceResponse &response) { if(operation=="list") { //list all scripts, this should be thread safe QStringList allScripts = scriptMgr->getScriptList(); response.writeJSON(QJsonDocument(QJsonArray::fromStringList(allScripts))); } else if (operation == "info") { if(parameters.contains("id")) { //retrieve detail about a single script QString scriptId = QString::fromUtf8(parameters.value("id")); if(parameters.contains("html")) { QString html = scriptMgr->getHtmlDescription(scriptId, false); response.setHeader("Content-Type","text/html; charset=UTF-8"); response.setData(wrapHtml(html, scriptId).toUtf8()); return; } QJsonObject obj; //if the script name is wrong, this will return empty strings obj.insert("id",scriptId); QString d = scriptMgr->getName(scriptId).trimmed(); obj.insert("name",d); obj.insert("name_localized", StelTranslator::globalTranslator->qtranslate(d)); d = scriptMgr->getDescription(scriptId).trimmed(); obj.insert("description",d); obj.insert("description_localized", StelTranslator::globalTranslator->qtranslate(d)); obj.insert("author",scriptMgr->getAuthor(scriptId).trimmed()); obj.insert("license",scriptMgr->getLicense(scriptId).trimmed()); //shortcut often causes a large delay because the whole file gets searched, and it is usually missing, so we ignore it //obj.insert("shortcut",scriptMgr->getShortcut(scriptId)); response.writeJSON(QJsonDocument(obj)); } else { response.writeRequestError("need parameter: id"); } } else if(operation == "status") { //generic script status QJsonObject obj; obj.insert("scriptIsRunning",scriptMgr->scriptIsRunning()); obj.insert("runningScriptId",scriptMgr->runningScriptId()); response.writeJSON(QJsonDocument(obj)); } else { //TODO some sort of service description? response.writeRequestError("unsupported operation. GET: list,info,status POST: run,stop"); } }