Skip to content

Commit

Permalink
root viewer iframe service
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohitty committed Aug 16, 2019
1 parent 092ee0a commit 4c161d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
2 changes: 0 additions & 2 deletions cmd/revad/svcs/httpsvcs/datasvc/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import (
func (s *svc) doGet(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := appctx.GetLogger(ctx)

files, ok := r.URL.Query()["filename"]

if !ok || len(files[0]) < 1 {
w.WriteHeader(http.StatusBadRequest)
return
Expand Down
49 changes: 22 additions & 27 deletions cmd/revad/svcs/httpsvcs/iframeuisvc/iframeuisvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ package iframeuisvc

import (
"net/http"
"strings"

"github.com/cs3org/reva/cmd/revad/httpserver"
"github.com/cs3org/reva/cmd/revad/svcs/httpsvcs"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/user"
"github.com/mitchellh/mapstructure"
)

Expand Down Expand Up @@ -74,32 +76,25 @@ func getHandler() http.Handler {
}

func doOpen(w http.ResponseWriter, r *http.Request) {
log := appctx.GetLogger(r.Context())
filename := r.URL.Path
html := `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://root.cern/js/latest/scripts/JSRootCore.min.js" type="text/javascript"></script>
<script type="text/javascript">
var filename = "http://localhost:9998/data` + filename + `";
JSROOT.OpenFile(filename, function(file) {
file.ReadObject("c1;1", function(obj) {
JSROOT.draw("drawing", obj, "colz");
});
});
</script>
</head>
<body>
<div id="drawing" style="width:800px; height:600px"></div>
</body>
</html>
`
if _, err := w.Write([]byte(html)); err != nil {
log.Err(err).Msg("error writing response")
ctx := r.Context()
log := appctx.GetLogger(ctx)

u, ok := user.ContextGetUser(ctx)
if !ok {
log.Error().Msg("error getting user from context")
w.WriteHeader(http.StatusInternalServerError)
return
}

filename := strings.TrimPrefix(r.URL.Path, "/")

tokens := r.URL.Query()["access_token"]
token := tokens[0]

responseString := `https://root.cern/js/latest/?file=http://localhost:9998/data?filename=/` + u.Username + `/` + filename + `&access_token=` + token
_, err := w.Write([]byte(responseString))
if err != nil {
log.Error().Err(err).Msg("can't write to response")
w.WriteHeader(http.StatusInternalServerError)
}
}

0 comments on commit 4c161d6

Please sign in to comment.