From 8152cda2ac098f0a74e13ecc406a35b5295f6e84 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 28 Nov 2023 11:55:34 +0100 Subject: [PATCH] Allow track and untrack of a project through the TrackButton - Add support for checking the tracking table from `radicle-httpd` to get a more precise information if the project is being tracked by the local node. - If a user isn't authenticated with their local httpd instance, we still show the Popover to explain how to do it on the CLI --- httpd-client/index.ts | 55 +++++++++++++++++++++ src/views/projects/Header/SeedButton.svelte | 15 ++++-- src/views/projects/Layout.svelte | 51 ++++++++++++++++++- src/views/projects/router.ts | 31 ++++++------ tests/e2e/node.spec.ts | 14 ++++++ 5 files changed, 143 insertions(+), 23 deletions(-) diff --git a/httpd-client/index.ts b/httpd-client/index.ts index d9fdd816a..241893145 100644 --- a/httpd-client/index.ts +++ b/httpd-client/index.ts @@ -6,6 +6,7 @@ import type { Tree, DiffResponse, } from "./lib/project.js"; +import type { SuccessResponse } from "./lib/shared.js"; import type { Comment, Embed } from "./lib/project/comment.js"; import type { Commit, @@ -38,6 +39,7 @@ import { z, array, boolean, literal, number, object, string, union } from "zod"; import * as project from "./lib/project.js"; import * as session from "./lib/session.js"; import { Fetcher } from "./lib/fetcher.js"; +import { successResponseSchema } from "./lib/shared.js"; export type { BaseUrl, @@ -127,6 +129,16 @@ const nodeInfoSchema = object({ ), }); +export type NodeTracking = z.infer; + +const nodeTrackingSchema = array( + object({ + id: string(), + scope: string(), + policy: string(), + }), +); + export interface NodeStats { projects: { count: number }; users: { count: number }; @@ -189,6 +201,49 @@ export class HttpdClient { ); } + public async getTracking(options?: RequestOptions): Promise { + return this.#fetcher.fetchOk( + { + method: "GET", + path: "node/policies/repos", + options, + }, + nodeTrackingSchema, + ); + } + + public async seedById( + id: string, + authToken: string, + options?: RequestOptions, + ): Promise { + return this.#fetcher.fetchOk( + { + method: "PUT", + path: `node/policies/repos/${id}`, + headers: { Authorization: `Bearer ${authToken}` }, + options, + }, + successResponseSchema, + ); + } + + public async stopSeedingById( + id: string, + authToken: string, + options?: RequestOptions, + ): Promise { + return this.#fetcher.fetchOk( + { + method: "DELETE", + path: `node/policies/repos/${id}`, + headers: { Authorization: `Bearer ${authToken}` }, + options, + }, + successResponseSchema, + ); + } + public async getNode(options?: RequestOptions): Promise { return this.#fetcher.fetchOk( { diff --git a/src/views/projects/Header/SeedButton.svelte b/src/views/projects/Header/SeedButton.svelte index ff606d62f..e2c005903 100644 --- a/src/views/projects/Header/SeedButton.svelte +++ b/src/views/projects/Header/SeedButton.svelte @@ -5,11 +5,11 @@ import IconSmall from "@app/components/IconSmall.svelte"; import Popover from "@app/components/Popover.svelte"; + export let disabled: boolean; export let projectId: string; export let seedCount: number; export let seeding: boolean; - - $: buttonTitle = seeding ? "Seeding" : "Seed"; + export let editSeeding: (() => Promise) | undefined;