From d2885365adfc1604f2efe4ed4429cc7aa50b4faa Mon Sep 17 00:00:00 2001 From: Sina Iman Date: Thu, 24 Oct 2024 09:02:15 -0400 Subject: [PATCH] fix jsonld resolve --- src/api/v2/resolvers/generic.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/api/v2/resolvers/generic.ts b/src/api/v2/resolvers/generic.ts index 6057f35..7eaa11c 100644 --- a/src/api/v2/resolvers/generic.ts +++ b/src/api/v2/resolvers/generic.ts @@ -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"; @@ -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 */ @@ -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,