Skip to content

Commit

Permalink
Merge pull request #44 from desci-labs/develop
Browse files Browse the repository at this point in the history
promote main
  • Loading branch information
hubsmoke authored Oct 24, 2024
2 parents 6d3bf20 + 7921cdd commit 113d9dd
Show file tree
Hide file tree
Showing 2 changed files with 32 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
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ const port = process.env.PORT || 5460;
app.use(pinoHttp({ logger }));
app.use(express.json());

/** Wide open, since it:
* - only resolves public information
* - doesn't implement any type of auth
* - should be generally available to the public
*/
app.use(function (_req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, OPTIONS");
next();
});

app.use("/api", api);

// Should probably check connectivity with ceramic/blockchain RPC/IPFS node
Expand Down

0 comments on commit 113d9dd

Please sign in to comment.