mirror of https://github.com/perkeep/perkeep.git
client, search, fs: cammount now getting search queries back
Change-Id: I68541e9f9d54fa4240872d440972ad39f6bad33f
This commit is contained in:
parent
a068e4d7aa
commit
e867ea7dc0
|
@ -34,6 +34,7 @@ import (
|
|||
"camlistore.org/pkg/auth"
|
||||
"camlistore.org/pkg/blobref"
|
||||
"camlistore.org/pkg/schema"
|
||||
"camlistore.org/pkg/search"
|
||||
)
|
||||
|
||||
// A Client provides access to a Camlistore server.
|
||||
|
@ -258,6 +259,31 @@ func (c *Client) SyncHandlers() ([]*SyncInfo, error) {
|
|||
return c.syncHandlers, nil
|
||||
}
|
||||
|
||||
var _ search.IGetRecentPermanodes = (*Client)(nil)
|
||||
|
||||
// SearchRecent implements search.IGetRecentPermanodes against a remote server over HTTP.
|
||||
func (c *Client) GetRecentPermanodes(req *search.RecentRequest) (*search.RecentResponse, error) {
|
||||
sr, err := c.SearchRoot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := sr + req.URLSuffix()
|
||||
hreq := c.newRequest("GET", url)
|
||||
hres, err := c.doReqGated(hreq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer hres.Body.Close()
|
||||
res := new(search.RecentResponse)
|
||||
if err := json.NewDecoder(hres.Body).Decode(res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := res.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// SearchExistingFileSchema does a search query looking for an
|
||||
// existing file with entire contents of wholeRef, then does a HEAD
|
||||
// request to verify the file still exists on the server. If so,
|
||||
|
|
|
@ -21,8 +21,10 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"log"
|
||||
"encoding/json"
|
||||
|
||||
//"camlistore.org/pkg/blobref"
|
||||
"camlistore.org/pkg/search"
|
||||
|
||||
"camlistore.org/third_party/code.google.com/p/rsc/fuse"
|
||||
)
|
||||
|
@ -43,6 +45,19 @@ func (n *recentDir) Attr() fuse.Attr {
|
|||
}
|
||||
|
||||
func (n *recentDir) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
|
||||
req := &search.RecentRequest{N: 100}
|
||||
res, err := n.fs.client.GetRecentPermanodes(req)
|
||||
if err != nil {
|
||||
log.Printf("fs.recent: GetRecentPermanodes error in ReadDir: %v", err)
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
v, err := json.MarshalIndent(res, " ", " ")
|
||||
if err != nil {
|
||||
log.Printf("json error: %v", err)
|
||||
} else {
|
||||
log.Printf("Got: %s", v)
|
||||
}
|
||||
|
||||
var ents []fuse.Dirent
|
||||
ents = append(ents, fuse.Dirent{Name: fmt.Sprintf("TODO-%d", rand.Intn(100))})
|
||||
// TODO: ...
|
||||
|
|
|
@ -18,6 +18,7 @@ package search
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -163,6 +164,11 @@ type RecentRequest struct {
|
|||
ThumbnailSize int // if zero, no thumbnails
|
||||
}
|
||||
|
||||
func (r *RecentRequest) URLSuffix() string {
|
||||
// TODO: Before
|
||||
return fmt.Sprintf("camli/search/recent?n=%d&thumbnails=%d", r.n(), r.thumbnailSize())
|
||||
}
|
||||
|
||||
func (r *RecentRequest) FromHTTP(req *http.Request) error {
|
||||
r.N, _ = strconv.Atoi(req.FormValue("n"))
|
||||
r.ThumbnailSize = thumbnailSize(req)
|
||||
|
@ -200,6 +206,19 @@ func (m MetaMap) Get(br *blobref.BlobRef) *DescribedBlob {
|
|||
type RecentResponse struct {
|
||||
Recent []*RecentItem `json:"recent"`
|
||||
Meta MetaMap `json:"meta"`
|
||||
|
||||
Error string `json:"error,omitempty"`
|
||||
ErrorType string `json:"errorType,omitempty"`
|
||||
}
|
||||
|
||||
func (r *RecentResponse) Err() error {
|
||||
if r.Error != "" || r.ErrorType != "" {
|
||||
if r.ErrorType != "" {
|
||||
return fmt.Errorf("%s: %s", r.ErrorType, r.Error)
|
||||
}
|
||||
return errors.New(r.Error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// A RecentItem is an item returned from $searchRoot/camli/search/recent in the "recent" list.
|
||||
|
|
Loading…
Reference in New Issue