@@ -21,6 +21,7 @@ package ocdav
2121import (
2222 "encoding/xml"
2323 "io"
24+ "io/ioutil"
2425 "net/http"
2526 "strings"
2627
@@ -29,8 +30,6 @@ import (
2930 providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
3031 "github.com/cs3org/reva/pkg/appctx"
3132 ctxpkg "github.com/cs3org/reva/pkg/ctx"
32-
33- "github.com/blevesearch/bleve/v2"
3433)
3534
3635const (
@@ -43,26 +42,6 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
4342 log := appctx .GetLogger (ctx )
4443 log .Info ().Msgf ("hugo: searching in path: %s" , r .URL .Path )
4544
46- index , err := bleve .Open ("/var/tmp/search.db" )
47- if err != nil {
48- log .Error ().Err (err ).Msg ("hugo: error opening bleve db" )
49- w .WriteHeader (http .StatusInternalServerError )
50- return
51- }
52-
53- query := bleve .NewQueryStringQuery ("mydoc" )
54- req := bleve .NewSearchRequest (query )
55- res , err := index .Search (req )
56- if err != nil {
57- log .Error ().Err (err ).Msg ("hugo: error searching" )
58- w .WriteHeader (http .StatusInternalServerError )
59- return
60- }
61-
62- log .Info ().Msgf ("hugo: bleve result: %+v" , res )
63-
64- // fn := path.Join(ns, r.URL.Path)
65-
6645 rep , status , err := readReport (r .Body )
6746 if err != nil {
6847 log .Error ().Err (err ).Msg ("error reading report" )
@@ -87,13 +66,74 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
8766func (s * svc ) doSearchFiles (w http.ResponseWriter , r * http.Request , sf * reportSearchFiles ) {
8867 ctx := r .Context ()
8968 log := appctx .GetLogger (ctx )
90- _ , err := s .getClient ()
91- if err != nil {
92- log .Error ().Err (err ).Msg ("error getting grpc client" )
93- w .WriteHeader (http .StatusInternalServerError )
94- return
95- }
96- w .WriteHeader (http .StatusNotImplemented )
69+
70+ log .Info ().Msgf ("hugo: search is: %+v" , sf )
71+
72+ /*
73+ _, err := bleve.Open("/var/tmp/search.db")
74+ if err != nil {
75+ log.Error().Err(err).Msg("hugo: error opening bleve db")
76+ w.WriteHeader(http.StatusInternalServerError)
77+ return
78+ }
79+
80+ query := bleve.NewWildcardQuery(sf.Search.Pattern)
81+ req := bleve.NewSearchRequest(query)
82+ res, err := index.Search(req)
83+ if err != nil {
84+ log.Error().Err(err).Msg("hugo: error searching")
85+ w.WriteHeader(http.StatusInternalServerError)
86+ return
87+ }
88+ */
89+
90+ //log.Info().Msgf("hugo: bleve result: %+v", res)
91+ data := `
92+ <?xml version="1.0" encoding="UTF-8"?>
93+ <d:multistatus xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
94+ <d:response>
95+ <d:href>/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asd.txt</d:href>
96+ <d:propstat>
97+ <d:prop>
98+ <oc:fileid>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!d5613880-307c-4e3e-b56d-97839fcf6d03</oc:fileid>
99+ <oc:file-parent>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51</oc:file-parent>
100+ <oc:name>asd.txt</oc:name>
101+ <d:getlastmodified>2022-11-08T10:45:16Z</d:getlastmodified>
102+ <d:getcontenttype>text/plain</d:getcontenttype>
103+ <oc:permissions>RDNVW</oc:permissions>
104+ <d:getetag />
105+ <d:resourcetype />
106+ <d:getcontentlength>0</d:getcontentlength>
107+ <oc:score>0.4809828996658325</oc:score>
108+ </d:prop>
109+ <d:status>HTTP/1.1 200 OK</d:status>
110+ </d:propstat>
111+ </d:response>
112+ <d:response>
113+ <d:href>/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asdddddd</d:href>
114+ <d:propstat>
115+ <d:prop>
116+ <oc:fileid>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!fa3c7a85-5fc4-46d3-a0b1-293a282da1b7</oc:fileid>
117+ <oc:file-parent>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51</oc:file-parent>
118+ <oc:name>asdddddd</oc:name>
119+ <d:getlastmodified>2022-11-08T10:45:32Z</d:getlastmodified>
120+ <d:getcontenttype>httpd/unix-directory</d:getcontenttype>
121+ <oc:permissions>RDNVCK</oc:permissions>
122+ <d:getetag />
123+ <d:resourcetype>
124+ <d:collection />
125+ </d:resourcetype>
126+ <oc:size>0</oc:size>
127+ <oc:score>0.4809828996658325</oc:score>
128+ </d:prop>
129+ <d:status>HTTP/1.1 200 OK</d:status>
130+ </d:propstat>
131+ </d:response>
132+ </d:multistatus>
133+ `
134+ w .Write ([]byte (data ))
135+ w .WriteHeader (207 )
136+ return
97137}
98138
99139func (s * svc ) doFilterFiles (w http.ResponseWriter , r * http.Request , ff * reportFilterFiles , namespace string ) {
@@ -171,7 +211,7 @@ type reportSearchFiles struct {
171211 Search reportSearchFilesSearch `xml:"search"`
172212}
173213type reportSearchFilesSearch struct {
174- Pattern string `xml:"search "`
214+ Pattern string `xml:"pattern "`
175215 Limit int `xml:"limit"`
176216 Offset int `xml:"offset"`
177217}
@@ -189,34 +229,16 @@ type reportFilterFilesRules struct {
189229}
190230
191231func readReport (r io.Reader ) (rep * report , status int , err error ) {
192- decoder := xml .NewDecoder (r )
193- rep = & report {}
194- for {
195- t , err := decoder .Token ()
196- if err == io .EOF {
197- // io.EOF is a successful end
198- return rep , 0 , nil
199- }
200- if err != nil {
201- return nil , http .StatusBadRequest , err
202- }
232+ content , err := ioutil .ReadAll (r )
233+ if err != nil {
234+ return nil , 0 , err
235+ }
203236
204- if v , ok := t .(xml.StartElement ); ok {
205- if v .Name .Local == elementNameSearchFiles {
206- var repSF reportSearchFiles
207- err = decoder .DecodeElement (& repSF , & v )
208- if err != nil {
209- return nil , http .StatusBadRequest , err
210- }
211- rep .SearchFiles = & repSF
212- } else if v .Name .Local == elementNameFilterFiles {
213- var repFF reportFilterFiles
214- err = decoder .DecodeElement (& repFF , & v )
215- if err != nil {
216- return nil , http .StatusBadRequest , err
217- }
218- rep .FilterFiles = & repFF
219- }
220- }
237+ s := & reportSearchFiles {Search : reportSearchFilesSearch {}}
238+ err = xml .Unmarshal (content , s )
239+ if err != nil {
240+ return nil , 0 , err
221241 }
242+
243+ return & report {SearchFiles : s }, 0 , err
222244}
0 commit comments