🪻 distributed transcription service thistle.dunkirk.sh

feat: improve health endpoint

dunkirk.sh fdedda45 58f6dc09

verified
+2 -2
src/components/transcription.ts
···
async checkHealth() {
try {
-
const response = await fetch("/api/transcriptions/health");
+
const response = await fetch("/api/health");
if (response.ok) {
const data = await response.json();
-
this.serviceAvailable = data.available;
+
this.serviceAvailable = data.status === "healthy";
} else {
this.serviceAvailable = false;
}
+3 -1
src/index.test.README.md
···
- `PUT /api/passkeys/:id` - Update passkey name
- `DELETE /api/passkeys/:id` - Delete passkey
+
### Health Endpoint
+
- `GET /api/health` - Check service health (database, whisper, storage)
+
### Transcription Endpoints
-
- `GET /api/transcriptions/health` - Check transcription service health
- `GET /api/transcriptions` - List user transcriptions
- `POST /api/transcriptions` - Upload audio file and start transcription
- `GET /api/transcriptions/:id` - Get transcription details
+13 -7
src/index.test.ts
···
beforeAll(async () => {
try {
-
const response = await fetch(`${BASE_URL}/api/transcriptions/health`, {
+
const response = await fetch(`${BASE_URL}/api/health`, {
signal: AbortSignal.timeout(1000),
});
serverAvailable = response.ok || response.status === 404;
···
});
});
-
describe("API Endpoints - Transcriptions", () => {
-
describe("GET /api/transcriptions/health", () => {
+
describe("API Endpoints - Health", () => {
+
describe("GET /api/health", () => {
serverTest(
-
"should return transcription service health status",
+
"should return service health status with details",
async () => {
-
const response = await fetch(`${BASE_URL}/api/transcriptions/health`);
+
const response = await fetch(`${BASE_URL}/api/health`);
expect(response.status).toBe(200);
const data = await response.json();
-
expect(data).toHaveProperty("available");
-
expect(typeof data.available).toBe("boolean");
+
expect(data).toHaveProperty("status");
+
expect(data).toHaveProperty("timestamp");
+
expect(data).toHaveProperty("services");
+
expect(data.services).toHaveProperty("database");
+
expect(data.services).toHaveProperty("whisper");
+
expect(data.services).toHaveProperty("storage");
},
);
});
+
});
+
describe("API Endpoints - Transcriptions", () => {
describe("GET /api/transcriptions", () => {
serverTest("should return user transcriptions", async () => {
// Register user
+10 -5
src/index.ts
···
},
},
-
"/api/transcriptions/health": {
+
"/api/health": {
GET: async () => {
const health = {
status: "healthy",
···
// Check storage (uploads and transcripts directories)
try {
-
const uploadsDir = Bun.file("./uploads");
-
const transcriptsDir = Bun.file("./transcripts");
-
const uploadsExists = await uploadsDir.exists();
-
const transcriptsExists = await transcriptsDir.exists();
+
const fs = await import("node:fs/promises");
+
const uploadsExists = await fs
+
.access("./uploads")
+
.then(() => true)
+
.catch(() => false);
+
const transcriptsExists = await fs
+
.access("./transcripts")
+
.then(() => true)
+
.catch(() => false);
health.services.storage = uploadsExists && transcriptsExists;
if (!health.services.storage) {
health.status = "unhealthy";