Skip to content

Commit

Permalink
fix dpid resolver returning vNaN for an invalid version string, or hi…
Browse files Browse the repository at this point in the history
…jacking other routes with a version assumption, fix test
  • Loading branch information
kadamidev committed Jun 14, 2024
1 parent e3aaacd commit 5e189bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/dpid-reader/DpidReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,24 @@ export class DpidReader {
private static transformWeb = async (result: DpidResult, request: DpidRequest) => {
const { prefix, suffix, version, domain } = request;
const uuid = result.id64;
// debugger;
const output = { msg: `beta.dpid.org resolver`, params: request, uuid };

// TODO: support version=v1 syntax in Nodes and we can get rid of cleanVersion logic
const cleanVersion: string | undefined = !version
let cleanVersion: string | undefined = !version
? undefined
: version?.substring(0, 1) == "v"
? version
: `v${parseInt(version || "0") + 1}`;

if (cleanVersion === "vNaN") {
/**
** Not a valid version, so pass along the original string the user entered, it may route to other
** codex entities or the DPID may be an alias to another external non research object entity.
*/
cleanVersion = version;
}

let environment = prefix === "beta-dev" || domain === "dev-beta.dpid.org" ? "-dev" : "";
if (domain === "staging-beta.dpid.org") {
environment = "-staging";
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ app.get("/*", async (req: Request, res: Response) => {
extra: dpidRequest,
eventType: LogEventType.DPID_GET,
});

const dpidResult = await DpidReader.read(dpidRequest);
if (dpidResult.id16 == "0x0") {
logger.error("dpid not found");
throw new Error("dpid not found");
}
const redir = await DpidReader.transform(dpidResult, dpidRequest);
// debugger;
// res.send({ output, redir });
if (dpidRequest.jsonld) {
res.setHeader("Content-Type", "application/ld+json").send(redir);
Expand Down
2 changes: 1 addition & 1 deletion test/basics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe("dPID resolution", function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46";
const expected = "https://nodes.desci.com/dpid/46/attestations/scientific-manuscript";
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand Down

0 comments on commit 5e189bf

Please sign in to comment.