diff --git a/go.mod b/go.mod index 2ab4b0e..41a2b00 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/FAU-CDI/wisski-distillery go 1.18 require ( - github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69 + github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41 github.com/Showmax/go-fqdn v1.0.0 github.com/alessio/shellescape v1.4.1 github.com/feiin/sqlstring v0.3.0 @@ -20,7 +20,7 @@ require ( github.com/tdewolff/minify v2.3.6+incompatible github.com/tkw1536/goprogram v0.2.4 golang.org/x/crypto v0.3.0 - golang.org/x/exp v0.0.0-20221205204356-47842c84f3db + golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 golang.org/x/sync v0.1.0 golang.org/x/term v0.3.0 gorm.io/driver/mysql v1.4.4 diff --git a/go.sum b/go.sum index bb7a398..f56dc35 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69 h1:wjiRzjx8G7Vm/rqHuAv9qMeLNHV3RmO9SNkh8VrvsBQ= -github.com/FAU-CDI/wdresolve v0.0.0-20220911200729-e66b93ed2b69/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q= +github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41 h1:RRN/aPFEOSpQVcq+f0iTBkUt6L/EBPTSH9risO3SDto= +github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41/go.mod h1:9L2AZlOgDtg1WZ9Z1P1nBjqOY/b0mVrVE7UvO20pO2Q= github.com/Showmax/go-fqdn v1.0.0 h1:0rG5IbmVliNT5O19Mfuvna9LL7zlHyRfsSvBPZmF9tM= github.com/Showmax/go-fqdn v1.0.0/go.mod h1:SfrFBzmDCtCGrnHhoDjuvFnKsWjEQX/Q9ARZvOrJAko= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= @@ -68,8 +68,8 @@ github.com/tkw1536/goprogram v0.2.4/go.mod h1:3Ngcwy7jtsZ+pINc+JfLdf8TWbvthdSS2T golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= -golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 h1:fJwx88sMf5RXwDwziL0/Mn9Wqs+efMSo/RYcL+37W9c= +golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= diff --git a/internal/dis/component/resolver/resolver.go b/internal/dis/component/resolver/resolver.go index 879e423..e4cccc7 100644 --- a/internal/dis/component/resolver/resolver.go +++ b/internal/dis/component/resolver/resolver.go @@ -10,15 +10,21 @@ import ( "github.com/FAU-CDI/wdresolve" "github.com/FAU-CDI/wdresolve/resolvers" "github.com/FAU-CDI/wisski-distillery/internal/dis/component" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom" "github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances" + "github.com/FAU-CDI/wisski-distillery/pkg/httpx" "github.com/FAU-CDI/wisski-distillery/pkg/lazy" "github.com/rs/zerolog" + + _ "embed" ) type Resolver struct { component.Base Dependencies struct { Instances *instances.Instances + Custom *custom.Custom } prefixes lazy.Lazy[map[string]string] // cached prefixes (from the server) @@ -39,11 +45,30 @@ func (resolver *Resolver) Routes() component.Routes { } } +//go:embed "resolver.html" +var resolverHTMLStr string +var resolverTemplate = static.AssetsHome.MustParseShared("resolver.html", resolverHTMLStr) + +type resolverContext struct { + custom.BaseContext + wdresolve.IndexContext +} + func (resolver *Resolver) HandleRoute(ctx context.Context, route string) (http.Handler, error) { + resolverTemplate := resolver.Dependencies.Custom.Template(resolverTemplate) + logger := zerolog.Ctx(ctx) var err error return resolver.handler.Get(func() (p wdresolve.ResolveHandler) { + p.HandleIndex = func(context wdresolve.IndexContext, w http.ResponseWriter, r *http.Request) { + ctx := resolverContext{ + IndexContext: context, + } + resolver.Dependencies.Custom.Update(&ctx, r) + + httpx.WriteHTML(ctx, nil, resolverTemplate, "", w, r) + } p.TrustXForwardedProto = true fallback := &resolvers.Regexp{ diff --git a/internal/dis/component/resolver/resolver.html b/internal/dis/component/resolver/resolver.html new file mode 100644 index 0000000..a249617 --- /dev/null +++ b/internal/dis/component/resolver/resolver.html @@ -0,0 +1,71 @@ +{{ template "_base.html" . }} +{{ define "title" }}WissKI Resolver{{ end }} + +{{ define "header"}} + +{{ end }} + +{{ define "content" }} +
+

wdresolve

+

+ This page implements a resolver for the WissKI Distillery. + It takes a RDF / Triplestore URI that refers to a WissKI Entity and redirects to the page that displays the entity. +

+
+
+

Resolve URI

+
+ + + + +

+ You can also resolve a URI by a appending ?uri= to the URL of this page, for example {{ .URL }}?uri=graf://dr.acula/12345. +

+
+
+ +{{ if .Prefixes }} +
+

Known Prefixes

+

+ These are for debugging purposes only. +

+
+
+
+
+ + + + + + + + + {{ range $unused, $prefix := .Prefixes }} + + + + + {{ end }} + +
+ Prefix + + WissKI +
+ + {{ (index $prefix 0) }} + + + + {{ (index $prefix 1) }} + +
+
+
+
+{{ end }} +{{ end }} \ No newline at end of file