refactor: our custom ipns cache should no longer be needed
This commit is contained in:
parent
2e7fdef740
commit
93dc1e76de
|
@ -17,10 +17,8 @@ import * as path from "path";
|
||||||
import { CID } from "multiformats/cid";
|
import { CID } from "multiformats/cid";
|
||||||
import { fileTypeFromBuffer } from "file-type";
|
import { fileTypeFromBuffer } from "file-type";
|
||||||
import extToMimes from "../mimes.js";
|
import extToMimes from "../mimes.js";
|
||||||
import NodeCache from "node-cache";
|
|
||||||
|
|
||||||
export default class IpfsProvider extends BaseProvider {
|
export default class IpfsProvider extends BaseProvider {
|
||||||
private _ipnsCache = new NodeCache({ stdTTL: 60 * 60 * 24 });
|
|
||||||
private _client = createClient();
|
private _client = createClient();
|
||||||
|
|
||||||
async shouldHandleRequest(
|
async shouldHandleRequest(
|
||||||
|
@ -76,13 +74,7 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
try {
|
try {
|
||||||
if (ipnsPath(cid)) {
|
if (ipnsPath(cid)) {
|
||||||
const cidHash = cid.replace("/ipns/", "");
|
const cidHash = cid.replace("/ipns/", "");
|
||||||
if (this._ipnsCache.has(cidHash)) {
|
|
||||||
cid = this._ipnsCache.get(cidHash);
|
|
||||||
} else {
|
|
||||||
cid = await this._client.ipns(cidHash);
|
cid = await this._client.ipns(cidHash);
|
||||||
this._ipnsCache.set(cidHash, cid);
|
|
||||||
}
|
|
||||||
|
|
||||||
cid = `/ipfs/${cid}`;
|
cid = `/ipfs/${cid}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue