Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Update stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Nov 8, 2022
1 parent feaaf7e commit fc9a280
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 58 deletions.
138 changes: 80 additions & 58 deletions internal/http/services/owncloud/ocdav/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package ocdav
import (
"encoding/xml"
"io"
"io/ioutil"
"net/http"
"strings"

Expand All @@ -29,8 +30,6 @@ import (
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"

"github.com/blevesearch/bleve/v2"
)

const (
Expand All @@ -43,26 +42,6 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
log := appctx.GetLogger(ctx)
log.Info().Msgf("hugo: searching in path: %s", r.URL.Path)

index, err := bleve.Open("/var/tmp/search.db")
if err != nil {
log.Error().Err(err).Msg("hugo: error opening bleve db")
w.WriteHeader(http.StatusInternalServerError)
return
}

query := bleve.NewQueryStringQuery("mydoc")
req := bleve.NewSearchRequest(query)
res, err := index.Search(req)
if err != nil {
log.Error().Err(err).Msg("hugo: error searching")
w.WriteHeader(http.StatusInternalServerError)
return
}

log.Info().Msgf("hugo: bleve result: %+v", res)

// fn := path.Join(ns, r.URL.Path)

rep, status, err := readReport(r.Body)
if err != nil {
log.Error().Err(err).Msg("error reading report")
Expand All @@ -87,13 +66,74 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSearchFiles) {
ctx := r.Context()
log := appctx.GetLogger(ctx)
_, err := s.getClient()
if err != nil {
log.Error().Err(err).Msg("error getting grpc client")
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNotImplemented)

log.Info().Msgf("hugo: search is: %+v", sf)

/*
_, err := bleve.Open("/var/tmp/search.db")
if err != nil {
log.Error().Err(err).Msg("hugo: error opening bleve db")
w.WriteHeader(http.StatusInternalServerError)
return
}
query := bleve.NewWildcardQuery(sf.Search.Pattern)
req := bleve.NewSearchRequest(query)
res, err := index.Search(req)
if err != nil {
log.Error().Err(err).Msg("hugo: error searching")
w.WriteHeader(http.StatusInternalServerError)
return
}
*/

//log.Info().Msgf("hugo: bleve result: %+v", res)
data := `
<?xml version="1.0" encoding="UTF-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
<d:response>
<d:href>/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asd.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!d5613880-307c-4e3e-b56d-97839fcf6d03</oc:fileid>
<oc:file-parent>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51</oc:file-parent>
<oc:name>asd.txt</oc:name>
<d:getlastmodified>2022-11-08T10:45:16Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>RDNVW</oc:permissions>
<d:getetag />
<d:resourcetype />
<d:getcontentlength>0</d:getcontentlength>
<oc:score>0.4809828996658325</oc:score>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asdddddd</d:href>
<d:propstat>
<d:prop>
<oc:fileid>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!fa3c7a85-5fc4-46d3-a0b1-293a282da1b7</oc:fileid>
<oc:file-parent>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51</oc:file-parent>
<oc:name>asdddddd</oc:name>
<d:getlastmodified>2022-11-08T10:45:32Z</d:getlastmodified>
<d:getcontenttype>httpd/unix-directory</d:getcontenttype>
<oc:permissions>RDNVCK</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
<oc:score>0.4809828996658325</oc:score>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>
`
w.Write([]byte(data))
w.WriteHeader(207)
return
}

func (s *svc) doFilterFiles(w http.ResponseWriter, r *http.Request, ff *reportFilterFiles, namespace string) {
Expand Down Expand Up @@ -171,7 +211,7 @@ type reportSearchFiles struct {
Search reportSearchFilesSearch `xml:"search"`
}
type reportSearchFilesSearch struct {
Pattern string `xml:"search"`
Pattern string `xml:"pattern"`
Limit int `xml:"limit"`
Offset int `xml:"offset"`
}
Expand All @@ -189,34 +229,16 @@ type reportFilterFilesRules struct {
}

func readReport(r io.Reader) (rep *report, status int, err error) {
decoder := xml.NewDecoder(r)
rep = &report{}
for {
t, err := decoder.Token()
if err == io.EOF {
// io.EOF is a successful end
return rep, 0, nil
}
if err != nil {
return nil, http.StatusBadRequest, err
}
content, err := ioutil.ReadAll(r)
if err != nil {
return nil, 0, err
}

if v, ok := t.(xml.StartElement); ok {
if v.Name.Local == elementNameSearchFiles {
var repSF reportSearchFiles
err = decoder.DecodeElement(&repSF, &v)
if err != nil {
return nil, http.StatusBadRequest, err
}
rep.SearchFiles = &repSF
} else if v.Name.Local == elementNameFilterFiles {
var repFF reportFilterFiles
err = decoder.DecodeElement(&repFF, &v)
if err != nil {
return nil, http.StatusBadRequest, err
}
rep.FilterFiles = &repFF
}
}
s := &reportSearchFiles{Search: reportSearchFilesSearch{}}
err = xml.Unmarshal(content, s)
if err != nil {
return nil, 0, err
}

return &report{SearchFiles: s}, 0, err
}
11 changes: 11 additions & 0 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,17 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, path st
return c.parseFind(ctx, auth, path, stdout)
}

// List the contents of the directory given by path infinity
// Use with care
func (c *Client) ListInfinity(ctx context.Context, auth eosclient.Authorization, path string) ([]*eosclient.FileInfo, error) {
args := []string{"find", "--fileinfo", path}
stdout, _, err := c.executeEOS(ctx, args, auth)
if err != nil {
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
}
return c.parseFind(ctx, auth, path, stdout)
}

// Read reads a file from the mgm
func (c *Client) Read(ctx context.Context, auth eosclient.Authorization, path string) (io.ReadCloser, error) {
rand := "eosread-" + uuid.New().String()
Expand Down

0 comments on commit fc9a280

Please sign in to comment.