structure-embed
v0.2.6
Published
Abstract class for creating embed hooks
Downloads
10
Readme
structure-embed
Abstract class for creating embed hooks. Create an implementation of this class
and register the hook
method of your instance with the dispatcher.
Example implementation
import {registerHook} from 'structure-dispatcher'
import Embed from 'structure-embed'
class ExampleEmbed extends Embed {
async processDigitalAsset(urlParts, digitalAsset) {
if(/\bexample\.com/.test(urlParts.hostname)) {
const embedUrl = `https://www.example.com/oembed?url=${urlParts.href}&format=json`
const embed = await this.fetchEmbed(embedUrl)
embed.mimetype = 'example/type'
return embed
}
}
}
const exampleEmbed = new ExampleEmbed()
registerHook({
when: 'after',
serviceName: 'digital-assets',
actionNames: ['getByUrl'],
}, exampleEmbed.hook)