Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions apps/app/src/directory-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ReactNode, useState } from "react";

import { Button, Input } from "@ace/ui";
import type { Diagnostics } from "@ace/host/protocol";
import { type Diagnostics, type Share, TEAM } from "@ace/host/protocol";

import { desktop } from "./desktop";
import { host } from "./host";
Expand Down Expand Up @@ -180,6 +180,20 @@ function served(directory: Diagnostics["directory"]): boolean {
return directory.serving || URL.parse(directory.url || "")?.pathname === "/directory";
}

/** Each shared project and who it is shared with, as "b-sandbox with the team; ace with rivera". */
function shared(shares: Share[]): string {
const projects = new Map<string, string[]>();
for (const { project, person } of shares) {
const name = project.startsWith("github:")
? project.slice("github:".length)
: (JSON.parse(project) as [string, string])[1].replace(/\/+$/, "").split("/").pop()!;
const people = projects.get(name) || [];
people.push(person === TEAM ? "the team" : person);
projects.set(name, people);
}
return [...projects].map(([name, people]) => `${name} with ${people.join(", ")}`).join("; ");
}

/** A time today, or a date and time when older, so a stale sync doesn't read as recent. */
function when(time: number) {
const date = new Date(time);
Expand Down Expand Up @@ -340,8 +354,12 @@ function TeamDirectory(
)}
onCancel={() => setConfirm(undefined)}
>
Stop serving the directory? Teammates stop seeing channels on offline Macs, and its
shares are deleted.
Stop serving the directory? Teammates stop seeing channels on offline Macs
{directory.shares.length
? `, and these shares are deleted, ending the access they give: ${
shared(directory.shares)
}.`
: "."}
</Confirm>
)}
{confirm === "leave" && (
Expand Down
1 change: 1 addition & 0 deletions apps/host/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function diagnostics(sync?: boolean): Promise<Diagnostics> {
secret: await secret,
services: { hosted, app, compute },
serving: served.isServing(),
shares: served.shares(),
},
shell: { ...environment },
web: web.address,
Expand Down
8 changes: 7 additions & 1 deletion apps/host/src/directory-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export function remove(): void {
log("info", "directory.removed", {});
}

/** The project shares stopping deletes. */
export function shares(): Share[] {
if (!isServing()) return [];
return open().query<Share, []>('SELECT project, person, shared_by AS "by", at FROM shares').all();
}

/** Requests under `/directory`, with `path` the rest. */
export async function handle(path: string, request: Request, caller: Caller): Promise<Response> {
if (!isServing()) return new Response("This host serves no directory", { status: 404 });
Expand Down Expand Up @@ -150,7 +156,7 @@ function read(sql: Database) {
channels: sql.query<{ listing: string }, []>("SELECT listing FROM channels").all().map((row) =>
JSON.parse(row.listing)
),
shares: sql.query<Share, []>('SELECT project, person, shared_by AS "by", at FROM shares').all(),
shares: shares(),
};
}

Expand Down
2 changes: 2 additions & 0 deletions apps/host/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export type Diagnostics = {
services: { hosted?: string; app?: string; compute?: string };
/** This host serves the team's directory on the tailnet. */
serving: boolean;
/** The project shares in the directory this host serves, which stopping it deletes. */
shares: Share[];
};
/** Whether the helper loaded the login shell's environment; `pending` while it retries. */
shell: { state: "adopted" | "pending" | "failed"; error?: string };
Expand Down