All checks were successful
Build and Push Docker Image / build (push) Successful in 38s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
780 B
TypeScript
36 lines
780 B
TypeScript
import { existsSync } from 'node:fs';
|
|
import { Hono } from 'hono';
|
|
import { getDb } from '../db/index';
|
|
|
|
const app = new Hono();
|
|
|
|
interface PathInfo {
|
|
prefix: string;
|
|
itemCount: number;
|
|
accessible: boolean;
|
|
}
|
|
|
|
app.get('/', (c) => {
|
|
const db = getDb();
|
|
const rows = db
|
|
.query<{ prefix: string; count: number }, []>(
|
|
`SELECT substr(file_path, 1, instr(substr(file_path, 2), '/') + 1) AS prefix,
|
|
COUNT(*) AS count
|
|
FROM media_items
|
|
WHERE file_path IS NOT NULL AND file_path != ''
|
|
GROUP BY prefix
|
|
ORDER BY prefix`,
|
|
)
|
|
.all();
|
|
|
|
const paths: PathInfo[] = rows.map((r: { prefix: string; count: number }) => ({
|
|
prefix: r.prefix,
|
|
itemCount: r.count,
|
|
accessible: existsSync(r.prefix),
|
|
}));
|
|
|
|
return c.json({ paths });
|
|
});
|
|
|
|
export default app;
|