mirror of
https://github.com/cnrancher/kube-explorer.git
synced 2025-04-28 11:14:44 +00:00
- Support embed api-ui resources - The ui-path arg will be applied if provided. Also applied to api-ui resource files
56 lines
1000 B
Go
56 lines
1000 B
Go
package ui
|
|
|
|
import "github.com/rancher/apiserver/pkg/writer"
|
|
|
|
type APIUI struct {
|
|
offline StringSetting
|
|
release BoolSetting
|
|
embed bool
|
|
}
|
|
|
|
func apiUI(opt *Options) APIUI {
|
|
var rtn = APIUI{
|
|
offline: opt.Offline,
|
|
release: opt.ReleaseSetting,
|
|
embed: true,
|
|
}
|
|
if rtn.offline == nil {
|
|
rtn.offline = StaticSetting("dynamic")
|
|
}
|
|
if rtn.release == nil {
|
|
rtn.release = StaticSetting(false)
|
|
}
|
|
for _, file := range []string{
|
|
"ui/api-ui/ui.min.css",
|
|
"ui/api-ui/ui.min.js",
|
|
} {
|
|
if _, err := staticContent.Open(file); err != nil {
|
|
rtn.embed = false
|
|
break
|
|
}
|
|
}
|
|
return rtn
|
|
}
|
|
|
|
func (a APIUI) content(name string) writer.StringGetter {
|
|
return func() (rtn string) {
|
|
switch a.offline() {
|
|
case "dynamic":
|
|
if !a.release() && !a.embed {
|
|
return ""
|
|
}
|
|
case "false":
|
|
return ""
|
|
}
|
|
return name
|
|
}
|
|
}
|
|
|
|
func (a APIUI) CSS() writer.StringGetter {
|
|
return a.content("/api-ui/ui.min.css")
|
|
}
|
|
|
|
func (a APIUI) JS() writer.StringGetter {
|
|
return a.content("/api-ui/ui.min.js")
|
|
}
|