From 9905d0f49600c64a9ece26730fce30cf2484fe32 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 16 Jul 2026 20:30:50 +0000 Subject: [PATCH] Add query compatibility parameter --- README.md | 4 ++++ src/app.ts | 6 +++++- tests/app.test.js | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bad62e1..47c8684 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ Tiny API that clones a Git repo and counts its non-empty lines of code. - `GET /health` - Health plus queue/cache stats. +You can also pass `query=` as a compatibility alias for `repo`. +This is considered unsafe and discouraged because the name is too generic and easier to misuse or collide with upstream tooling. +Prefer `repo` unless you explicitly need legacy compatibility. + ## Auth No auth by default. If `API_KEY` is set, send it as either: diff --git a/src/app.ts b/src/app.ts index 1ec3745..f78ab33 100644 --- a/src/app.ts +++ b/src/app.ts @@ -71,7 +71,11 @@ export function createApp(config: RuntimeConfig, deps: AppDependencies) { } function readCountRequest(req: Request): CountRequest { - const repo = typeof req.query.repo === "string" ? req.query.repo.trim() : ""; + const repo = typeof req.query.repo === "string" + ? req.query.repo.trim() + : typeof req.query.query === "string" + ? req.query.query.trim() + : ""; if (!repo) { throw new HttpError(400, "Missing repo query parameter"); } diff --git a/tests/app.test.js b/tests/app.test.js index e904e3a..06649e9 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -45,6 +45,30 @@ test("GET /loc returns count metadata", async () => { assert.equal(response.body.languages[0].language, "TypeScript"); }); +test("GET /loc accepts query as a repo alias", async () => { + const app = createApp(baseConfig, { + getHealth: () => ({ cacheEntries: 0, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }), + getPublicKey: async () => "ssh-ed25519 AAAA", + getDefaultKeyName: () => "loc_via_git_ed25519", + count: async (requestInput) => ({ + repo: requestInput.repo, + ref: requestInput.ref, + sshKey: requestInput.sshKey, + cached: false, + lineCount: 2, + fileCount: 1, + languages: [{ language: "Plain Text", files: 1, lines: 2 }], + scannedAt: "2026-01-01T00:00:00.000Z", + durationMs: 10 + }) + }); + + const response = await request(app).get("/loc?query=https://example.com/query.git"); + + assert.equal(response.status, 200); + assert.equal(response.body.repo, "https://example.com/query.git"); +}); + test("GET /ssh/public-key returns text without auth", async () => { const app = createApp({ ...baseConfig, apiKey: "secret" }, { getHealth: () => ({ cacheEntries: 0, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }),