Skip to content

Instantly share code, notes, and snippets.

@sebastinez
Last active December 14, 2021 09:00
Show Gist options
  • Save sebastinez/65e59bc81e6c02e663323dfd68a1e08b to your computer and use it in GitHub Desktop.
Save sebastinez/65e59bc81e6c02e663323dfd68a1e08b to your computer and use it in GitHub Desktop.
Allow seed version to be used in queries
diff --git a/src/base/registrations/registrar.ts b/src/base/registrations/registrar.ts
index 6ed987c..2723a5a 100644
--- a/src/base/registrations/registrar.ts
+++ b/src/base/registrations/registrar.ts
@@ -142,7 +143,11 @@ export async function getSeed(name: string, config: Config, resolver?: EnsResolv
resolver.getText('eth.radicle.seed.api'),
]);
- return new Seed(config, host, id, git, api);
+ const seed = new Seed(config, host, id, git, api);
+ // Queries the seeds version and sets the version property
+ await seed.setVersion();
+
+ return seed;
}
export function registrar(config: Config): ethers.Contract {
diff --git a/src/base/seeds/Seed.ts b/src/base/seeds/Seed.ts
index c43e301..17d7f20 100644
--- a/src/base/seeds/Seed.ts
+++ b/src/base/seeds/Seed.ts
@@ -13,6 +13,7 @@ export class Seed {
id?: string;
git?: string;
api?: string;
+ version?: string;
config: Config;
constructor(config: Config, host?: string, id?: string, git?: string, api?: string) {
@@ -43,4 +44,8 @@ export class Seed {
const result = await getProjects(this.config);
return result.map((project: any) => ({ ...project, id: project.urn }));
}
+ async setVersion(): Promise<void> {
+ const result = await api.get('', {}, this.config);
+ this.version = result.version;
+ }
}
diff --git a/src/config.json b/src/config.json
index fdc7b24..b870c50 100644
--- a/src/config.json
+++ b/src/config.json
@@ -76,7 +76,8 @@
"host": "0.0.0.0",
"api": { "port": 8777 },
"link": { "port": 8776 },
- "git": { "port": 80 }
+ "git": { "port": 80 },
+ "version": "0.2.0"
}
},
"ipfs": { "gateway": "https://ipfs.io/ipfs/" },
diff --git a/src/config.ts b/src/config.ts
index 38594fc..4d79202 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -57,9 +57,10 @@ export class Config {
};
abi: { [contract: string]: string[] };
seed: {
- api: { host?: string; port: number };
- git: { host?: string; port: number };
+ api: { host?: string; id?: string; port: number };
+ git: { host?: string; id?: string; port: number };
link: { host?: string; id?: string; port: number };
+ version: string;
};
ceramic: {
client: Core;
diff --git a/src/project.ts b/src/project.ts
index 8343cdb..c05cc94 100644
--- a/src/project.ts
+++ b/src/project.ts
@@ -95,7 +95,9 @@ export async function getTree(
if (path === "/") {
path = "";
}
- return api.get(`projects/${urn}/tree/${commit}/${path}`, {}, config);
+ return config.seed.version == "0.2.0"
+ ? api.get(`projects/${urn}/tree/${config.seed.link.id}/${commit}/${path}`, {}, config)
+ : api.get(`projects/${urn}/tree/${commit}/${path}`, {}, config);
}
export async function getBlob(
@@ -105,7 +107,9 @@ export async function getBlob(
options: { highlight: boolean },
config: Config
): Promise<Blob> {
- return api.get(`projects/${urn}/blob/${commit}/${path}`, options, config);
+ return config.seed.version == "0.2.0"
+ ? api.get(`projects/${urn}/blob/${config.seed.link.id}/${commit}/${path}`, options, config)
+ : api.get(`projects/${urn}/blob/${commit}/${path}`, options, config);
}
export async function getReadme(
@@ -113,7 +117,9 @@ export async function getReadme(
commit: string,
config: Config
): Promise<Blob> {
- return api.get(`projects/${urn}/readme/${commit}`, {}, config);
+ return config.seed.version == "0.2.0"
+ ? api.get(`projects/${urn}/readme/${config.seed.link.id}/${commit}`, {}, config)
+ : api.get(`projects/${urn}/readme/${commit}`, {}, config);
}
export function path(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment