Skip to content

Commit 078a850

Browse files
authored
Update custom viewer handling in UI configuration to eliminate dependency on generated code (#9637)
* Update custom viewer handling in UI configuration to eliminate dependency on generated code. * add missing file * Fix file format
1 parent a88f49b commit 078a850

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

pkg/api/controller.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5544,8 +5544,32 @@ func (c *Controller) getUIConfig() *apigen.UIConfig {
55445544
}
55455545

55465546
customViewers := uiConfig.GetCustomViewers()
5547+
if len(customViewers) == 0 {
5548+
return &apigen.UIConfig{
5549+
CustomViewers: nil,
5550+
}
5551+
}
5552+
5553+
apigenViewers := make([]apigen.CustomViewer, len(customViewers))
5554+
for i, cv := range customViewers {
5555+
var extensions *[]string
5556+
if len(cv.Extensions) > 0 {
5557+
extensions = &cv.Extensions
5558+
}
5559+
var contentTypes *[]string
5560+
if len(cv.ContentTypes) > 0 {
5561+
contentTypes = &cv.ContentTypes
5562+
}
5563+
apigenViewers[i] = apigen.CustomViewer{
5564+
Name: cv.Name,
5565+
Url: cv.URL,
5566+
Extensions: extensions,
5567+
ContentTypes: contentTypes,
5568+
}
5569+
}
5570+
55475571
return &apigen.UIConfig{
5548-
CustomViewers: &customViewers,
5572+
CustomViewers: &apigenViewers,
55495573
}
55505574
}
55515575

pkg/api/params/customviewer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package params
2+
3+
// CustomViewer defines a custom viewer configuration
4+
type CustomViewer struct {
5+
Name string
6+
URL string
7+
Extensions []string
8+
ContentTypes []string
9+
}

pkg/config/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/go-viper/mapstructure/v2"
1313
"github.com/mitchellh/go-homedir"
1414
"github.com/spf13/viper"
15-
"github.com/treeverse/lakefs/pkg/api/apigen"
1615
apiparams "github.com/treeverse/lakefs/pkg/api/params"
1716
blockparams "github.com/treeverse/lakefs/pkg/block/params"
1817
"github.com/treeverse/lakefs/pkg/logging"
@@ -447,7 +446,7 @@ type AuthConfig interface {
447446
type UIConfig interface {
448447
IsUIEnabled() bool
449448
GetSnippets() []apiparams.CodeSnippet
450-
GetCustomViewers() []apigen.CustomViewer
449+
GetCustomViewers() []apiparams.CustomViewer
451450
}
452451

453452
// BaseConfig - Output struct of configuration, used to validate. If you read a key using a viper accessor
@@ -834,6 +833,6 @@ func BuildCodeSnippets(s []UISnippet) []apiparams.CodeSnippet {
834833
return snippets
835834
}
836835

837-
func (u *UI) GetCustomViewers() []apigen.CustomViewer {
836+
func (u *UI) GetCustomViewers() []apiparams.CustomViewer {
838837
return nil
839838
}

0 commit comments

Comments
 (0)