TheGame icon indicating copy to clipboard operation
TheGame copied to clipboard

IPNS websites support

Open alexjorgef opened this issue 2 years ago • 6 comments

What would you like to be added?

On the user's profile page, beside ipfs://, http://, https://, the user should be able to add a website with a ipns:// URL schema.

image

This is an interesting feature for me and loved to help with the implementation

Why is this needed?

The problem with ipfs://<CID> schema is when the website's files update, a new CID is generated. Adding IPNS permits websites hosted in IPFS to update dynamically by pointing a IPNS record name to a mutable/immutable path (ref).

alexjorgef avatar Jan 24 '23 06:01 alexjorgef

This sounds doable.

It would likely take modifying httpLink and the input validation.

In constants I'd change:

export const IPFS_LINK_PATTERN =
  process.env.NEXT_PUBLIC_IPFS_LINK_PATTERN ||
  'https://ipfs.io/ipfs/{cid}/{path}'

To:

export const IPFS_LINK_PATTERN =
  process.env.NEXT_PUBLIC_IPFS_LINK_PATTERN ||
  'https://ipfs.io/{protocol}/{cid}/{path}'

Then the httpLink function should look something like:

export const httpLink = (uri?: Maybe<string>) => {
  const [, proto, origCID, path] =
    uri?.match(/^(ip[nf]s):(?:\/\/)?([^/]+)(?:\/(.*))?$/) ?? [];

  try {
    if (origCID) {
      const cid = new CID(origCID);

      let v0CID = '';
      try {
        v0CID = cid.toV0().toString();
      } catch {}

      let v1CID = '';
      try {
        v1CID = cid.toV1().toString('base32');
      } catch {}

      const pattern = IPFS_LINK_PATTERN;
      return pattern
        .replace(/{protocol}/g, proto)
        .replace(/{cid}/g, origCID)
        .replace(/{v0cid}/g, v0CID)
        .replace(/{v1cid}/g, v1CID)
        .replace(/{path}/g, path ?? '');
    }
  } catch {}

  return uri ?? undefined; // Image.src won't take null
};

dysbulic avatar Jan 24 '23 07:01 dysbulic

I sent you an invite to the MetaFam organization. If you make a pull request, could you do it from a branch pushed to the MetaFam/TheGame repo?

The test instances won't work with forks from other accounts.

dysbulic avatar Jan 24 '23 07:01 dysbulic

I sent you an invite to the MetaFam organization. If you make a pull request, could you do it from a branch pushed to the TheGame repo?

The test instances won't work with forks from other accounts.

Great!! I will delete my fork, thank you. Looking to test and open a pull request

alexjorgef avatar Jan 24 '23 07:01 alexjorgef

Though at this point in time we don't display the website anywhere in the profile. It is stored in Ceramic, however, and accessible to any parties that might want to look it up.

We are undergoing a significant revamp of the backend of the profiling system, and homepages might may it into the new version…

dysbulic avatar Jan 24 '23 07:01 dysbulic

I understand, tracking the progress on that and any related commits

alexjorgef avatar Jan 24 '23 07:01 alexjorgef

If you add ?debug=t to the profile URL, it should print out the Ceramic stream ids for your basic and extended profile to the console when you save. You can then put those in Cerscan and see what they contain (i.e. if your website saved correctly).

dysbulic avatar Jan 24 '23 07:01 dysbulic