From 7242a6844f5ed06c8dc75ef2a057885974c10b8c Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 14 Oct 2024 23:39:41 +0800 Subject: [PATCH] auto upload --- backend-server/api/entry.go | 2 +- backend-server/knowledge/api.go | 14 ++++++++------ backend-server/model/feed.go | 1 + backend-server/storage/feed.go | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend-server/api/entry.go b/backend-server/api/entry.go index 2aa6b4e..b12879c 100644 --- a/backend-server/api/entry.go +++ b/backend-server/api/entry.go @@ -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 } diff --git a/backend-server/knowledge/api.go b/backend-server/knowledge/api.go index 6b8192e..609dad3 100644 --- a/backend-server/knowledge/api.go +++ b/backend-server/knowledge/api.go @@ -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) } @@ -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)) @@ -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)) @@ -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) } } } @@ -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) { diff --git a/backend-server/model/feed.go b/backend-server/model/feed.go index e460c70..6d64670 100644 --- a/backend-server/model/feed.go +++ b/backend-server/model/feed.go @@ -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 } diff --git a/backend-server/storage/feed.go b/backend-server/storage/feed.go index 3a37933..744a1a4 100644 --- a/backend-server/storage/feed.go +++ b/backend-server/storage/feed.go @@ -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, @@ -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