diff --git a/lib/properties/cover-property.js b/lib/properties/cover-property.js index c4d62f6..13f58b5 100644 --- a/lib/properties/cover-property.js +++ b/lib/properties/cover-property.js @@ -18,6 +18,12 @@ class CoverProperty extends Property { mediaType: '', }, ], + forms: [ + { + href: '', + contentType: '', + }, + ], }); this.updateImage(this.device.adapter.config.altcover); } @@ -36,17 +42,32 @@ class CoverProperty extends Property { updateImage(url) { let filename; - if (url.toLowerCase().endsWith('.png')) { - this.links[0].mediaType = 'image/png'; - filename = 'cover.png'; - } else if (url.toLowerCase().endsWith('.gif')) { - this.links[0].mediaType = 'image/gif'; - filename = 'cover.gif'; - } else { - this.links[0].mediaType = 'image/jpeg'; - filename = 'cover.jpg'; + if (this.links) { + if (url.toLowerCase().endsWith('.png')) { + this.links[0].mediaType = 'image/png'; + filename = 'cover.png'; + } else if (url.toLowerCase().endsWith('.gif')) { + this.links[0].mediaType = 'image/gif'; + filename = 'cover.gif'; + } else { + this.links[0].mediaType = 'image/jpeg'; + filename = 'cover.jpg'; + } + this.links[0].href = `/media/frontier-silicon/${this.device.id}/${filename}`; + } + if (this.forms) { + if (url.toLowerCase().endsWith('.png')) { + this.forms[0].contentType = 'image/png'; + filename = 'cover.png'; + } else if (url.toLowerCase().endsWith('.gif')) { + this.forms[0].contentType = 'image/gif'; + filename = 'cover.gif'; + } else { + this.forms[0].contentType = 'image/jpeg'; + filename = 'cover.jpg'; + } + this.forms[0].href = `/media/frontier-silicon/${this.device.id}/${filename}`; } - this.links[0].href = `/media/frontier-silicon/${this.device.id}/${filename}`; saveImageTo(url, path.join(this.device.mediaDir, filename), () => { this.device.adapter.handleDeviceUpdated(this.device); });