mirror of
https://github.com/Dvorinka/Dash.git
synced 2026-10-28 07:41:27 +00:00
Backend: internal/widget registry (type metadata + Fetcher), Pi-hole v5 / AdGuard / Immich fetchers, /api/widgets/types + /api/widgets/:id/data with 30s TTL cache (failures cached too), kind+config on item create/patch. Config secrets are never logged or echoed in errors. Frontend: WidgetContent host maps config.type to a component, polls /data every 30s for server-backed types; clock renders client-side. Generic WidgetDialog builds its form from the registry's field list. Widget tiles are sortable items in both renderers. Generated with [Devin](https://devin.ai) Authored By: TDvorak <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package widget
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Immich REST API: GET /api/statistics with an x-api-key header.
|
|
type immich struct{}
|
|
|
|
func init() { register(immich{}) }
|
|
|
|
func (immich) Meta() Type {
|
|
return Type{
|
|
Type: "immich",
|
|
Name: "Immich",
|
|
Description: "Library size and photo count",
|
|
Fields: []Field{
|
|
{Key: "endpoint", Label: "Endpoint", Placeholder: "http://immich.local:2283", Required: true},
|
|
{Key: "apiKey", Label: "API key", Secret: true, Required: true},
|
|
},
|
|
}
|
|
}
|
|
|
|
type immichData struct {
|
|
Photos int `json:"photos"`
|
|
Videos int `json:"videos"`
|
|
UsageB int64 `json:"usageBytes"`
|
|
}
|
|
|
|
func (immich) Fetch(ctx context.Context, cfg json.RawMessage) (any, error) {
|
|
endpoint := strings.TrimRight(cfgStr(cfg, "endpoint"), "/")
|
|
key := cfgStr(cfg, "apiKey")
|
|
if endpoint == "" || key == "" {
|
|
return nil, fmt.Errorf("endpoint and apiKey required")
|
|
}
|
|
var raw struct {
|
|
Images int `json:"images"`
|
|
Videos int `json:"videos"`
|
|
Usage int64 `json:"usage"`
|
|
}
|
|
if err := getJSON(ctx, endpoint+"/api/statistics",
|
|
map[string]string{"x-api-key": key}, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
return immichData{
|
|
Photos: raw.Images,
|
|
Videos: raw.Videos,
|
|
UsageB: raw.Usage,
|
|
}, nil
|
|
}
|