Skip to content

Commit

Permalink
Merge pull request #63 from beclab/feat/beat-arm
Browse files Browse the repository at this point in the history
auto upload
  • Loading branch information
kaki-admin authored Oct 15, 2024
2 parents 6d665b1 + 7242a68 commit 91dd815
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend-server/api/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (h *handler) newFetchContent(entry *model.Entry) string {
knowledge.UpdateLibraryEntryContent(updateEntry)

if entry.MediaContent != "" || entry.MediaUrl != "" {
knowledge.NewEnclosure(entry, h.store)
knowledge.NewEnclosure(entry, nil, h.store)
}
return entry.FullContent
}
Expand Down
14 changes: 8 additions & 6 deletions backend-server/knowledge/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func SaveFeedEntries(store *storage.Storage, entries model.Entries, feed *model.
reqModel := model.GetEntryAddModel(entryModel, feed.FeedURL)
addList = append(addList, reqModel)
}
doReq(addList, entries, store, true)
doReq(addList, entries, feed, store, true)

}

Expand Down Expand Up @@ -55,7 +55,7 @@ func doDownloadReq(download model.EntryDownloadModel) {

common.Logger.Info("update download finish ", zap.String("download url", download.DataSource))
}
func NewEnclosure(entry *model.Entry, store *storage.Storage) {
func NewEnclosure(entry *model.Entry, feed *model.Feed, store *storage.Storage) {
exist := store.GetEnclosureNumByEntry(entry.ID)
if exist > 0 {
common.Logger.Info("new enclosure exit where entry's enclosure exist ", zap.String("entry id:", entry.ID))
Expand All @@ -71,13 +71,15 @@ func NewEnclosure(entry *model.Entry, store *storage.Storage) {
download.FileName = ""
download.FileType = entry.MediaType

doDownloadReq(download)
if feed == nil || feed.AutoDownload {
doDownloadReq(download)
}
} else {
common.Logger.Error("entry mediaUrl is null")
}
}

func doReq(list []*model.EntryAddModel, entries model.Entries, store *storage.Storage, isNew bool) {
func doReq(list []*model.EntryAddModel, entries model.Entries, feed *model.Feed, store *storage.Storage, isNew bool) {
jsonByte, _ := json.Marshal(list)
url := common.EntryMonogoUpdateApiUrl()
request, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonByte))
Expand Down Expand Up @@ -108,7 +110,7 @@ func doReq(list []*model.EntryAddModel, entries model.Entries, store *storage.St
if ok {
entry.ID = entryID
if entry.MediaContent != "" || entry.MediaUrl != "" {
NewEnclosure(entry, store)
NewEnclosure(entry, feed, store)
}
}
}
Expand All @@ -129,7 +131,7 @@ func UpdateFeedEntries(store *storage.Storage, entries model.Entries, feed *mode
reqModel := model.GetEntryUpdateSourceModel(entryModel, feed.FeedURL)
addList = append(addList, reqModel)
}
doReq(addList, entries, store, false)
doReq(addList, entries, feed, store, false)
}

func UpdateLibraryEntryContent(entry *model.Entry) {
Expand Down
1 change: 1 addition & 0 deletions backend-server/model/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Feed struct {
IgnoreHTTPCache bool `json:"ignore_http_cache"`
EtagHeader string `json:"etag_header"`
LastModifiedHeader string `json:"last_modified_header"`
AutoDownload bool `json:"auto_download"`
Entries Entries
}

Expand Down
3 changes: 2 additions & 1 deletion backend-server/storage/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (s *Storage) GetFeedById(feedID string) (*model.Feed, error) {
var feed model.Feed
query := `SELECT id, feed_url, site_url, title,etag_header,last_modified_header,checked_at,parsing_error_count,
parsing_error_message,user_agent,cookie,username,password,ignore_http_cache,allow_self_signed_certificates,fetch_via_proxy,
icon_type,icon_content
icon_type,icon_content,auto_download
FROM feeds WHERE id=$1`
err := s.db.QueryRow(query, feedID).Scan(&feed.ID,
&feed.FeedURL,
Expand All @@ -40,6 +40,7 @@ func (s *Storage) GetFeedById(feedID string) (*model.Feed, error) {
&feed.FetchViaProxy,
&feed.IconMimeType,
&feed.IconContent,
&feed.AutoDownload,
)
if err == sql.ErrNoRows {
return nil, nil
Expand Down

0 comments on commit 91dd815

Please sign in to comment.