Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async id function? #106

Open
aq1 opened this issue Feb 4, 2023 · 1 comment
Open

Async id function? #106

aq1 opened this issue Feb 4, 2023 · 1 comment

Comments

@aq1
Copy link

aq1 commented Feb 4, 2023

I know now it is not an option but imagine this use case. If you paste shorten link to sketchfab (for example https://skfb.ly/oDtnZ) you need to make request to this url and follow redirects to find real id to be inserted in iframe. So the id function would be like this:

@aq1
Copy link
Author

aq1 commented Feb 4, 2023

As an option:

class AsyncIDEmbed extends Embed {
  async onPaste(event) {
    const { key: service, data: url } = event.detail;

    const { regex, embedUrl, width, height, id = async (ids) => ids.shift() } = Embed.services[service];
    const result = regex.exec(url).slice(1);
    const embed = embedUrl.replace(/<%= remote_id %>/g, await id(result));
    this.data = {
      service,
      source: url,
      embed,
      width,
      height,
    };
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant