/** * Space for photos and files: the launch promises (assets/design/shared/SPACE.md, 23 Nov 2026). * * 2 GB free; each friend who joins adds 1 GB to both, counted once the friend has used an app on 14 separate days; * 2 TB at most; a full space refuses new files only (`space_full`), never a row. Behind `SPACE_RULES` (off | count | * on), off by default: today's cap and nothing new written. An account may be set apart by the admin. A GB here is * 1024³ bytes, so a promise is never short. */importtype { PlanState } from"./plans.ts";exporttypeSpaceMode = "off" | "count" | "on";exportconst GB = 1024 ** 3;exportconst FREE_BYTES = 2 * GB;exportconst FRIEND_BYTES = 1 * GB;exportconst MOST_BYTES = 2 * 1024 * GB;/** Days of use before a friend counts. */exportconst DAYS_TO_COUNT = 14;/** How long a new account may name who invited it. */exportconst NAME_INVITER_MS = 30 * 86_400_000;/** From this fraction of the allowance a sync pass says how full the space is. */exportconst SPACE_WARN_FRACTION = 0.8;/** The object's meta keys. */exportconst META = { mode: "space_mode", floor: "space_floor", bought: "space_bought", friends: "space_friends", days: "space_days", dayLast: "space_day_last", told: "space_days14_told", plan: "space_plan",} asconst;exportconst SPACE_FULL = "space_full";/** The refusal's words (a draft for the owner). */exportconst SPACE_FULL_WORDS = "Your space for photos and files is full. This one wasn't saved to your account. Everything you already have is safe, and your writing keeps syncing.";/** A switch's value read as a mode; anything else is off. */exportfunction modeOf(value: string | null | undefined): SpaceMode {return value === "on" || value === "count" ? value : "off";}/** The account's mode: its own when the admin set one, else the Worker's switch. */exportfunction accountMode(own: string | null, worker: string | undefined): SpaceMode {return own !== null ? modeOf(own) : modeOf(worker);}/** What the account may hold under the rules: 2 GB and 1 GB a friend, or what was bought, never above 2 TB, and never below what it held when the rules came on. */exportfunction allowance(friends: number, bought: number, floor: number): number {const rule = FREE_BYTES + Math.max(0, Math.floor(friends)) * FRIEND_BYTES;returnMath.max(Math.min(MOST_BYTES, Math.max(rule, bought)), floor);}/** The UTC day of `at`, as `YYYY-MM-DD`. */exportfunction dayOf(at: Date): string {return at.toISOString().slice(0, 10);}/** One more day of use counted, when `today` is a day not yet counted and fewer than 14 are; the new count, or null when nothing changes. */exportfunction dayCounted(last: string | null, days: number, today: string): number | null {if (days >= DAYS_TO_COUNT || last === today) returnnull;return days + 1;}/** The space as the owner reads it (`GET /v1/space`). */exportinterfaceSpaceAnswer { mode: SpaceMode; bytes: number; allowance: number; free: number; friends: number; counting: { days: number; of: number }; bought: number; floor: number;/** The plan he holds (src/plans.ts), as it stands; null with none. */ plan: PlanState | null;}