Files
SnapOtter/apps/api/src/routes/tools/popular.ts
T
SnapOtter f387e98fff feat: tool-first workflow polish -- fix tests, lint cleanup
- Remove obsolete fullscreen redirect test (route deleted in Task 3)
- Update dropzone test strings to match new i18n values
- Fix categories count in i18n locale test (12 -> 24)
- Add chart-maker to no-dropzone exempt list in tool-registry test
- Auto-fix import ordering (Biome) in popular tools route and landing config
2026-06-14 19:44:58 +08:00

43 lines
964 B
TypeScript

import { sql } from "drizzle-orm";
import type { FastifyInstance } from "fastify";
import { db } from "../../db/index.js";
import { jobs } from "../../db/schema.js";
const DEFAULT_POPULAR = [
"resize",
"crop",
"compress",
"convert",
"remove-background",
"upscale",
"merge-pdf",
"watermark-text",
"compress-video",
"trim-video",
"convert-audio",
"compress-pdf",
];
export async function registerPopularTools(app: FastifyInstance) {
app.get("/api/v1/tools/popular", async () => {
try {
const rows = await db
.select({
toolId: jobs.toolId,
count: sql<number>`count(*)`.as("count"),
})
.from(jobs)
.groupBy(jobs.toolId)
.orderBy(sql`count(*) desc`)
.limit(12);
if (rows.length < 4) {
return { tools: DEFAULT_POPULAR };
}
return { tools: rows.map((r) => r.toolId) };
} catch {
return { tools: DEFAULT_POPULAR };
}
});
}