Skip to content

Commit

Permalink
Simplify sidebar context boxes
Browse files Browse the repository at this point in the history
Also starts removing features that relied on the web client handling
local httpd instances
  • Loading branch information
sebastinez committed Jul 2, 2024
1 parent 02057b5 commit 72e1b99
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 364 deletions.
7 changes: 5 additions & 2 deletions http-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
SuccessResponse,
CodeLocation,
Range,
SeedingPolicy,
DefaultSeedingPolicy,
} from "./lib/shared.js";
import type { Comment, Embed, Reaction } from "./lib/project/comment.js";
Expand Down Expand Up @@ -50,6 +51,7 @@ import { Fetcher } from "./lib/fetcher.js";
import {
nodeConfigSchema,
scopeSchema,
seedingPolicySchema,
successResponseSchema,
} from "./lib/shared.js";

Expand Down Expand Up @@ -85,6 +87,7 @@ export type {
Remote,
Review,
Revision,
SeedingPolicy,
TreeStats,
Tree,
Verdict,
Expand Down Expand Up @@ -211,14 +214,14 @@ export class HttpdClient {
public async getPoliciesById(
id: string,
options?: RequestOptions,
): Promise<NodePolicies["policy"][]> {
): Promise<SeedingPolicy> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `node/policies/repos/${id}`,
options,
},
array(nodePoliciesSchema.shape.policy),
seedingPolicySchema,
);
}

Expand Down
12 changes: 12 additions & 0 deletions http-client/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export const successResponseSchema = object({

export const scopeSchema = union([literal("followed"), literal("all")]);

export const seedingPolicySchema = union([
object({
policy: literal("block"),
}),
object({
policy: literal("allow"),
scope: scopeSchema,
}),
]);

export type SeedingPolicy = z.infer<typeof seedingPolicySchema>;

const defaultSeedingPolicySchema = union([
object({
default: literal("block"),
Expand Down
10 changes: 1 addition & 9 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BaseUrl, DefaultSeedingPolicy } from "@http-client";
import type { BaseUrl } from "@http-client";

import md5 from "md5";
import bs58 from "bs58";
Expand All @@ -13,14 +13,6 @@ export function formatLocationHash(hash: string | null): number | null {
return null;
}

export function formatShortSeedingPolicy(
policy: DefaultSeedingPolicy | undefined,
) {
return policy?.default === "allow" && policy?.scope === "all"
? "permissive"
: "restrictive";
}

// Removes the first and last character which are always `/`.
export function formatUserAgent(agent: string): string {
return agent.slice(1, -1);
Expand Down
6 changes: 4 additions & 2 deletions src/views/nodes/View.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { api, httpdStore } from "@app/lib/httpd";
import {
baseUrlToString,
formatShortSeedingPolicy,
formatUserAgent,
isLocal,
truncateId,
Expand All @@ -32,7 +31,10 @@
export let seedingPolicy: DefaultSeedingPolicy | undefined = undefined;
export let agent: string;
$: shortScope = formatShortSeedingPolicy(seedingPolicy);
$: shortScope =
seedingPolicy?.default === "allow" && seedingPolicy?.scope === "all"
? "permissive"
: "restrictive";
$: hostname = isLocal(baseUrl.hostname) ? "Local Node" : baseUrl.hostname;
$: session =
$httpdStore.state === "authenticated" && isLocal(api.baseUrl.hostname)
Expand Down
Loading

0 comments on commit 72e1b99

Please sign in to comment.