Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix jsonld resolve #43

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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