mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Rename Seed class attributes
seed.api -> seed.addr seed.link -> seed.node Co-authored-by: xphoniex <dj.2dixx@gmail.com> Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
co-authored by
xphoniex
parent
26f96990a4
commit
25edd969f8
@@ -14,9 +14,9 @@
|
||||
export let port: number;
|
||||
export let full = false;
|
||||
|
||||
const seedHost = seed.api.port
|
||||
? `${seed.api.host}:${seed.api.port}`
|
||||
: `${formatSeedHost(seed.api.host)}`;
|
||||
const seedHost = seed.addr.port
|
||||
? `${seed.addr.host}:${seed.addr.port}`
|
||||
: `${formatSeedHost(seed.addr.host)}`;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
import { defaultSeedPort } from "@app/lib/seed";
|
||||
|
||||
export interface Host {
|
||||
host: string;
|
||||
port: number | null;
|
||||
@@ -10,7 +12,7 @@ export class Request {
|
||||
port: number;
|
||||
|
||||
constructor(path: string, api: Host) {
|
||||
this.port = api.port || 8777;
|
||||
this.port = api.port || defaultSeedPort;
|
||||
this.base = api.host;
|
||||
this.path = path.startsWith("/") ? path.slice(1) : path;
|
||||
this.protocol = api.host === "0.0.0.0" ? "http://" : "https://";
|
||||
|
||||
+9
-9
@@ -3,7 +3,7 @@ import type { Wallet } from "@app/lib/wallet";
|
||||
import { type Host, Request } from "@app/lib/api";
|
||||
|
||||
import { Profile, ProfileType } from "@app/lib/profile";
|
||||
import { Seed } from "@app/lib/seed";
|
||||
import { Seed, defaultSeedPort } from "@app/lib/seed";
|
||||
import { isFulfilled, isOid, isRadicleId } from "@app/lib/utils";
|
||||
|
||||
export type Id = string;
|
||||
@@ -278,7 +278,7 @@ export class Project implements ProjectInfo {
|
||||
async getCommit(commit: string): Promise<Commit> {
|
||||
return new Request(
|
||||
`projects/${this.id}/commits/${commit}`,
|
||||
this.seed.api,
|
||||
this.seed.addr,
|
||||
).get();
|
||||
}
|
||||
|
||||
@@ -286,21 +286,21 @@ export class Project implements ProjectInfo {
|
||||
if (path === "/") path = "";
|
||||
return new Request(
|
||||
`projects/${this.id}/tree/${commit}/${path}`,
|
||||
this.seed.api,
|
||||
this.seed.addr,
|
||||
).get();
|
||||
}
|
||||
|
||||
async getBlob(commit: string, path: string): Promise<Blob> {
|
||||
return new Request(
|
||||
`projects/${this.id}/blob/${commit}/${path}`,
|
||||
this.seed.api,
|
||||
this.seed.addr,
|
||||
).get();
|
||||
}
|
||||
|
||||
async getReadme(commit: string): Promise<Blob> {
|
||||
return new Request(
|
||||
`projects/${this.id}/readme/${commit}`,
|
||||
this.seed.api,
|
||||
this.seed.addr,
|
||||
).get();
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ export class Project implements ProjectInfo {
|
||||
|
||||
const [host, port] = seedHost?.includes(":")
|
||||
? seedHost.split(":")
|
||||
: [seedHost, "8777"];
|
||||
: [seedHost, defaultSeedPort];
|
||||
|
||||
const seed = profile
|
||||
? profile.seed
|
||||
@@ -332,14 +332,14 @@ export class Project implements ProjectInfo {
|
||||
throw new Error("Couldn't load project: invalid seed");
|
||||
}
|
||||
|
||||
const info = await Project.getInfo(id, seed.api);
|
||||
const info = await Project.getInfo(id, seed.addr);
|
||||
id = isRadicleId(id) ? id : info.id;
|
||||
|
||||
// Older versions of http-api don't include the ID.
|
||||
if (!info.id) info.id = id;
|
||||
|
||||
const peers: Peer[] = info.delegates
|
||||
? await Project.getRemotes(id, seed.api)
|
||||
? await Project.getRemotes(id, seed.addr)
|
||||
: [];
|
||||
|
||||
let remote: Remote = {
|
||||
@@ -348,7 +348,7 @@ export class Project implements ProjectInfo {
|
||||
|
||||
if (peer) {
|
||||
try {
|
||||
remote = await Project.getRemote(id, peer, seed.api);
|
||||
remote = await Project.getRemote(id, peer, seed.addr);
|
||||
} catch {
|
||||
remote.heads = {};
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export async function getRegistration(
|
||||
host: seedHost,
|
||||
id: seedId,
|
||||
git: seedGit,
|
||||
api: seedApi,
|
||||
addr: seedApi,
|
||||
});
|
||||
} catch (e: any) {
|
||||
console.debug(e, seedHost, seedId);
|
||||
@@ -170,7 +170,7 @@ export async function getSeed(
|
||||
}
|
||||
|
||||
try {
|
||||
return new Seed({ host, id, git, api });
|
||||
return new Seed({ host, id, git, addr: api });
|
||||
} catch (e: any) {
|
||||
console.debug(e, host, id);
|
||||
return new InvalidSeed(id, host);
|
||||
|
||||
+42
-42
@@ -23,16 +23,16 @@ export class InvalidSeed {
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultHttpApiPort = 8777;
|
||||
export const defaultLinkPort = 8776;
|
||||
export const defaultSeedPort = 8777;
|
||||
export const defaultNodePort = 8776;
|
||||
export const defaultGitPort = 443;
|
||||
|
||||
export class Seed {
|
||||
valid = true as const;
|
||||
|
||||
api: { host: string; port: number | null };
|
||||
addr: { host: string; port: number | null };
|
||||
git: { host: string; port: number | null };
|
||||
link: { host: string; id: string; port: number };
|
||||
node: { host: string; id: string; port: number };
|
||||
|
||||
version?: string;
|
||||
emoji: string;
|
||||
@@ -41,59 +41,59 @@ export class Seed {
|
||||
host: string;
|
||||
id: string;
|
||||
git?: string | null;
|
||||
api?: string | null;
|
||||
addr?: string | null;
|
||||
version?: string | null;
|
||||
}) {
|
||||
assert(isDomain(seed.host), `invalid seed host: ${seed.host}`);
|
||||
assert(/^[a-z0-9]+$/.test(seed.id), `invalid seed id ${seed.id}`);
|
||||
|
||||
let api = null;
|
||||
let git = null;
|
||||
let apiPort: number | null = defaultHttpApiPort;
|
||||
let gitPort: number | null = defaultGitPort;
|
||||
let _seed = null;
|
||||
let _git = null;
|
||||
let _seedPort: number | null = defaultSeedPort;
|
||||
let _gitPort: number | null = defaultGitPort;
|
||||
|
||||
if (seed.api) {
|
||||
if (seed.addr) {
|
||||
try {
|
||||
const url = new URL(seed.api);
|
||||
api = url.hostname;
|
||||
const url = new URL(seed.addr);
|
||||
_seed = url.hostname;
|
||||
|
||||
if (url.port) {
|
||||
apiPort = Number(url.port);
|
||||
_seedPort = Number(url.port);
|
||||
} else if (url.protocol === "http:" && url.port === "") {
|
||||
apiPort = 80;
|
||||
_seedPort = 80;
|
||||
}
|
||||
if (url.protocol === "https:" && url.port === "") {
|
||||
apiPort = 443;
|
||||
_seedPort = 443;
|
||||
} else {
|
||||
apiPort = null;
|
||||
_seedPort = null;
|
||||
}
|
||||
} catch {
|
||||
api = seed.api;
|
||||
_seed = seed.addr;
|
||||
}
|
||||
assert(isDomain(api), `invalid seed api host ${api}`);
|
||||
assert(isDomain(_seed), `invalid seed host ${_seed}`);
|
||||
}
|
||||
|
||||
if (seed.git) {
|
||||
try {
|
||||
const url = new URL(seed.git);
|
||||
git = url.hostname;
|
||||
gitPort = url.port ? Number(url.port) : null;
|
||||
_git = url.hostname;
|
||||
_gitPort = url.port ? Number(url.port) : null;
|
||||
} catch {
|
||||
git = seed.git;
|
||||
_git = seed.git;
|
||||
}
|
||||
assert(isDomain(git), `invalid seed git host ${git}`);
|
||||
assert(isDomain(_git), `invalid seed git host ${_git}`);
|
||||
}
|
||||
|
||||
this.emoji = getSeedEmoji(seed.host);
|
||||
|
||||
// The `git` and `api` keys being more specific take
|
||||
// The `_seed` being more specific takes
|
||||
// precedence over the `host`, if available.
|
||||
api = api ?? seed.host;
|
||||
git = git ?? seed.host;
|
||||
_seed = _seed ?? seed.host;
|
||||
_git = _git ?? seed.host;
|
||||
|
||||
this.api = { host: api, port: apiPort };
|
||||
this.git = { host: git, port: gitPort };
|
||||
this.link = { host: seed.host, id: seed.id, port: defaultLinkPort };
|
||||
this.addr = { host: _seed, port: _seedPort };
|
||||
this.git = { host: _git, port: _gitPort };
|
||||
this.node = { host: seed.host, id: seed.id, port: defaultNodePort };
|
||||
|
||||
if (seed.version) {
|
||||
this.version = seed.version;
|
||||
@@ -101,25 +101,25 @@ export class Seed {
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this.link.id;
|
||||
return this.node.id;
|
||||
}
|
||||
|
||||
get host(): string {
|
||||
return this.api.host;
|
||||
return this.addr.host;
|
||||
}
|
||||
|
||||
async getPeer(): Promise<{ id: string }> {
|
||||
return Seed.getPeer(this.api);
|
||||
async getNode(): Promise<{ id: string }> {
|
||||
return Seed.getNode(this.addr);
|
||||
}
|
||||
|
||||
async getProject(id: string): Promise<proj.ProjectInfo> {
|
||||
return proj.Project.getInfo(id, this.api);
|
||||
return proj.Project.getInfo(id, this.addr);
|
||||
}
|
||||
|
||||
async getProjects(perPage: number, id?: string): Promise<proj.ProjectInfo[]> {
|
||||
const result = id
|
||||
? await proj.Project.getDelegateProjects(id, this.api, { perPage })
|
||||
: await proj.Project.getProjects(this.api, { perPage });
|
||||
? await proj.Project.getDelegateProjects(id, this.addr, { perPage })
|
||||
: await proj.Project.getProjects(this.addr, { perPage });
|
||||
|
||||
return result.map((project: proj.ProjectInfo) => ({
|
||||
...project,
|
||||
@@ -131,10 +131,10 @@ export class Seed {
|
||||
projects: { count: number };
|
||||
users: { count: number };
|
||||
}> {
|
||||
return new Request("/stats", this.api).get();
|
||||
return new Request("/stats", this.addr).get();
|
||||
}
|
||||
|
||||
static async getPeer(host: Host): Promise<{ id: string }> {
|
||||
static async getNode(host: Host): Promise<{ id: string }> {
|
||||
return new Request("/peer", host).get();
|
||||
}
|
||||
|
||||
@@ -144,19 +144,19 @@ export class Seed {
|
||||
|
||||
static async lookup(
|
||||
hostname: string,
|
||||
port: number = defaultHttpApiPort,
|
||||
port: number = defaultSeedPort,
|
||||
): Promise<Seed> {
|
||||
const host = { host: hostname, port };
|
||||
const [info, peer] = await Promise.all([
|
||||
const [info, node] = await Promise.all([
|
||||
Seed.getInfo(host),
|
||||
Seed.getPeer(host),
|
||||
Seed.getNode(host),
|
||||
]);
|
||||
|
||||
return new Seed({
|
||||
host: hostname,
|
||||
id: peer.id,
|
||||
id: node.id,
|
||||
version: info.version,
|
||||
api: `https://${host.host}:${host.port}`,
|
||||
addr: `https://${host.host}:${host.port}`,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
<Widget
|
||||
compact
|
||||
project={result.info}
|
||||
seed={{ api: result.seed }}
|
||||
seed={{ addr: result.seed }}
|
||||
on:click={() => onClick(result.info, result.seed)} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
import SetName from "./SetName.svelte";
|
||||
import { MissingReverseRecord, NotFoundError } from "@app/lib/error";
|
||||
import { User, Profile, ProfileType } from "@app/lib/profile";
|
||||
import { defaultLinkPort } from "@app/lib/seed";
|
||||
import { defaultNodePort } from "@app/lib/seed";
|
||||
import { session } from "@app/lib/session";
|
||||
|
||||
export let wallet: Wallet;
|
||||
@@ -187,7 +187,7 @@
|
||||
<!-- Seed Address -->
|
||||
{#if profile.seed && profile.seed.valid}
|
||||
<div class="txt-highlight">Seed</div>
|
||||
<SeedAddress seed={profile.seed} port={defaultLinkPort} />
|
||||
<SeedAddress seed={profile.seed} port={defaultNodePort} />
|
||||
{/if}
|
||||
<!-- Address -->
|
||||
<div class="txt-highlight">Address</div>
|
||||
|
||||
@@ -50,13 +50,13 @@
|
||||
};
|
||||
|
||||
function goToSeed() {
|
||||
if (seed.api.port) {
|
||||
if (seed.addr.port) {
|
||||
router.push({
|
||||
resource: "seeds",
|
||||
params: { host: `${seed.api.host}:${seed.api.port}` },
|
||||
params: { host: `${seed.addr.host}:${seed.addr.port}` },
|
||||
});
|
||||
} else {
|
||||
router.push({ resource: "seeds", params: { host: seed.api.host } });
|
||||
router.push({ resource: "seeds", params: { host: seed.addr.host } });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -101,13 +101,13 @@
|
||||
<CloneButton seedHost={seed.git.host} {id} />
|
||||
{/if}
|
||||
<span>
|
||||
{#if seed.api.host}
|
||||
{#if seed.addr.host}
|
||||
<HeaderToggleLabel
|
||||
clickable
|
||||
ariaLabel="Seed"
|
||||
title="Project data is fetched from this seed"
|
||||
on:click={goToSeed}>
|
||||
<span>{seed.api.host}</span>
|
||||
<span>{seed.addr.host}</span>
|
||||
</HeaderToggleLabel>
|
||||
{/if}
|
||||
</span>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
export let history: CommitsHistory;
|
||||
|
||||
const fetchMoreCommits = async (): Promise<CommitMetadata[]> => {
|
||||
const response = await Project.getCommits(project.id, project.seed.api, {
|
||||
const response = await Project.getCommits(project.id, project.seed.addr, {
|
||||
// Fetching 31 elements since we remove the first one
|
||||
parent: history.headers[history.headers.length - 1].header.sha1,
|
||||
perPage: 31,
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
{#if activeRoute.params.view.resource === "tree"}
|
||||
<Browser {project} {commit} {tree} {activeRoute} />
|
||||
{:else if activeRoute.params.view.resource === "history"}
|
||||
{#await proj.Project.getCommits( project.id, project.seed.api, { parent: commit, verified: true }, )}
|
||||
{#await proj.Project.getCommits( project.id, project.seed.addr, { parent: commit, verified: true }, )}
|
||||
<Loading center />
|
||||
{:then history}
|
||||
<History {project} {history} />
|
||||
@@ -135,7 +135,7 @@
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "issues"}
|
||||
{#await issue.Issue.getIssues(project.id, project.seed.api)}
|
||||
{#await issue.Issue.getIssues(project.id, project.seed.addr)}
|
||||
<Loading center />
|
||||
{:then issues}
|
||||
<Issues state={issueFilter} {wallet} {issues} />
|
||||
@@ -145,7 +145,7 @@
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "issue"}
|
||||
{#await issue.Issue.getIssue(project.id, activeRoute.params.view.params.issue, project.seed.api)}
|
||||
{#await issue.Issue.getIssue(project.id, activeRoute.params.view.params.issue, project.seed.addr)}
|
||||
<Loading center />
|
||||
{:then issue}
|
||||
<Issue {project} {wallet} {issue} />
|
||||
@@ -155,7 +155,7 @@
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "patches"}
|
||||
{#await patch.Patch.getPatches(project.id, project.seed.api)}
|
||||
{#await patch.Patch.getPatches(project.id, project.seed.addr)}
|
||||
<Loading center />
|
||||
{:then patches}
|
||||
<Patches {wallet} state={patchFilter} {patches} />
|
||||
@@ -165,7 +165,7 @@
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "patch"}
|
||||
{#await patch.Patch.getPatch(project.id, activeRoute.params.view.params.patch, project.seed.api)}
|
||||
{#await patch.Patch.getPatch(project.id, activeRoute.params.view.params.patch, project.seed.addr)}
|
||||
<Loading center />
|
||||
{:then patch}
|
||||
<Patch {project} {wallet} {patch} />
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
import { formatCommit } from "@app/lib/utils";
|
||||
|
||||
export let project: proj.ProjectInfo;
|
||||
export let seed: { api: Host };
|
||||
export let seed: { addr: Host };
|
||||
export let faded = false;
|
||||
export let compact = false;
|
||||
|
||||
const loadCommits = async () => {
|
||||
const commits = await Project.getActivity(project.id, seed.api);
|
||||
const commits = await Project.getActivity(project.id, seed.addr);
|
||||
|
||||
return groupCommitsByWeek(commits.activity);
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import Modal from "@app/components/Modal.svelte";
|
||||
import Update from "./Update.svelte";
|
||||
import { assert } from "@app/lib/error";
|
||||
import { defaultHttpApiPort } from "@app/lib/seed";
|
||||
import { defaultSeedPort } from "@app/lib/seed";
|
||||
import { getRegistration, getOwner } from "@app/lib/registrar";
|
||||
import { isAddressEqual, isReverseRecordSet, twemoji } from "@app/lib/utils";
|
||||
import { session } from "@app/lib/session";
|
||||
@@ -138,7 +138,7 @@
|
||||
description:
|
||||
"The seed host address. " +
|
||||
"Only domain names with TLS are supported. " +
|
||||
`HTTP(S) API requests use port ${defaultHttpApiPort}.`,
|
||||
`HTTP(S) API requests use port ${defaultSeedPort}.`,
|
||||
value: r.profile.seed?.host ?? "",
|
||||
editable: true,
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { Stats } from "@app/lib/seed";
|
||||
import type { ProjectInfo } from "@app/lib/project";
|
||||
import { formatSeedId, formatSeedHost, twemoji } from "@app/lib/utils";
|
||||
import { Seed } from "@app/lib/seed";
|
||||
import { Seed, defaultSeedPort } from "@app/lib/seed";
|
||||
import Loading from "@app/components/Loading.svelte";
|
||||
import SeedAddress from "@app/components/SeedAddress.svelte";
|
||||
import NotFound from "@app/components/NotFound.svelte";
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
const [host, port] = hostAndPort.includes(":")
|
||||
? hostAndPort.split(":")
|
||||
: [hostAndPort, 8777];
|
||||
: [hostAndPort, defaultSeedPort];
|
||||
|
||||
const hostName = formatSeedHost(host);
|
||||
const seedHost: Host = { host, port: Number(port) };
|
||||
@@ -99,7 +99,7 @@
|
||||
<div class="fields">
|
||||
<!-- Seed Address -->
|
||||
<div class="txt-highlight">Address</div>
|
||||
<SeedAddress {seed} port={seed.link.port} />
|
||||
<SeedAddress {seed} port={seed.node.port} />
|
||||
<!-- Seed ID -->
|
||||
<div class="txt-highlight">Seed ID</div>
|
||||
<div class="seed-label">
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
const fetchMoreProjects = async (): Promise<proj.ProjectInfo[]> => {
|
||||
try {
|
||||
stats = await seed.getStats();
|
||||
const projects = await proj.Project.getProjects(seed.api, {
|
||||
const projects = await proj.Project.getProjects(seed.addr, {
|
||||
perPage: 10,
|
||||
page: (page += 1),
|
||||
});
|
||||
@@ -41,9 +41,9 @@
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
id: project.id,
|
||||
seed: seed.api.port
|
||||
? `${seed.api.host}:${seed.api.port}`
|
||||
: seed.api.host,
|
||||
seed: seed.addr.port
|
||||
? `${seed.addr.host}:${seed.addr.port}`
|
||||
: seed.addr.host,
|
||||
profile: profile?.name ?? profile?.address,
|
||||
revision: project.head ?? undefined,
|
||||
hash: undefined,
|
||||
|
||||
Reference in New Issue
Block a user