mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
- 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
43 lines
964 B
TypeScript
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 };
|
|
}
|
|
});
|
|
}
|