Files
zeekayandHanzo Dev 6b68c9299e kv: one name for the store, and it is Hanzo KV
The client was already @hanzo/kv; only the vocabulary was still Redis. Every
module, symbol and comment now says what it connects to:

  lib/redis.ts                    -> lib/kv.ts                (exports kv, lockKv)
  lib/redis-job-store.ts          -> lib/kv-job-store.ts      (KvJobStore)
  lib/redis-download-job-store.ts -> lib/kv-download-job-store.ts
  lib/files/tus-redis-locker.ts   -> lib/files/tus-kv-locker.ts (KvLocker, KvLock)
  lib/api/domains/redis.ts        -> lib/api/domains/kv.ts    (getKey)
  lib/redis/                      -> lib/kv-queue/

KV_URL is now the only endpoint variable — the REDIS_URL fallback and the
redis://localhost default are gone, and the default scheme is kv://, which
@hanzo/kv parses natively (utils/index.js). .env.example gained the KV_URL it
never documented, and lost UPSTASH_REDIS_REST_LOCKER_URL/TOKEN: nothing has read
those since the client changed — the locker opens a second connection to the
same KV, so there is no second endpoint to configure.

The second connection is `lockKv`, not `locker`: both tus routes already have a
local `const locker = new KvLocker(...)`, so naming the client `locker` made the
lock take itself as its own client.

Verified against the repo's own gate (npx tsc --noEmit): 100 errors before and
after, 0 introduced, compared set-wise by file:line:code. Behaviour is untouched
— this is naming, one connection string, and dead config.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-09 10:09:34 -07:00

51 lines
1.3 KiB
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth";
import { getFileForDocumentPage } from "@/lib/documents/get-file-helper";
import { ratelimit } from "@/lib/kv";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../auth/[...nextauth]";
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method !== "GET") {
res.status(405).json({ message: "Method Not Allowed" });
return;
}
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
const { success } = await ratelimit(150, "1 m").limit(
`get-thumbnail:${(session.user as CustomUser).id}`,
);
if (!success) {
return res.status(429).json({ message: "Too many requests" });
}
const { documentId, pageNumber, versionNumber } = req.query as {
documentId: string;
pageNumber: string;
versionNumber: string;
};
try {
const imageUrl = await getFileForDocumentPage(
Number(pageNumber),
documentId,
versionNumber === "undefined" ? undefined : Number(versionNumber),
);
return res.status(200).json({ imageUrl });
} catch (error) {
res.status(500).json({ message: (error as Error).message });
return;
}
}