import { env } from "cloudflare:workers";
import { isTakenDown } from "~/lib/account-disable";
import type { AccountCardData, RepoCardData } from "~/lib/og";
import { accountOgPath, repoOgPath, siteOgPath } from "~/lib/og";
import type { RepoRow } from "~/lib/types";
import { first } from "../db";
import { repoDb } from "../scoped-db";
import { repoTakenDown } from "../repos";
import { isScratchRepo } from "../sites/config";
/** Only what an anonymous visitor can see: public, not hidden, not taken down. Anything else gets the site card. */
export function repoCardVisible(
repo: Pick<
RepoRow,
| "visibility"
| "hidden_at"
| "owner_disabled_at"
| "owner_disabled_reason"
| "owner_id"
>,
): boolean {
return (
repo.visibility === "public" &&
!repo.hidden_at &&
!repoTakenDown(repo) &&
!isScratchRepo(repo)
);
}
export async function repoCardData(repo: RepoRow): Promise<RepoCardData> {
const [owner, release] = await Promise.all([
first<{ avatar_key: string | null }>(
"SELECT avatar_key FROM accounts WHERE id = ?",
repo.owner_id,
),
repoDb(repo.id).first<{ tag: string }>(
"SELECT tag FROM releases WHERE repo_id = ? AND draft = 0 ORDER BY COALESCE(published_at, created_at) DESC LIMIT 1",
repo.id,
),
]);