コード例 #1
0
ファイル: resolv.go プロジェクト: sigmonsays/voyager
func (l *layoutResolver) Resolve(voy *voy.VoyFile, localpath string, files []*types.File) (filetype.FileType, error) {
	var customLayout string
	ltmp := strings.Split(localpath, "/")
Layout:
	for i := len(ltmp); i > 1; i-- {
		p := strings.Join(ltmp[:i], "/")
		log.Tracef("check custom layout %s", p)
		l, found := voy.Layouts[p]
		if found {
			log.Tracef("found custom layout %s for %s", l, p)
			customLayout = l
			break Layout
		}
	}

	var layout filetype.FileType

	if customLayout == "" {
		layout = filetype.GuessLayout(localpath, files)
	} else {
		layout = filetype.TypeFromString(customLayout)
		log.Debugf("using custom layout %s (%q) for %s", layout, customLayout, localpath)
	}

	return layout, nil
}
コード例 #2
0
ファイル: server.go プロジェクト: sigmonsays/voyager
func (s *Server) RemoteRequest(w http.ResponseWriter, r *http.Request, req *types.ListPathRequest) {

	// dispatch handler to appropriate handler based on content

	log.Tracef("remote request %s", req)

	dopts := vapi.DefaultDialOptions()

	c, err := vapi.Connect(req.ServerName, dopts)
	if err != nil {
		WriteError(w, r, "remote:%s connect %s: %s", req.ServerName, req.Path, err)
		return
	}

	list_req := &vapi.ListRequest{
		User: req.User,
		Path: req.Path,
	}

	res, err := c.Client.ListFiles(s.Ctx, list_req)
	if err != nil {
		WriteError(w, r, "remote:%s list files %s: %s", req.ServerName, req.Path, err)
		return
	}
	log.Tracef("response layout:%s files:%d",
		res.Layout, len(res.Files))

	hndlr := &handler.Handler{
		Username:     req.User,
		UrlPrefix:    res.UrlPrefix,
		RemoteServer: res.RemoteServer,
		RelPath:      res.RelPath,
		LocalPath:    res.LocalPath,
		Template:     s.Template,
	}

	if res.IsDir == false {
		// deliver the object normally
		handler.NewListHandler(hndlr).ServeHTTP(w, r)
		return
	}

	hndlr.Layout = filetype.TypeFromString(res.Layout)
	files := make([]*types.File, 0)
	for _, file := range res.Files {
		f := &types.File{
			IsDir: file.IsDir,
			Name:  file.Name,
			Size:  file.Size,
		}
		files = append(files, f)
	}
	hndlr.Files = files

	log.Debugf("dispatch %s user:%s files:%d",
		hndlr.Layout, req.User, len(files))

	reqHandler := s.Factory.MakeHandler(hndlr)
	if reqHandler == nil {
		handler.NewListHandler(hndlr).ServeHTTP(w, r)
	} else {
		reqHandler.ServeHTTP(w, r)
	}

}