♻️ Refactored feed module
This commit is contained in:
46
pkg/internal/models/feed.go
Normal file
46
pkg/internal/models/feed.go
Normal file
@ -0,0 +1,46 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
|
||||
"github.com/google/uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SubscriptionFeed struct {
|
||||
cruda.BaseModel
|
||||
|
||||
URL string `json:"url"`
|
||||
IsEnabled bool `json:"enabled"`
|
||||
PullInterval int `json:"pull_interval"`
|
||||
Adapter string `json:"adapter"`
|
||||
AccountID *uint `json:"account_id"`
|
||||
LastFetchedAt *time.Time `json:"last_fetched_at"`
|
||||
}
|
||||
|
||||
type SubscriptionItem struct {
|
||||
cruda.BaseModel
|
||||
|
||||
FeedID uint `json:"feed_id"`
|
||||
Feed SubscriptionFeed `json:"feed"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Content string `json:"content"`
|
||||
URL string `json:"url"`
|
||||
Hash string `json:"hash" gorm:"uniqueIndex"`
|
||||
|
||||
// PublishedAt is the time when the article is published, when the feed adapter didn't provide this default to creation date
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
}
|
||||
|
||||
func (v *SubscriptionItem) GenHash() {
|
||||
if len(v.URL) == 0 {
|
||||
v.URL = uuid.NewString()
|
||||
return
|
||||
}
|
||||
|
||||
hash := md5.Sum([]byte(v.URL))
|
||||
v.Hash = hex.EncodeToString(hash[:])
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type NewsArticle struct {
|
||||
cruda.BaseModel
|
||||
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Content string `json:"content"`
|
||||
URL string `json:"url"`
|
||||
Hash string `json:"hash" gorm:"uniqueIndex"`
|
||||
Source string `json:"source"`
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
}
|
||||
|
||||
func (v *NewsArticle) GenHash() *NewsArticle {
|
||||
if len(v.URL) == 0 {
|
||||
v.Hash = uuid.NewString()
|
||||
return v
|
||||
}
|
||||
|
||||
hash := md5.Sum([]byte(v.URL))
|
||||
v.Hash = hex.EncodeToString(hash[:])
|
||||
return v
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package models
|
||||
|
||||
type NewsSource struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type"`
|
||||
Source string `json:"source"`
|
||||
Depth int `json:"depth"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Advanced bool `json:"advanced"`
|
||||
}
|
Reference in New Issue
Block a user