2023-01-01 04:40:45 +00:00
|
|
|
//go:build js
|
2019-04-30 15:35:15 +00:00
|
|
|
|
2016-08-29 19:37:35 +00:00
|
|
|
//go:generate go run gensearchtypes.go -out zsearch.go
|
2016-07-15 00:10:07 +00:00
|
|
|
|
2016-05-12 22:14:54 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2016 The Perkeep Authors.
|
2016-05-12 22:14:54 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This package contains source code for gopherjs, to generate javascript code
|
|
|
|
// that is included in the publisher web UI.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-13 17:03:13 +00:00
|
|
|
"fmt"
|
2017-04-24 09:33:08 +00:00
|
|
|
"strings"
|
2016-07-13 17:03:13 +00:00
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
2016-07-13 17:03:13 +00:00
|
|
|
|
2016-05-12 22:14:54 +00:00
|
|
|
"github.com/gopherjs/gopherjs/js"
|
|
|
|
"github.com/gopherjs/jquery"
|
|
|
|
)
|
|
|
|
|
2016-07-18 18:12:35 +00:00
|
|
|
var jQuery = jquery.NewJQuery
|
2016-05-12 22:14:54 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
//show jQuery Version on console:
|
|
|
|
print("Your current jQuery version is: " + jQuery().Jquery)
|
|
|
|
|
2016-07-13 17:03:13 +00:00
|
|
|
js.Global.Set("RenderMembers", RenderMembers)
|
2016-07-18 18:12:35 +00:00
|
|
|
js.Global.Set("RenderFile", StartRenderFile)
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func host() (string, error) {
|
2016-07-18 18:12:35 +00:00
|
|
|
h := js.Global.Get("host")
|
|
|
|
if undefOrEmptyString(h) {
|
2016-07-13 17:03:13 +00:00
|
|
|
return "", fmt.Errorf("No Host in header")
|
|
|
|
}
|
2016-07-18 18:12:35 +00:00
|
|
|
return h.String(), nil
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func scheme() (string, error) {
|
2017-04-24 09:33:08 +00:00
|
|
|
// We can't rely on the publisher's server-side to set the scheme as a var,
|
|
|
|
// because it could be behind a proxy, serving for a scheme different
|
|
|
|
// from the one we're seeing from the outside.
|
|
|
|
// Ask the browser instead what scheme/protocol the current page was accessed with.
|
|
|
|
proto := js.Global.Get("location").Get("protocol")
|
|
|
|
if undefOrEmptyString(proto) {
|
|
|
|
return "", fmt.Errorf("window.location.protocol missing or invalid")
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
2017-04-24 09:33:08 +00:00
|
|
|
return strings.TrimRight(proto.String(), ":"), nil
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func subjectBasePath() (string, error) {
|
2016-07-18 18:12:35 +00:00
|
|
|
basePath := js.Global.Get("subjectBasePath")
|
|
|
|
if undefOrEmptyString(basePath) {
|
2016-07-13 17:03:13 +00:00
|
|
|
return "", fmt.Errorf("No SubjectBasePath in header")
|
|
|
|
}
|
2016-07-18 18:12:35 +00:00
|
|
|
return basePath.String(), nil
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func subject() (blob.Ref, error) {
|
2016-07-18 18:12:35 +00:00
|
|
|
o := js.Global.Get("subject")
|
|
|
|
if undefOrEmptyString(o) {
|
2016-07-13 17:03:13 +00:00
|
|
|
return blob.Ref{}, fmt.Errorf("No Subject in header")
|
|
|
|
}
|
2016-07-18 18:12:35 +00:00
|
|
|
sbj := o.String()
|
2016-07-13 17:03:13 +00:00
|
|
|
br, ok := blob.Parse(sbj)
|
|
|
|
if !ok {
|
|
|
|
return blob.Ref{}, fmt.Errorf("invalid blobref %q", sbj)
|
|
|
|
}
|
|
|
|
return br, nil
|
|
|
|
}
|
|
|
|
|
2016-07-18 18:12:35 +00:00
|
|
|
func publishedRoot() (blob.Ref, error) {
|
|
|
|
o := js.Global.Get("publishedRoot")
|
|
|
|
if undefOrEmptyString(o) {
|
|
|
|
return blob.Ref{}, fmt.Errorf("No PublishedRoot in header")
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
2016-07-18 18:12:35 +00:00
|
|
|
root := o.String()
|
|
|
|
br, ok := blob.Parse(root)
|
|
|
|
if !ok {
|
|
|
|
return blob.Ref{}, fmt.Errorf("invalid blobref %q", root)
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
2016-07-18 18:12:35 +00:00
|
|
|
return br, nil
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-18 18:12:35 +00:00
|
|
|
func pathPrefix() (string, error) {
|
|
|
|
prefix := js.Global.Get("pathPrefix")
|
|
|
|
if undefOrEmptyString(prefix) {
|
|
|
|
return "", fmt.Errorf("No PathPrefix in header")
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
2016-07-18 18:12:35 +00:00
|
|
|
return prefix.String(), nil
|
2016-07-13 17:03:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-18 18:12:35 +00:00
|
|
|
func undefOrEmptyString(o *js.Object) bool {
|
|
|
|
return o == js.Undefined || o.String() == ""
|
2016-05-12 22:14:54 +00:00
|
|
|
}
|