412 lines · 16.3 KB
import { assignedToViewer } from "~/server/involvement-read";
import { createServerFn } from "@tanstack/react-start";
import { isTakenDown } from "~/lib/account-disable";
import { invalidateUnread } from "~/server/user-inbox";
import { env } from "cloudflare:workers";
import { accountOgImage } from "~/server/og/data";
import { limitWrite, limitAccountWrite } from "~/server/limits";
import { z } from "zod";
import { requireViewer, viewerMiddleware } from "./middleware";
import { all, first, MAX_IN_LIST, placeholders, run } from "~/server/db";
import { replica } from "~/server/db-replica";
import { accountDb, repoDb } from "~/server/scoped-db";
import { filterReadable } from "~/server/notification-store";
import { hashPassword } from "~/server/crypto";
import { revokeAccessTokens, revokeAccessTokensWhere } from "~/server/access-token-store";
import { createSession } from "~/server/auth";
import { confirmPassword, notifySecurityEvent, revokeAllSessions } from "~/server/account-security";
import {
  canListOrgMembers,
  createOrg,
  listMyOrgInvitations,
  listOrgInvitations as listPendingOrgInvitations,
  loadOrgSettings,
  respondToOrgInvitation,
  setOrgMember as setOrgMembership,
  updateOrgSettings as saveOrgSettings,
} from "~/server/accounts";
import { ORG_DEFAULT_PERMISSIONS } from "~/server/repos";
import { deleteOrganization as removeOrganization } from "~/server/org-delete";
import { revokeUnsubscribeTokens } from "~/server/notify/prefs";
import { canAdministerAccount, toRepoSummaries, visibleReposClause } from "~/server/repos";
import { accountOrGhost, accountsById } from "~/server/people";
import { forbidden, notFoundError } from "~/server/errors";
import { accountNameFormat, displayName, password, website } from "~/lib/validation";
import type { AccountRow, JsonValue, RepoRow } from "~/lib/types";

const ACTIVITY_LIMIT = 40;
/** Activity feeds read this many of the most recently pushed repositories. */
const FEED_REPOS = 30;
const NOTIFICATION_LIMIT = 100;