feat: add support bundle notice to viewer
This commit is contained in:
@@ -62,7 +62,7 @@ func newHandler(opts HandlerOptions) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
page, err := buildPageData([]byte(payload), title)
|
||||
page, err := buildPageData([]byte(payload), title, RenderOptions{})
|
||||
if err != nil {
|
||||
if opts.Standalone {
|
||||
html, renderErr := web.RenderUpload(pageData{
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package viewer
|
||||
|
||||
type pageData struct {
|
||||
Title string
|
||||
HasSnapshot bool
|
||||
Error string
|
||||
Meta []fieldRow
|
||||
Sections []sectionView
|
||||
Title string
|
||||
HasSnapshot bool
|
||||
Error string
|
||||
NoticeTitle string
|
||||
NoticeBody string
|
||||
DownloadArchiveURL string
|
||||
DownloadArchiveLabel string
|
||||
Meta []fieldRow
|
||||
Sections []sectionView
|
||||
}
|
||||
|
||||
type sectionView struct {
|
||||
|
||||
@@ -81,16 +81,33 @@ var preferredColumns = map[string][]string{
|
||||
"other": {"name", "value", "unit"},
|
||||
}
|
||||
|
||||
type RenderOptions struct {
|
||||
DownloadArchiveURL string
|
||||
DownloadArchiveLabel string
|
||||
NoticeTitle string
|
||||
NoticeBody string
|
||||
}
|
||||
|
||||
func RenderHTML(snapshot []byte, title string) ([]byte, error) {
|
||||
page, err := buildPageData(snapshot, title)
|
||||
return RenderHTMLWithOptions(snapshot, title, RenderOptions{})
|
||||
}
|
||||
|
||||
func RenderHTMLWithOptions(snapshot []byte, title string, opts RenderOptions) ([]byte, error) {
|
||||
page, err := buildPageData(snapshot, title, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return web.Render(page)
|
||||
}
|
||||
|
||||
func buildPageData(snapshot []byte, title string) (pageData, error) {
|
||||
page := pageData{Title: title}
|
||||
func buildPageData(snapshot []byte, title string, opts RenderOptions) (pageData, error) {
|
||||
page := pageData{
|
||||
Title: title,
|
||||
NoticeTitle: strings.TrimSpace(opts.NoticeTitle),
|
||||
NoticeBody: strings.TrimSpace(opts.NoticeBody),
|
||||
DownloadArchiveURL: strings.TrimSpace(opts.DownloadArchiveURL),
|
||||
DownloadArchiveLabel: strings.TrimSpace(opts.DownloadArchiveLabel),
|
||||
}
|
||||
if strings.TrimSpace(string(snapshot)) == "" {
|
||||
return page, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user