queen-raae / gatsby-remark-oembed

A GatsbyJS Plugin that transforms oembed links into its corresponding embed code.
https://gatsby-remark-oembed.netlify.com/
MIT License
162 stars 25 forks source link

Create a new release #145

Open raae opened 3 years ago

YoranBrondsema commented 3 years ago

Yes please! Anything I can do to get the Instagram fix into a new release?

raae commented 3 years ago

A new release does not fix Instagram, one has to add an access_token to the Setting to do so. See the updated readme.

I should of course also get on with making a new release as well. I might reach out to you to test the new release before releasing.

raae commented 3 years ago

I see that the order of Instagram endpoints have been changed in the provider list this plugin rely on, meaning the deprecated endpoint is now favoured. I do not understand why it is in there at all, I will make a PR against @iamcal/oembed.

So even with adding an access_token it will be broken right now.

I am thinking more and more that I might need to keep my own vetted list, or get more involved with that repo as well.

YoranBrondsema commented 3 years ago

I agree, it's confusing that in https://github.com/iamcal/oembed/blob/1db773d2665db51101776744f04a0a15b0086bdc/providers/instagram.yml a same URL can match multiple endpoints.

It does seem like the schemes in @iamcal/oembed are sorted by order of preference though. So the first match should be the "correct" one. If that's the assumption, then it would make sense to rewrite https://github.com/raae/gatsby-remark-oembed/blob/master/gatsby-remark-oembed/utils/getProviderEndpointForLinkUrl.js as:

const getProviderEndpointForLinkUrl = (linkUrl, providers) => {
  for (const provider of providers || []) {
    for (const endpoint of provider.endpoints || []) {
      const isInstagram = provider.provider_name === "Instagram";
      const hasAccessToken = provider.params && provider.params.access_token;

      for (let schema of endpoint.schemes || []) {
        schema = schema.replace("*", ".*");
        const regExp = new RegExp(schema);
        const isMatchingSchema = regExp.test(linkUrl);

        if (isMatchingSchema && isInstagram && !hasAccessToken) {
          throw new Error(
            "Instagram require you to configure an access_token. For more information, visit https://developers.facebook.com/docs/instagram/oembed/."
          );
        } else if (isMatchingSchema) {
          return {
            url: endpoint.url,
            params: {
              url: linkUrl,
              ...provider.params
            }
          };
        }
      }
    }
  }

  return {};
};

so return early as soon as a match is found. Would that make sense?

raae commented 3 years ago

The deprecated endpoint has been removed (https://github.com/iamcal/oembed/pull/515), it should be reflected in the provider list within an hour and Instagram embed should work again if you provide an access_token.

raae commented 3 years ago

@YoranBrondsema I would like to do a complete refactor of the code you reference as this was my first ever node project and I have learned a lot since then. Therefore I do not think we need to update this now as all providers should have only one match for the foreseeable future.

However when I get around to diagramming the refactor and roadmap for this plugin I would love to have you contribute.

YoranBrondsema commented 3 years ago

@raae Sounds good! Thanks for following up on the issue on https://github.com/iamcal/oembed.

raae commented 2 years ago

Working on it, help test the next version - see https://github.com/queen-raae/gatsby-remark-oembed/discussions/159