* @brief Returns the full catalog (or one kind's slice) of bundled scripts. */
| 172 | * @brief Returns the full catalog (or one kind's slice) of bundled scripts. |
| 173 | */ |
| 174 | API::CommandResponse API::Handlers::ScriptsHandler::list(const QString& id, |
| 175 | const QJsonObject& params) |
| 176 | { |
| 177 | const auto kindFilter = params.value(QStringLiteral("kind")).toString(); |
| 178 | |
| 179 | QJsonArray entries; |
| 180 | QJsonArray kindList; |
| 181 | int total = 0; |
| 182 | |
| 183 | for (const auto& k : kinds()) { |
| 184 | if (!kindFilter.isEmpty() && k.id != kindFilter) |
| 185 | continue; |
| 186 | |
| 187 | QJsonObject kobj; |
| 188 | kobj[QStringLiteral("id")] = k.id; |
| 189 | kobj[QStringLiteral("description")] = k.description; |
| 190 | kindList.append(kobj); |
| 191 | |
| 192 | const auto manifest = loadManifest(k); |
| 193 | for (const auto& v : manifest) { |
| 194 | const auto entry = v.toObject(); |
| 195 | entries.append(summarizeEntry(k, entry)); |
| 196 | total += 1; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if (!kindFilter.isEmpty() && kindList.isEmpty()) { |
| 201 | return CommandResponse::makeError( |
| 202 | id, |
| 203 | ErrorCode::InvalidParam, |
| 204 | QStringLiteral("Unknown script kind: %1. Valid kinds: painter, " |
| 205 | "frame_parser_js, frame_parser_lua, transform_js, " |
| 206 | "transform_lua, output_widget_js") |
| 207 | .arg(kindFilter)); |
| 208 | } |
| 209 | |
| 210 | QJsonObject result; |
| 211 | result[QStringLiteral("kinds")] = kindList; |
| 212 | result[QStringLiteral("entries")] = entries; |
| 213 | result[QStringLiteral("total")] = total; |
| 214 | result[QStringLiteral("hint")] = |
| 215 | QStringLiteral("Each entry has {id, name, kind, datasetCount?}. Read the body with " |
| 216 | "scripts.get {kind, id} -- the body is the exact text you can pass to " |
| 217 | "the corresponding setCode endpoint after light edits."); |
| 218 | return CommandResponse::makeSuccess(id, result); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @brief Returns the body of one script (UTF-8 text). |
no test coverage detected