Compare commits
No commits in common. "0a6ecc6314ce9e943d6619d490876e92624811a0" and "8cf93953548f91aa15a7f1cde0c388536bdddd3c" have entirely different histories.
0a6ecc6314
...
8cf9395354
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cvsa",
|
"name": "cvsa",
|
||||||
"version": "3.15.34",
|
"version": "2.13.22",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import { sql } from "@core/db/dbNew";
|
|
||||||
import type { LatestSnapshotType } from "@core/db/schema.d.ts";
|
|
||||||
|
|
||||||
export async function getVideosInViewsRange(minViews: number, maxViews: number) {
|
|
||||||
return sql<LatestSnapshotType[]>`
|
|
||||||
SELECT *
|
|
||||||
FROM latest_video_snapshot
|
|
||||||
WHERE views >= ${minViews}
|
|
||||||
AND views <= ${maxViews}
|
|
||||||
ORDER BY views DESC
|
|
||||||
LIMIT 5000
|
|
||||||
`;
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
import { Hono } from "hono";
|
import { Context, Hono } from "hono";
|
||||||
import { Variables } from "hono/types";
|
import { Variables } from "hono/types";
|
||||||
import { bodyLimitForPing } from "./bodyLimits.ts";
|
import { bodyLimitForPing } from "./bodyLimits.ts";
|
||||||
import { pingHandler } from "routes/ping";
|
import { pingHandler } from "routes/ping";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@cvsa/backend",
|
"name": "@cvsa/backend",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "0.6.0",
|
"version": "0.5.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"dev": "NODE_ENV=development bun run --hot src/main.ts",
|
"dev": "NODE_ENV=development bun run --hot src/main.ts",
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
import type { Context } from "hono";
|
|
||||||
import { createHandlers } from "src/utils.ts";
|
|
||||||
import type { BlankEnv, BlankInput } from "hono/types";
|
|
||||||
import { number, object, ValidationError } from "yup";
|
|
||||||
import { ErrorResponse } from "src/schema";
|
|
||||||
import { startTime, endTime } from "hono/timing";
|
|
||||||
import { getVideosInViewsRange } from "@/db/latestSnapshots";
|
|
||||||
|
|
||||||
const SnapshotQueryParamsSchema = object({
|
|
||||||
min_views: number().integer().optional().positive(),
|
|
||||||
max_views: number().integer().optional().positive()
|
|
||||||
});
|
|
||||||
|
|
||||||
type ContextType = Context<BlankEnv, "/videos", BlankInput>;
|
|
||||||
|
|
||||||
export const getVideosHanlder = createHandlers(async (c: ContextType) => {
|
|
||||||
startTime(c, "parse", "Parse the request");
|
|
||||||
try {
|
|
||||||
const queryParams = await SnapshotQueryParamsSchema.validate(c.req.query());
|
|
||||||
const { min_views, max_views } = queryParams;
|
|
||||||
|
|
||||||
if (!min_views && !max_views) {
|
|
||||||
const response: ErrorResponse<string> = {
|
|
||||||
code: "INVALID_QUERY_PARAMS",
|
|
||||||
message: "Invalid query parameters",
|
|
||||||
errors: ["Must provide one of these query parameters: min_views, max_views"]
|
|
||||||
};
|
|
||||||
return c.json<ErrorResponse<string>>(response, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
endTime(c, "parse");
|
|
||||||
|
|
||||||
startTime(c, "db", "Query the database");
|
|
||||||
|
|
||||||
const minViews = min_views ? min_views : 0;
|
|
||||||
const maxViews = max_views ? max_views : 2147483647;
|
|
||||||
|
|
||||||
const result = await getVideosInViewsRange(minViews, maxViews);
|
|
||||||
|
|
||||||
endTime(c, "db");
|
|
||||||
|
|
||||||
const rows = result.map((row) => ({
|
|
||||||
...row,
|
|
||||||
aid: Number(row.aid)
|
|
||||||
}));
|
|
||||||
|
|
||||||
return c.json(rows);
|
|
||||||
} catch (e: unknown) {
|
|
||||||
if (e instanceof ValidationError) {
|
|
||||||
const response: ErrorResponse<string> = {
|
|
||||||
code: "INVALID_QUERY_PARAMS",
|
|
||||||
message: "Invalid query parameters",
|
|
||||||
errors: e.errors
|
|
||||||
};
|
|
||||||
return c.json<ErrorResponse<string>>(response, 400);
|
|
||||||
} else {
|
|
||||||
const response: ErrorResponse<unknown> = {
|
|
||||||
code: "UNKNOWN_ERROR",
|
|
||||||
message: "Unhandled error",
|
|
||||||
errors: [e]
|
|
||||||
};
|
|
||||||
return c.json<ErrorResponse<unknown>>(response, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -1 +0,0 @@
|
|||||||
export * from "./GET.ts";
|
|
@ -15,4 +15,4 @@ configureRoutes(app);
|
|||||||
|
|
||||||
await startServer(app);
|
await startServer(app);
|
||||||
|
|
||||||
export const VERSION = "0.6.0";
|
export const VERSION = "0.5.2";
|
||||||
|
@ -6,14 +6,11 @@ import { Hono } from "hono";
|
|||||||
import { Variables } from "hono/types";
|
import { Variables } from "hono/types";
|
||||||
import { createCaptchaSessionHandler, verifyChallengeHandler } from "routes/captcha";
|
import { createCaptchaSessionHandler, verifyChallengeHandler } from "routes/captcha";
|
||||||
import { getCaptchaDifficultyHandler } from "routes/captcha/difficulty/GET.ts";
|
import { getCaptchaDifficultyHandler } from "routes/captcha/difficulty/GET.ts";
|
||||||
import { getVideosHanlder } from "@/routes/videos";
|
|
||||||
|
|
||||||
export function configureRoutes(app: Hono<{ Variables: Variables }>) {
|
export function configureRoutes(app: Hono<{ Variables: Variables }>) {
|
||||||
app.get("/", ...rootHandler);
|
app.get("/", ...rootHandler);
|
||||||
app.all("/ping", ...pingHandler);
|
app.all("/ping", ...pingHandler);
|
||||||
|
|
||||||
app.get("/videos", ...getVideosHanlder);
|
|
||||||
|
|
||||||
app.get("/video/:id/snapshots", ...getSnapshotsHanlder);
|
app.get("/video/:id/snapshots", ...getSnapshotsHanlder);
|
||||||
app.get("/video/:id/info", ...videoInfoHandler);
|
app.get("/video/:id/info", ...videoInfoHandler);
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "crawler",
|
"name": "crawler",
|
||||||
"version": "1.2.26",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "bun --env-file=.env.test run vitest",
|
"test": "bun --env-file=.env.test run vitest",
|
||||||
"worker:main": "bun run ./src/worker.ts",
|
"worker:main": "bun run ./src/worker.ts",
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.9.0",
|
"version": "0.0.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "astro dev",
|
"dev": "astro dev",
|
||||||
"build": "astro build",
|
"build": "astro build",
|
||||||
"preview": "astro preview",
|
"preview": "astro preview",
|
||||||
"astro": "astro"
|
"astro": "astro"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/node": "^9.1.3",
|
"@astrojs/node": "^9.1.3",
|
||||||
"@astrojs/svelte": "^7.0.9",
|
"@astrojs/svelte": "^7.0.9",
|
||||||
"@tailwindcss/vite": "^4.1.4",
|
"@tailwindcss/vite": "^4.1.4",
|
||||||
"argon2id": "^1.0.1",
|
"argon2id": "^1.0.1",
|
||||||
"astro": "^5.5.5",
|
"astro": "^5.5.5",
|
||||||
"autoprefixer": "^10.4.21",
|
"autoprefixer": "^10.4.21",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"pg": "^8.11.11",
|
"pg": "^8.11.11",
|
||||||
"postcss": "^8.5.3",
|
"postcss": "^8.5.3",
|
||||||
"postgres": "^3.4.5",
|
"postgres": "^3.4.5",
|
||||||
"svelte": "^5.25.7",
|
"svelte": "^5.25.7",
|
||||||
"tailwindcss": "^4.1.4",
|
"tailwindcss": "^4.1.4",
|
||||||
"ua-parser-js": "^2.0.3",
|
"ua-parser-js": "^2.0.3",
|
||||||
"vite-tsconfig-paths": "^5.1.4"
|
"vite-tsconfig-paths": "^5.1.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-wasm": "^6.2.2",
|
"@rollup/plugin-wasm": "^6.2.2",
|
||||||
"@types/pg": "^8.11.11"
|
"@types/pg": "^8.11.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next",
|
"name": "next",
|
||||||
"version": "2.8.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack -p 7400",
|
"dev": "next dev --turbopack -p 7400",
|
||||||
|
Loading…
Reference in New Issue
Block a user