feat: initial version
This commit is contained in:
parent
cc3d532bea
commit
6d8e0c3aad
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"preset": [
|
||||
"@lumeweb/presetter-kernel-module-preset"
|
||||
],
|
||||
"config": {
|
||||
"official": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "@lumeweb/resolver-module-cid",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"readme": "ERROR: No README data found!",
|
||||
"_id": "@lumeweb/resolver-module-cid@0.1.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "gitea@git.lumeweb.com:LumeWeb/resolver-module-cid.git"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "presetter bootstrap",
|
||||
"build": "run build",
|
||||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lumeweb/kernel-libresolver": "^0.1.0-develop.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.44"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { setup } from "@lumeweb/kernel-libresolver";
|
||||
import CID from "./resolver.js";
|
||||
|
||||
// @ts-ignore
|
||||
setup(new CID());
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
import {
|
||||
AbstractResolverModule,
|
||||
DNS_RECORD_TYPE,
|
||||
DNSResult,
|
||||
resolverEmptyResponse,
|
||||
ResolverOptions,
|
||||
resolveSuccess,
|
||||
} from "@lumeweb/kernel-libresolver";
|
||||
|
||||
const NETWORK_MAP = new Map(
|
||||
Object.entries({
|
||||
IPFS: "ipfs://",
|
||||
IPNS: "ipns://",
|
||||
}),
|
||||
);
|
||||
|
||||
const NAMESPACE = "lume";
|
||||
|
||||
export default class CID extends AbstractResolverModule {
|
||||
ready(): Promise<void> {
|
||||
return Promise.resolve(true) as any;
|
||||
}
|
||||
|
||||
async resolve(
|
||||
domain: string,
|
||||
options: ResolverOptions,
|
||||
bypassCache: boolean,
|
||||
): Promise<DNSResult> {
|
||||
if (!domain.includes(".")) {
|
||||
return resolverEmptyResponse();
|
||||
}
|
||||
|
||||
const domainParts = domain.split(".");
|
||||
const last = domainParts.slice()?.pop();
|
||||
if (last !== NAMESPACE) {
|
||||
return resolverEmptyResponse();
|
||||
}
|
||||
|
||||
const network = domainParts.slice(1).shift()?.toUpperCase() as string;
|
||||
|
||||
if (!NETWORK_MAP.has(network)) {
|
||||
return resolverEmptyResponse();
|
||||
}
|
||||
|
||||
const cid = domainParts.slice()?.shift();
|
||||
|
||||
if (!cid) {
|
||||
return resolverEmptyResponse();
|
||||
}
|
||||
|
||||
return resolveSuccess([
|
||||
{
|
||||
type: DNS_RECORD_TYPE.CONTENT,
|
||||
value: NETWORK_MAP.get(network) + cid,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue