MetaFam / TheGame

The platform that MetaGame will be played on aka MetaOS - an open source framework for running decentralized societies. Currently featuring MyMeta Profiles, Dashboard & Quests
https://metagame.wtf
Other
131 stars 78 forks source link

IPNS websites support #1511

Open alexjorgef opened 1 year ago

alexjorgef commented 1 year ago

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).

dysbulic commented 1 year ago

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 commented 1 year ago

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.

alexjorgef commented 1 year ago

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

dysbulic commented 1 year ago

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…

alexjorgef commented 1 year ago

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

dysbulic commented 1 year ago

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).