2017-11-20 06:10:04 +01:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package form // import "miniflux.app/ui/form"
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2017-11-28 06:30:04 +01:00
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/errors"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// SubscriptionForm represents the subscription form.
|
2017-11-20 06:10:04 +01:00
|
|
|
type SubscriptionForm struct {
|
2020-09-10 08:28:54 +02:00
|
|
|
URL string
|
|
|
|
CategoryID int64
|
|
|
|
Crawler bool
|
|
|
|
FetchViaProxy bool
|
|
|
|
UserAgent string
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
ScraperRules string
|
|
|
|
RewriteRules string
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// Validate makes sure the form values are valid.
|
2017-11-20 06:10:04 +01:00
|
|
|
func (s *SubscriptionForm) Validate() error {
|
|
|
|
if s.URL == "" || s.CategoryID == 0 {
|
2018-09-22 03:53:29 +02:00
|
|
|
return errors.NewLocalizedError("error.feed_mandatory_fields")
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// NewSubscriptionForm returns a new SubscriptionForm.
|
2017-11-20 06:10:04 +01:00
|
|
|
func NewSubscriptionForm(r *http.Request) *SubscriptionForm {
|
|
|
|
categoryID, err := strconv.Atoi(r.FormValue("category_id"))
|
|
|
|
if err != nil {
|
|
|
|
categoryID = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return &SubscriptionForm{
|
2020-09-10 08:28:54 +02:00
|
|
|
URL: r.FormValue("url"),
|
|
|
|
Crawler: r.FormValue("crawler") == "1",
|
|
|
|
FetchViaProxy: r.FormValue("fetch_via_proxy") == "1",
|
|
|
|
CategoryID: int64(categoryID),
|
|
|
|
UserAgent: r.FormValue("user_agent"),
|
|
|
|
Username: r.FormValue("feed_username"),
|
|
|
|
Password: r.FormValue("feed_password"),
|
|
|
|
ScraperRules: r.FormValue("scraper_rules"),
|
|
|
|
RewriteRules: r.FormValue("rewrite_rules"),
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
}
|