mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-26 21:01:24 +02:00
Add fallback-content-type property
This commit is contained in:
parent
e5bb102ab1
commit
6f8e576c9b
@ -1006,12 +1006,16 @@ Display a widget provided by an external source (3rd party). If you want to lear
|
|||||||
| Name | Type | Required | Default |
|
| Name | Type | Required | Default |
|
||||||
| ---- | ---- | -------- | ------- |
|
| ---- | ---- | -------- | ------- |
|
||||||
| url | string | yes | |
|
| url | string | yes | |
|
||||||
|
| fallback-content-type | string | no | |
|
||||||
| allow-potentially-dangerous-html | boolean | no | false |
|
| allow-potentially-dangerous-html | boolean | no | false |
|
||||||
| parameters | key & value | no | |
|
| parameters | key & value | no | |
|
||||||
|
|
||||||
##### `url`
|
##### `url`
|
||||||
The URL of the extension.
|
The URL of the extension.
|
||||||
|
|
||||||
|
##### `fallback-content-type`
|
||||||
|
Optionally specify the fallback content type of the extension if the URL does not return a valid `Widget-Content-Type` header. Currently the only supported value for this property is `html`.
|
||||||
|
|
||||||
##### `allow-potentially-dangerous-html`
|
##### `allow-potentially-dangerous-html`
|
||||||
Whether to allow the extension to display HTML.
|
Whether to allow the extension to display HTML.
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ const (
|
|||||||
|
|
||||||
type ExtensionRequestOptions struct {
|
type ExtensionRequestOptions struct {
|
||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
|
FallbackContentType string `yaml:"fallback-content-type"`
|
||||||
Parameters map[string]string `yaml:"parameters"`
|
Parameters map[string]string `yaml:"parameters"`
|
||||||
AllowHtml bool `yaml:"allow-potentially-dangerous-html"`
|
AllowHtml bool `yaml:"allow-potentially-dangerous-html"`
|
||||||
}
|
}
|
||||||
@ -87,9 +88,13 @@ func FetchExtension(options ExtensionRequestOptions) (Extension, error) {
|
|||||||
|
|
||||||
contentType, ok := ExtensionStringToType[response.Header.Get(ExtensionHeaderContentType)]
|
contentType, ok := ExtensionStringToType[response.Header.Get(ExtensionHeaderContentType)]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
contentType, ok = ExtensionStringToType[options.FallbackContentType]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
contentType = ExtensionContentUnknown
|
contentType = ExtensionContentUnknown
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension.Content = convertExtensionContent(options, body, contentType)
|
extension.Content = convertExtensionContent(options, body, contentType)
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
type Extension struct {
|
type Extension struct {
|
||||||
widgetBase `yaml:",inline"`
|
widgetBase `yaml:",inline"`
|
||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
|
FallbackContentType string `yaml:"fallback-content-type"`
|
||||||
Parameters map[string]string `yaml:"parameters"`
|
Parameters map[string]string `yaml:"parameters"`
|
||||||
AllowHtml bool `yaml:"allow-potentially-dangerous-html"`
|
AllowHtml bool `yaml:"allow-potentially-dangerous-html"`
|
||||||
Extension feed.Extension `yaml:"-"`
|
Extension feed.Extension `yaml:"-"`
|
||||||
@ -39,6 +40,7 @@ func (widget *Extension) Initialize() error {
|
|||||||
func (widget *Extension) Update(ctx context.Context) {
|
func (widget *Extension) Update(ctx context.Context) {
|
||||||
extension, err := feed.FetchExtension(feed.ExtensionRequestOptions{
|
extension, err := feed.FetchExtension(feed.ExtensionRequestOptions{
|
||||||
URL: widget.URL,
|
URL: widget.URL,
|
||||||
|
FallbackContentType: widget.FallbackContentType,
|
||||||
Parameters: widget.Parameters,
|
Parameters: widget.Parameters,
|
||||||
AllowHtml: widget.AllowHtml,
|
AllowHtml: widget.AllowHtml,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user