mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Rename hostnamePort to hostAndPort
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
@@ -125,7 +125,7 @@ export class HttpdClient {
|
||||
}`;
|
||||
}
|
||||
|
||||
public get hostnamePort(): string {
|
||||
public get hostAndPort(): string {
|
||||
return `${this.#baseUrl.hostname}:${this.#baseUrl.port}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@
|
||||
route={{
|
||||
resource: "seeds",
|
||||
params: {
|
||||
hostnamePort: httpd.api.hostnamePort,
|
||||
hostAndPort: httpd.api.hostAndPort,
|
||||
projectPageIndex: 0,
|
||||
},
|
||||
}}>
|
||||
@@ -152,7 +152,7 @@
|
||||
route={{
|
||||
resource: "seeds",
|
||||
params: {
|
||||
hostnamePort: httpd.api.hostnamePort,
|
||||
hostAndPort: httpd.api.hostAndPort,
|
||||
projectPageIndex: 0,
|
||||
},
|
||||
}}>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as modal from "@app/lib/modal";
|
||||
import * as router from "@app/lib/router";
|
||||
import { searchPlaceholder } from "@app/lib/shared";
|
||||
import { unreachable } from "@app/lib/utils";
|
||||
import { getHostAndPort, unreachable } from "@app/lib/utils";
|
||||
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import SearchResultsModal from "@app/App/Header/SearchResultsModal.svelte";
|
||||
@@ -47,13 +47,14 @@
|
||||
} else if (searchResult.type === "projects") {
|
||||
input = "";
|
||||
if (searchResult.results.length === 1) {
|
||||
const { project, baseUrl } = searchResult.results[0];
|
||||
void router.push({
|
||||
resource: "projects",
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
id: searchResult.results[0].project.id,
|
||||
id: project.id,
|
||||
peer: undefined,
|
||||
hostnamePort: searchResult.results[0].baseUrl.hostname,
|
||||
hostAndPort: getHostAndPort(baseUrl),
|
||||
hash: undefined,
|
||||
search: undefined,
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { ProjectBaseUrl } from "@app/lib/search";
|
||||
|
||||
import * as modal from "@app/lib/modal";
|
||||
import { formatRepositoryId } from "@app/lib/utils";
|
||||
import { formatRepositoryId, getHostAndPort } from "@app/lib/utils";
|
||||
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import Modal from "@app/components/Modal.svelte";
|
||||
@@ -40,7 +40,7 @@
|
||||
resource: "projects",
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
hostnamePort: result.baseUrl.hostname,
|
||||
hostAndPort: getHostAndPort(result.baseUrl),
|
||||
id: result.project.id,
|
||||
},
|
||||
}}>
|
||||
|
||||
+19
-19
@@ -124,8 +124,8 @@ function pathToRoute(url: URL): Route | null {
|
||||
const resource = segments.shift();
|
||||
switch (resource) {
|
||||
case "seeds": {
|
||||
const hostnamePort = segments.shift();
|
||||
if (hostnamePort) {
|
||||
const hostAndPort = segments.shift();
|
||||
if (hostAndPort) {
|
||||
const id = segments.shift();
|
||||
if (id) {
|
||||
// Allows project paths with or without trailing slash
|
||||
@@ -139,17 +139,17 @@ function pathToRoute(url: URL): Route | null {
|
||||
view: { resource: "tree" },
|
||||
id,
|
||||
peer: undefined,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
},
|
||||
};
|
||||
}
|
||||
const params = resolveProjectRoute(url, hostnamePort, id, segments);
|
||||
const params = resolveProjectRoute(url, hostAndPort, id, segments);
|
||||
if (params) {
|
||||
return {
|
||||
resource: "projects",
|
||||
params: {
|
||||
...params,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
id,
|
||||
},
|
||||
};
|
||||
@@ -158,7 +158,7 @@ function pathToRoute(url: URL): Route | null {
|
||||
}
|
||||
return {
|
||||
resource: "seeds",
|
||||
params: { hostnamePort, projectPageIndex: 0 },
|
||||
params: { hostAndPort, projectPageIndex: 0 },
|
||||
};
|
||||
}
|
||||
return null;
|
||||
@@ -192,11 +192,11 @@ export function routeToPath(route: Route) {
|
||||
} else if (route.resource === "session") {
|
||||
return `/session?id=${route.params.id}&sig=${route.params.signature}&pk=${route.params.publicKey}`;
|
||||
} else if (route.resource === "seeds") {
|
||||
return `/seeds/${route.params.hostnamePort}`;
|
||||
return `/seeds/${route.params.hostAndPort}`;
|
||||
} else if (route.resource === "loadError") {
|
||||
return "";
|
||||
} else if (route.resource === "projects") {
|
||||
const hostnamePortPrefix = `/seeds/${route.params.hostnamePort}`;
|
||||
const hostAndPortPrefix = `/seeds/${route.params.hostAndPort}`;
|
||||
const content = `/${route.params.view.resource}`;
|
||||
|
||||
let peer = "";
|
||||
@@ -230,31 +230,31 @@ export function routeToPath(route: Route) {
|
||||
|
||||
if (route.params.view.resource === "tree") {
|
||||
if (suffix) {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/tree${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/tree${suffix}`;
|
||||
}
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}`;
|
||||
} else if (route.params.view.resource === "commits") {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/commits${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/commits${suffix}`;
|
||||
} else if (route.params.view.resource === "history") {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/history${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/history${suffix}`;
|
||||
} else if (
|
||||
route.params.view.resource === "issues" &&
|
||||
route.params.view.params?.view.resource === "new"
|
||||
) {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/issues/new${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/issues/new${suffix}`;
|
||||
} else if (route.params.view.resource === "issues") {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/issues${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/issues${suffix}`;
|
||||
} else if (route.params.view.resource === "issue") {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/issues/${route.params.view.params.issue}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/issues/${route.params.view.params.issue}`;
|
||||
} else if (route.params.view.resource === "patches") {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/patches${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/patches${suffix}`;
|
||||
} else if (route.params.view.resource === "patch") {
|
||||
if (route.params.view.params.revision) {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}/${route.params.view.params.revision}${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}/${route.params.view.params.revision}${suffix}`;
|
||||
}
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}${suffix}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}/patches/${route.params.view.params.patch}${suffix}`;
|
||||
} else {
|
||||
return `${hostnamePortPrefix}/${route.params.id}${peer}${content}`;
|
||||
return `${hostAndPortPrefix}/${route.params.id}${peer}${content}`;
|
||||
}
|
||||
} else if (route.resource === "booting") {
|
||||
return "";
|
||||
|
||||
+16
-10
@@ -244,18 +244,18 @@ export function twemoji(
|
||||
});
|
||||
}
|
||||
|
||||
export function extractBaseUrl(hostnamePort: string): BaseUrl {
|
||||
export function extractBaseUrl(hostAndPort: string): BaseUrl {
|
||||
if (
|
||||
hostnamePort === "radicle.local" ||
|
||||
hostnamePort === "radicle.local:8080" ||
|
||||
hostnamePort === "0.0.0.0" ||
|
||||
hostnamePort === "0.0.0.0:8080" ||
|
||||
hostnamePort === "127.0.0.1" ||
|
||||
hostnamePort === "127.0.0.1:8080"
|
||||
hostAndPort === "radicle.local" ||
|
||||
hostAndPort === "radicle.local:8080" ||
|
||||
hostAndPort === "0.0.0.0" ||
|
||||
hostAndPort === "0.0.0.0:8080" ||
|
||||
hostAndPort === "127.0.0.1" ||
|
||||
hostAndPort === "127.0.0.1:8080"
|
||||
) {
|
||||
return { hostname: "127.0.0.1", port: 8080, scheme: "http" };
|
||||
} else if (hostnamePort.includes(":")) {
|
||||
const [hostname, port] = hostnamePort.split(":");
|
||||
} else if (hostAndPort.includes(":")) {
|
||||
const [hostname, port] = hostAndPort.split(":");
|
||||
return {
|
||||
hostname,
|
||||
port: Number(port),
|
||||
@@ -263,13 +263,19 @@ export function extractBaseUrl(hostnamePort: string): BaseUrl {
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
hostname: hostnamePort,
|
||||
hostname: hostAndPort,
|
||||
port: config.seeds.defaultHttpdPort,
|
||||
scheme: config.seeds.defaultHttpdScheme,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getHostAndPort(baseUrl: BaseUrl): string {
|
||||
return baseUrl.port === config.seeds.defaultHttpdPort
|
||||
? baseUrl.hostname
|
||||
: `${baseUrl.hostname}:${baseUrl.port}`;
|
||||
}
|
||||
|
||||
export function createAddRemoveArrays(
|
||||
currentArray: string[],
|
||||
newArray: string[],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { ProjectBaseUrlActivity } from "./router";
|
||||
|
||||
import { twemoji } from "@app/lib/utils";
|
||||
import { getHostAndPort, twemoji } from "@app/lib/utils";
|
||||
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import ProjectCard from "@app/components/ProjectCard.svelte";
|
||||
@@ -78,7 +78,7 @@
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
id: project.id,
|
||||
hostnamePort: baseUrl.hostname,
|
||||
hostAndPort: getHostAndPort(baseUrl),
|
||||
peer: undefined,
|
||||
revision: undefined,
|
||||
},
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import type { BaseUrl } from "@httpd-client";
|
||||
import type { ProjectLoadedView } from "@app/views/projects/router";
|
||||
|
||||
import { config } from "@app/lib/config";
|
||||
import { isLocal } from "@app/lib/utils";
|
||||
import { getHostAndPort, isLocal } from "@app/lib/utils";
|
||||
import { pluralize } from "@app/lib/pluralize";
|
||||
|
||||
import CloneButton from "@app/views/projects/CloneButton.svelte";
|
||||
@@ -108,10 +107,7 @@
|
||||
route={{
|
||||
resource: "seeds",
|
||||
params: {
|
||||
hostnamePort:
|
||||
baseUrl.port === config.seeds.defaultHttpdPort
|
||||
? baseUrl.hostname
|
||||
: `${baseUrl.hostname}:${baseUrl.port}`,
|
||||
hostAndPort: getHostAndPort(baseUrl),
|
||||
projectPageIndex: 0,
|
||||
},
|
||||
}}>
|
||||
|
||||
@@ -141,7 +141,7 @@
|
||||
resource: "projects",
|
||||
params: {
|
||||
id: projectId,
|
||||
hostnamePort: baseUrl.hostname,
|
||||
hostAndPort: utils.getHostAndPort(baseUrl),
|
||||
view: {
|
||||
resource: "issue",
|
||||
params: { issue: issue.id },
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import Patches from "./Patches.svelte";
|
||||
import ProjectMeta from "./ProjectMeta.svelte";
|
||||
|
||||
export let hostnamePort: string;
|
||||
export let hostAndPort: string;
|
||||
export let id: string;
|
||||
export let project: Project;
|
||||
export let view: ProjectLoadedView;
|
||||
@@ -43,7 +43,7 @@
|
||||
(searchParams.get("tab") as "activity" | "commits" | "files") || "activity";
|
||||
$: patchFilter = (searchParams.get("state") as PatchStatus) || "open";
|
||||
$: patchDiffFilter = searchParams.get("diff") || undefined;
|
||||
$: baseUrl = utils.extractBaseUrl(hostnamePort);
|
||||
$: baseUrl = utils.extractBaseUrl(hostAndPort);
|
||||
$: api = new HttpdClient(baseUrl);
|
||||
|
||||
function handleIssueCreation({ detail: issueId }: CustomEvent<string>) {
|
||||
@@ -51,7 +51,7 @@
|
||||
resource: "projects",
|
||||
params: {
|
||||
id,
|
||||
hostnamePort: httpd.api.hostnamePort,
|
||||
hostAndPort: httpd.api.hostAndPort,
|
||||
view: {
|
||||
resource: "issue",
|
||||
params: { issue: issueId },
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface ProjectLoadedRoute {
|
||||
export interface ProjectsParams {
|
||||
id: string;
|
||||
hash?: string;
|
||||
hostnamePort: string;
|
||||
hostAndPort: string;
|
||||
path?: string;
|
||||
peer?: string;
|
||||
revision?: string;
|
||||
@@ -56,7 +56,7 @@ export interface ProjectsParams {
|
||||
}
|
||||
|
||||
export interface ProjectLoadedParams {
|
||||
hostnamePort: string;
|
||||
hostAndPort: string;
|
||||
id: string;
|
||||
project: Project;
|
||||
view: ProjectLoadedView;
|
||||
@@ -146,7 +146,7 @@ export function parseRevisionToOid(
|
||||
export async function loadProjectRoute(
|
||||
params: ProjectsParams,
|
||||
): Promise<ProjectLoadedRoute | LoadError> {
|
||||
const baseUrl = extractBaseUrl(params.hostnamePort);
|
||||
const baseUrl = extractBaseUrl(params.hostAndPort);
|
||||
const api = new HttpdClient(baseUrl);
|
||||
try {
|
||||
if (
|
||||
@@ -408,7 +408,7 @@ export async function updateProjectRoute(
|
||||
|
||||
export function resolveProjectRoute(
|
||||
url: URL,
|
||||
hostnamePort: string,
|
||||
hostAndPort: string,
|
||||
id: string,
|
||||
segments: string[],
|
||||
): ProjectsParams | null {
|
||||
@@ -424,7 +424,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "tree" },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
path: undefined,
|
||||
revision: undefined,
|
||||
@@ -436,7 +436,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "history" },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
path: undefined,
|
||||
revision: undefined,
|
||||
@@ -447,7 +447,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "commits" },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
path: undefined,
|
||||
revision: undefined,
|
||||
@@ -460,7 +460,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "issues", params: { view: { resource: "new" } } },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
search: sanitizeQueryString(url.search),
|
||||
path: undefined,
|
||||
@@ -470,7 +470,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "issue", params: { issue: issueOrAction } },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
path: undefined,
|
||||
revision: undefined,
|
||||
@@ -480,7 +480,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "issues" },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
search: sanitizeQueryString(url.search),
|
||||
path: undefined,
|
||||
@@ -494,7 +494,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "patch", params: { patch, revision } },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
path: undefined,
|
||||
revision: undefined,
|
||||
@@ -504,7 +504,7 @@ export function resolveProjectRoute(
|
||||
return {
|
||||
view: { resource: "patches" },
|
||||
id,
|
||||
hostnamePort,
|
||||
hostAndPort,
|
||||
peer,
|
||||
search: sanitizeQueryString(url.search),
|
||||
path: undefined,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import type { ProjectActivity } from "@app/views/seeds/router";
|
||||
|
||||
import { config } from "@app/lib/config";
|
||||
import { isLocal, truncateId } from "@app/lib/utils";
|
||||
import { getHostAndPort, isLocal, truncateId } from "@app/lib/utils";
|
||||
import { loadProjects } from "@app/views/seeds/router";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
@@ -131,10 +131,7 @@
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
id: project.id,
|
||||
hostnamePort:
|
||||
baseUrl.port === config.seeds.defaultHttpdPort
|
||||
? baseUrl.hostname
|
||||
: `${baseUrl.hostname}:${baseUrl.port}`,
|
||||
hostAndPort: getHostAndPort(baseUrl),
|
||||
revision: undefined,
|
||||
hash: undefined,
|
||||
search: undefined,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { extractBaseUrl } from "@app/lib/utils";
|
||||
import { loadProjectActivity } from "@app/lib/commit";
|
||||
|
||||
interface SeedsRouteParams {
|
||||
hostnamePort: string;
|
||||
hostAndPort: string;
|
||||
projectPageIndex: number;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ export async function loadProjects(
|
||||
export async function loadSeedRoute(
|
||||
params: SeedsRouteParams,
|
||||
): Promise<SeedsLoadedRoute | LoadError> {
|
||||
const baseUrl = extractBaseUrl(params.hostnamePort);
|
||||
const baseUrl = extractBaseUrl(params.hostAndPort);
|
||||
const api = new HttpdClient(baseUrl);
|
||||
try {
|
||||
const projectPageIndex = 0;
|
||||
@@ -91,7 +91,7 @@ export async function loadSeedRoute(
|
||||
return {
|
||||
resource: "loadError",
|
||||
params: {
|
||||
title: params.hostnamePort,
|
||||
title: params.hostAndPort,
|
||||
errorMessage: "Not able to query this seed.",
|
||||
stackTrace: error.stack,
|
||||
},
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
modal.show({ component: AuthenticatedModal, props: {} });
|
||||
void router.push({
|
||||
resource: "seeds",
|
||||
params: { hostnamePort: httpd.api.hostnamePort, projectPageIndex: 0 },
|
||||
params: {
|
||||
hostAndPort: httpd.api.hostAndPort,
|
||||
projectPageIndex: 0,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
modal.show({
|
||||
|
||||
@@ -10,7 +10,7 @@ describe("routeToPath", () => {
|
||||
{
|
||||
input: {
|
||||
resource: "seeds",
|
||||
params: { hostnamePort: "willow.radicle.garden" },
|
||||
params: { hostAndPort: "willow.radicle.garden" },
|
||||
},
|
||||
output: "/seeds/willow.radicle.garden",
|
||||
description: "Seed View Route",
|
||||
@@ -20,7 +20,7 @@ describe("routeToPath", () => {
|
||||
resource: "projects",
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
hostnamePort: "willow.radicle.garden",
|
||||
hostAndPort: "willow.radicle.garden",
|
||||
id: "rad:zKtT7DmF9H34KkvcKj9PHW19WzjT",
|
||||
},
|
||||
},
|
||||
@@ -54,7 +54,7 @@ describe("pathToRoute", () => {
|
||||
input: new URL("/seeds/willow.radicle.garden", dummyUrl),
|
||||
output: {
|
||||
resource: "seeds",
|
||||
params: { hostnamePort: "willow.radicle.garden", projectPageIndex: 0 },
|
||||
params: { hostAndPort: "willow.radicle.garden", projectPageIndex: 0 },
|
||||
},
|
||||
description: "Seed View Route",
|
||||
},
|
||||
@@ -67,7 +67,7 @@ describe("pathToRoute", () => {
|
||||
resource: "projects",
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
hostnamePort: "willow.radicle.garden",
|
||||
hostAndPort: "willow.radicle.garden",
|
||||
profile: undefined,
|
||||
peer: undefined,
|
||||
id: "rad:zKtT7DmF9H34KkvcKj9PHW19WzjT",
|
||||
@@ -92,7 +92,7 @@ describe("pathToRoute", () => {
|
||||
resource: "projects",
|
||||
params: {
|
||||
view: { resource: "tree" },
|
||||
hostnamePort: "willow.radicle.garden",
|
||||
hostAndPort: "willow.radicle.garden",
|
||||
profile: undefined,
|
||||
peer: undefined,
|
||||
id: "rad:zKtT7DmF9H34KkvcKj9PHW19WzjT",
|
||||
|
||||
Reference in New Issue
Block a user