Skip to content

Commit

Permalink
Merge pull request #43 from desci-labs/fix-jsonld-resolve
Browse files Browse the repository at this point in the history
fix jsonld resolve
  • Loading branch information
hubsmoke authored Oct 24, 2024
2 parents 9f0cae9 + d288536 commit 7921cdd
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/api/v2/resolvers/generic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Request, Response } from "express";
import axios from "axios";
import type { ResearchObjectV1 } from "@desci-labs/desci-models";
import { RoCrateTransformer, type ResearchObjectV1 } from "@desci-labs/desci-models";

import parentLogger, { serializeError } from "../../../logger.js";
import analytics, { LogEventType } from "../../../analytics.js";
Expand Down Expand Up @@ -80,15 +80,6 @@ export const resolveGenericHandler = async (
const isRaw = query.raw !== undefined;
const isJsonld = query.jsonld !== undefined;

if (isJsonld) {
logger.error({ path, query }, "got request for jsonld");
return res.status(501).send({
error: "jsonld format not supported",
details: "jsonld formatted requests are not supported by the resolver",
...baseError,
});
}

/** dPID version identifier, possibly adjusted to 0-based indexing */
let versionIx: number | undefined;
/** dPID path suffix, possibly empty */
Expand All @@ -109,6 +100,25 @@ export const resolveGenericHandler = async (
}
}

if (isJsonld) {
logger.warn({ path, query }, "got request for jsonld");
const resolveResult = await resolveDpid(parseInt(dpid), versionIx);

// console.log({ resolveResult });

const manifestUrl = `${IPFS_GATEWAY}/${resolveResult.manifest}`;

const transformer = new RoCrateTransformer();

const response = await fetch(manifestUrl);

// console.log({ manifestUrl });

const roCrate = transformer.exportObject(await response.json());

return res.setHeader("Content-Type", "application/ld+json").send(JSON.stringify(roCrate));
}

analytics.log({
dpid: parseInt(dpid),
version: versionIx || -1,
Expand Down

0 comments on commit 7921cdd

Please sign in to comment.