2017-11-20 00:10:04 -05: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.
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2017-11-25 01:29:20 -05:00
|
|
|
// Feed represents a feed in the database.
|
2017-11-20 00:10:04 -05:00
|
|
|
type Feed struct {
|
|
|
|
ID int64 `json:"id"`
|
|
|
|
UserID int64 `json:"user_id"`
|
|
|
|
FeedURL string `json:"feed_url"`
|
|
|
|
SiteURL string `json:"site_url"`
|
|
|
|
Title string `json:"title"`
|
2017-12-24 21:04:34 -05:00
|
|
|
CheckedAt time.Time `json:"checked_at"`
|
|
|
|
EtagHeader string `json:"etag_header"`
|
|
|
|
LastModifiedHeader string `json:"last_modified_header"`
|
|
|
|
ParsingErrorMsg string `json:"parsing_error_message"`
|
|
|
|
ParsingErrorCount int `json:"parsing_error_count"`
|
2017-12-10 23:51:04 -05:00
|
|
|
ScraperRules string `json:"scraper_rules"`
|
2017-12-12 01:16:32 -05:00
|
|
|
RewriteRules string `json:"rewrite_rules"`
|
2017-12-12 22:19:36 -05:00
|
|
|
Crawler bool `json:"crawler"`
|
2017-11-20 00:10:04 -05:00
|
|
|
Category *Category `json:"category,omitempty"`
|
|
|
|
Entries Entries `json:"entries,omitempty"`
|
2017-12-24 21:04:34 -05:00
|
|
|
Icon *FeedIcon `json:"icon"`
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Feed) String() string {
|
|
|
|
return fmt.Sprintf("ID=%d, UserID=%d, FeedURL=%s, SiteURL=%s, Title=%s, Category={%s}",
|
|
|
|
f.ID,
|
|
|
|
f.UserID,
|
|
|
|
f.FeedURL,
|
|
|
|
f.SiteURL,
|
|
|
|
f.Title,
|
|
|
|
f.Category,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-12-24 21:04:34 -05:00
|
|
|
// Merge combine override to the current struct
|
|
|
|
func (f *Feed) Merge(override *Feed) {
|
|
|
|
if override.Title != "" && override.Title != f.Title {
|
|
|
|
f.Title = override.Title
|
|
|
|
}
|
|
|
|
|
|
|
|
if override.SiteURL != "" && override.SiteURL != f.SiteURL {
|
|
|
|
f.SiteURL = override.SiteURL
|
|
|
|
}
|
|
|
|
|
|
|
|
if override.FeedURL != "" && override.FeedURL != f.FeedURL {
|
|
|
|
f.FeedURL = override.FeedURL
|
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2017-12-24 21:04:34 -05:00
|
|
|
if override.ScraperRules != "" && override.ScraperRules != f.ScraperRules {
|
|
|
|
f.ScraperRules = override.ScraperRules
|
|
|
|
}
|
|
|
|
|
|
|
|
if override.RewriteRules != "" && override.RewriteRules != f.RewriteRules {
|
|
|
|
f.RewriteRules = override.RewriteRules
|
|
|
|
}
|
|
|
|
|
|
|
|
if override.Crawler != f.Crawler {
|
|
|
|
f.Crawler = override.Crawler
|
|
|
|
}
|
2017-11-20 00:10:04 -05:00
|
|
|
|
2017-12-24 21:04:34 -05:00
|
|
|
if override.Category != nil && override.Category.ID != 0 && override.Category.ID != f.Category.ID {
|
|
|
|
f.Category.ID = override.Category.ID
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Feeds is a list of feed
|
|
|
|
type Feeds []*Feed
|