ui: generate query tokens URL, remove JS
This commit is contained in:
parent
fc36ee6064
commit
d031b5ff3b
@ -1,6 +1,8 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -10,6 +12,7 @@ type baseResponse struct {
|
|||||||
Context *gin.Context
|
Context *gin.Context
|
||||||
Login string
|
Login string
|
||||||
Authorized bool
|
Authorized bool
|
||||||
|
BaseURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (br baseResponse) Rel(path string, tail ...string) string {
|
func (br baseResponse) Rel(path string, tail ...string) string {
|
||||||
@ -30,5 +33,21 @@ func base(gctx *gin.Context) baseResponse {
|
|||||||
Authorized: gctx.GetBool(ctxAuthorized),
|
Authorized: gctx.GetBool(ctxAuthorized),
|
||||||
Context: gctx,
|
Context: gctx,
|
||||||
Login: gctx.GetString(ctxLogin),
|
Login: gctx.GetString(ctxLogin),
|
||||||
|
BaseURL: getProto(gctx.Request) + "://" + gctx.Request.Host,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getProto(req *http.Request) string {
|
||||||
|
return extractScheme(req.Header.Get("Origin"), extractScheme(req.Header.Get("Referer"), "https"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractScheme(guess, fallback string) string {
|
||||||
|
if guess == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
u, err := url.Parse(guess)
|
||||||
|
if err != nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return u.Scheme
|
||||||
|
}
|
||||||
|
@ -57,8 +57,7 @@
|
|||||||
<dt class="col-sm-3">API endpoint</dt>
|
<dt class="col-sm-3">API endpoint</dt>
|
||||||
<dd class="col-sm-9">
|
<dd class="col-sm-9">
|
||||||
<code>
|
<code>
|
||||||
<noscript>JS required to detect API url</noscript>
|
{{$.BaseURL}}/api/{{.Unit.Name}}/
|
||||||
<script>document.write((new URL("../../../api/{{.Unit.Name}}/", window.location).href))</script>
|
|
||||||
</code>
|
</code>
|
||||||
</dd>
|
</dd>
|
||||||
{{- end}}
|
{{- end}}
|
||||||
@ -154,9 +153,22 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{if .QueryToken.Enable}}
|
{{if .QueryToken.Enable}}
|
||||||
<dt class="col-sm-3">Query token</dt>
|
<dt class="col-sm-3">Query token</dt>
|
||||||
<dd class="col-sm-9">in
|
<dd class="col-sm-9">
|
||||||
<code>{{.QueryToken.GetParam}}</code>
|
<details>
|
||||||
param
|
<summary>
|
||||||
|
in
|
||||||
|
<code>{{.QueryToken.GetParam}}</code>
|
||||||
|
param
|
||||||
|
</summary>
|
||||||
|
<ul>
|
||||||
|
{{range .QueryToken.Tokens}}
|
||||||
|
<li>
|
||||||
|
<code>{{$.BaseURL}}/api/{{$.Unit.Name}}/?{{$.Unit.Authorization.QueryToken.GetParam}}={{.}}</code>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .HeaderToken.Enable}}
|
{{if .HeaderToken.Enable}}
|
||||||
|
Loading…
Reference in New Issue
Block a user