Skip to content

Commit

Permalink
Added /app/notify endpoint for logging/tracking apps
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Jul 6, 2023
1 parent e57f98e commit 691bfb5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions changelog/unreleased/app-notif.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: added an /app/notify endpoint for logging/tracking apps

The new endpoint serves to probe the health state of apps such as
Microsoft Office Online, and it is expected to be called by the frontend
upon successful loading of the document by the underlying app

https://github.com/cs3org/reva/pull/4044
37 changes: 37 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/internal/http/services/datagateway"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/rhttp"
Expand Down Expand Up @@ -91,6 +92,7 @@ func (s *svc) routerInit() error {
s.router.Get("/list", s.handleList)
s.router.Post("/new", s.handleNew)
s.router.Post("/open", s.handleOpen)
s.router.Post("/notify", s.handleNotify)
return nil
}

Expand Down Expand Up @@ -419,6 +421,9 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
return
}

log := appctx.GetLogger(ctx)
log.Info().Str("url", openRes.AppUrl.AppUrl).Interface("resource", fileRef).Msg("returning app URL for file")

w.Header().Set("Content-Type", "application/json")
if _, err = w.Write(js); err != nil {
writeError(w, r, appErrorServerError, "Internal error with JSON payload",
Expand All @@ -427,6 +432,38 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
}
}

func (s *svc) handleNotify(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
writeError(w, r, appErrorInvalidParameter, "parameters could not be parsed", nil)
}

fileID := r.Form.Get("file_id")
var fileRef provider.Reference
if fileID == "" {
path := r.Form.Get("path")
if path == "" {
writeError(w, r, appErrorInvalidParameter, "missing file ID or path", nil)
return
}
fileRef.Path = path
} else {
resourceID := resourceid.OwnCloudResourceIDUnwrap(fileID)
if resourceID == nil {
writeError(w, r, appErrorInvalidParameter, "invalid file ID", nil)
return
}
fileRef.ResourceId = resourceID
}

// log the fileid for later correlation / monitoring
ctx := r.Context()
log := appctx.GetLogger(ctx)
log.Info().Interface("resource", fileRef).Msg("file successfully opened in app")

w.WriteHeader(http.StatusOK)
}

func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent string) []*appregistry.MimeTypeInfo {
ua := ua.Parse(userAgent)
res := []*appregistry.MimeTypeInfo{}
Expand Down
1 change: 0 additions & 1 deletion pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
}
}

log.Info().Str("url", appFullURL).Str("resource", resource.Path).Msg("wopi: returning URL for file")
return &appprovider.OpenInAppURL{
AppUrl: appFullURL,
Method: method,
Expand Down

0 comments on commit 691bfb5

Please sign in to comment.