Exemple #1
0
func (r *ReleasesCommand) list(c *kingpin.ParseContext) error {
	_, dbh := commonInit()

	limit := r.Limit
	if limit == 0 {
		limit = 10
	}

	var cats []types.Category
	for _, c := range r.Categories {
		cats = append(cats, types.CategoryFromInt(c))
	}

	releases, err := dbh.SearchReleases(r.SearchTerm, 0, r.Limit, cats)
	if err != nil {
		return err
	}
	fmt.Printf("Found %d releases matching your search criteria\n", len(releases))
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 5, 0, 1, ' ', 0)
	fmt.Fprintln(w, "Name\tCategory\tDate\tGroup\tHash")
	for _, r := range releases {
		fmt.Fprintln(w, fmt.Sprintf("%s\t%s\t%s\t%s\t%s", r.Name, r.CategoryName(), r.Posted, r.Group.Name, r.Hash))
	}
	w.Flush()
	return nil
}
Exemple #2
0
func searchHandler(rw http.ResponseWriter, r *http.Request) {
	rend := render.New()
	searchrequest := new(searchReq)
	errs := binding.Bind(r, searchrequest)
	if errs.Len() > 0 {
		handleBindingErrors(rw, errs)
		return
	}
	if searchrequest.Limit == 0 {
		searchrequest.Limit = defaultLimit
	}

	dbh := getDB(r)
	var cats []types.Category
	for _, c := range searchrequest.Categories {
		cats = append(cats, types.CategoryFromInt(c))
	}

	releases, err := dbh.SearchReleases(searchrequest.Query, searchrequest.Offset, searchrequest.Limit, cats)
	if err != nil {
		rend.Text(rw, http.StatusInternalServerError, fmt.Sprintf("Error: %v", err))
		return
	}

	sr := &searchResponse{
		Header:       template.HTML(`<?xml version="1.0" encoding="UTF-8"?>`),
		URL:          r.RequestURI,
		ContactEmail: "[email protected]",
		Offset:       searchrequest.Offset,
		Total:        len(releases),
		Image: &rssImage{
			URL:         "http://localhost/foo.jpg",
			Title:       "gonab",
			Link:        "myurl",
			Description: "visit gonab",
		},
	}
	sr.NZBs = make([]NZB, len(releases))
	for i, rel := range releases {
		sr.NZBs[i] = NZB{
			Title:       rel.Name,
			Link:        makeNZBUrl(rel, r),
			Size:        rel.Size,
			Category:    rel.Category.Name,
			Description: rel.Name,
			GUID:        rel.Hash,
			PermaLink:   true,
			Comments:    fmt.Sprintf("https://%s/nzb/details/%s#comments", r.Host, rel.Hash),
			Date:        rel.Posted,
			Group:       rel.Group.Name,
		}
	}

	searchResponseTemplate.Execute(rw, sr)
}