MCPcopy Create free account
hub / github.com/perkeep/perkeep / uiFromConfig

Function uiFromConfig

pkg/server/ui.go:136–248  ·  view source on GitHub ↗
(ld blobserver.Loader, conf jsonconfig.Obj)

Source from the content-addressed store, hash-verified

134}
135
136func uiFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, err error) {
137 ui := &UIHandler{
138 prefix: ld.MyPrefix(),
139 sourceRoot: conf.OptionalString("sourceRoot", ""),
140 resizeSem: syncutil.NewSem(int64(conf.OptionalInt("maxResizeBytes",
141 constants.DefaultMaxResizeMem))),
142
143 serverFiles: Files,
144 uiFiles: uistatic.Files,
145 lessStaticFiles: lessstatic.Files,
146 reactStaticFiles: reactstatic.Files,
147 leafletStaticFiles: leafletstatic.Files,
148 keepyStaticFiles: keepystatic.Files,
149 fontawesomeStaticFiles: fontawesomestatic.Files,
150 opensansStaticFiles: opensansstatic.Files,
151 }
152 cachePrefix := conf.OptionalString("cache", "")
153 scaledImageConf := conf.OptionalObject("scaledImage")
154 if err = conf.Validate(); err != nil {
155 return
156 }
157
158 scaledImageKV, err := newKVOrNil(scaledImageConf)
159 if err != nil {
160 return nil, fmt.Errorf("in UI handler's scaledImage: %v", err)
161 }
162 if scaledImageKV != nil && cachePrefix == "" {
163 return nil, fmt.Errorf("in UI handler, can't specify scaledImage without cache")
164 }
165 if cachePrefix != "" {
166 bs, err := ld.GetStorage(cachePrefix)
167 if err != nil {
168 return nil, fmt.Errorf("UI handler's cache of %q error: %v", cachePrefix, err)
169 }
170 ui.Cache = bs
171 ui.thumbMeta = NewThumbMeta(scaledImageKV)
172 }
173
174 if ui.sourceRoot == "" {
175 ui.sourceRoot = os.Getenv("CAMLI_DEV_CAMLI_ROOT")
176 if ui.sourceRoot == "" {
177 files, err := uistatic.Files.ReadDir(".")
178 if err != nil {
179 return nil, fmt.Errorf("Could not read static files: %v", err)
180 }
181 if len(files) == 0 {
182 ui.sourceRoot, err = osutil.PkSourceRoot()
183 if err != nil {
184 log.Printf("Warning: server not compiled with linked-in UI resources (HTML, JS, CSS), and source root folder not found: %v", err)
185 } else {
186 log.Printf("Using UI resources (HTML, JS, CSS) from disk, under %v", ui.sourceRoot)
187 }
188 }
189 }
190 }
191 if ui.sourceRoot != "" {
192 ui.uiDir = filepath.Join(ui.sourceRoot, filepath.FromSlash("server/perkeepd/ui"))
193 // Ignore any fileembed files:

Callers

nothing calls this directly

Calls 12

makeClosureHandlerMethod · 0.95
PkSourceRootFunction · 0.92
newKVOrNilFunction · 0.85
NewThumbMetaFunction · 0.85
makeFileServerFunction · 0.85
PrintfMethod · 0.80
registerUIHandlerMethod · 0.80
MyPrefixMethod · 0.65
GetStorageMethod · 0.65
FindHandlerByTypeMethod · 0.65
GetHandlerMethod · 0.65
ReadDirMethod · 0.45

Tested by

no test coverage detected