Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Support custom seed ports via URLs
Alexis Sellier committed 4 years ago
commit 69b45e1cf02f8f8730257c1ff002951eaada3446
parent 19c1676f5008358df003e2b41a58113866e15981
3 files changed +55 -3
added src/base/seeds/Seed.spec.ts
@@ -0,0 +1,48 @@
+
import { Seed } from "./Seed";
+
import { Config } from "@app/config";
+

+
describe('Seed', function () {
+
  it("Constructs git host correctly", () => {
+
    const cfg = new Config({ name: "homestead", chainId: 1 }, null as any, null);
+
    const seed = new Seed({
+
      host: "seed.cloudhead.io",
+
      id: "hydzjm73tstmdcwhach3psfgkunbjpih7ztnuswhw9w6h9pi5sffd6",
+
      git: "git.seed.cloudhead.io",
+
    }, cfg);
+

+
    expect(seed.git.host).to.eq("git.seed.cloudhead.io");
+
    expect(seed.git.port).to.eq(443);
+

+
    expect(seed.host).to.eq("seed.cloudhead.io");
+
    expect(seed.api.host).to.eq(seed.host);
+
    expect(seed.api.port).to.eq(8777);
+
  });
+

+
  it("Constructs git host correctly with custom port", () => {
+
    const cfg = new Config({ name: "homestead", chainId: 1 }, null as any, null);
+
    const seed = new Seed({
+
      host: "seed.cloudhead.io",
+
      id: "hydzjm73tstmdcwhach3psfgkunbjpih7ztnuswhw9w6h9pi5sffd6",
+
      git: "https://git.seed.cloudhead.io:8778",
+
    }, cfg);
+

+
    expect(seed.git.host).to.eq("git.seed.cloudhead.io");
+
    expect(seed.git.port).to.eq(8778);
+
  });
+

+
  it("Constructs api host correctly", () => {
+
    const cfg = new Config({ name: "homestead", chainId: 1 }, null as any, null);
+
    const seed = new Seed({
+
      host: "seed.cloudhead.io",
+
      id: "hydzjm73tstmdcwhach3psfgkunbjpih7ztnuswhw9w6h9pi5sffd6",
+
      api: "https://api.seed.cloudhead.io:8080",
+
    }, cfg);
+

+
    expect(seed.api.host).to.eq("api.seed.cloudhead.io");
+
    expect(seed.api.port).to.eq(8080);
+

+
    expect(seed.host).to.eq("api.seed.cloudhead.io");
+
    expect(seed.git.host).to.eq("seed.cloudhead.io");
+
    expect(seed.git.port).to.eq(443);
+
  });
+
});
modified src/base/seeds/Seed.ts
@@ -38,11 +38,14 @@ export class Seed {

    let api = null;
    let git = null;
+
    let apiPort = null;
+
    let gitPort = null;

    if (seed.api) {
      try {
        const url = new URL(seed.api);
        api = url.hostname;
+
        apiPort = url.port || null;
      } catch {
        api = seed.api;
      }
@@ -53,6 +56,7 @@ export class Seed {
      try {
        const url = new URL(seed.git);
        git = url.hostname;
+
        gitPort = url.port || null;
      } catch {
        git = seed.git;
      }
@@ -71,8 +75,8 @@ export class Seed {
    api = api ?? seed.host;
    git = git ?? seed.host;

-
    this.api = { host: api, port: cfg.seed.api.port };
-
    this.git = { host: git, port: cfg.seed.git.port };
+
    this.api = { host: api, port: Number(apiPort) || cfg.seed.api.port };
+
    this.git = { host: git, port: Number(gitPort) || cfg.seed.git.port };
    this.link = { host: seed.host, id: seed.id, port: cfg.seed.link.port };

    if (seed.version) {
modified src/config.json
@@ -90,7 +90,7 @@
    "seed": {
      "api": { "port": 8777 },
      "link": { "port": 8776 },
-
      "git": { "port": 80 }
+
      "git": { "port": 443 }
    }
  },
  "ipfs": { "gateway": "https://ipfs.io/ipfs/" },