GET /api/project-health?name=X — checks db integrity */
| 1217 | |
| 1218 | /* GET /api/project-health?name=X — checks db integrity */ |
| 1219 | static void handle_project_health(cbm_http_conn_t *c, const cbm_http_req_t *req) { |
| 1220 | char name[256] = {0}; |
| 1221 | if (!cbm_http_query_param(req->query, "name", name, (int)sizeof(name)) || name[0] == '\0') { |
| 1222 | cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"missing name\"}"); |
| 1223 | return; |
| 1224 | } |
| 1225 | |
| 1226 | char db_path[1024]; |
| 1227 | db_path_for_project(name, db_path, sizeof(db_path)); |
| 1228 | |
| 1229 | if (!cbm_file_exists(db_path)) { |
| 1230 | cbm_http_replyf(c, 200, g_cors_json, "{\"status\":\"missing\"}"); |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | cbm_store_t *store = cbm_store_open_path_query(db_path); |
| 1235 | if (!store) { |
| 1236 | cbm_http_replyf(c, 200, g_cors_json, "{\"status\":\"corrupt\",\"reason\":\"cannot open\"}"); |
| 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | int node_count = cbm_store_count_nodes(store, name); |
| 1241 | int edge_count = cbm_store_count_edges(store, name); |
| 1242 | cbm_store_close(store); |
| 1243 | |
| 1244 | int64_t size = cbm_file_size(db_path); |
| 1245 | |
| 1246 | cbm_http_replyf(c, 200, g_cors_json, |
| 1247 | "{\"status\":\"healthy\",\"nodes\":%d,\"edges\":%d,\"size_bytes\":%lld}", |
| 1248 | node_count, edge_count, (long long)size); |
| 1249 | } |
| 1250 | |
| 1251 | /* ── Handle GET /api/layout ───────────────────────────────────── */ |
| 1252 |
no test coverage detected