embed icon indicating copy to clipboard operation
embed copied to clipboard

Async id function?

Open aq1 opened this issue 2 years ago • 1 comments

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 avatar Feb 04 '23 12:02 aq1

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,
    };
  }
}

aq1 avatar Feb 04 '23 13:02 aq1