Skip to content

Commit

Permalink
Merge pull request #194 from glanceapp/backport-fixes
Browse files Browse the repository at this point in the history
Backport fixes from v0.6.0 to v0.5.0
  • Loading branch information
svilenmarkov authored Aug 9, 2024
2 parents 82b6531 + 139937f commit b37f8a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions internal/assets/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ kbd:active {
height: 6rem;
font: inherit;
outline: none;
color: var(--color-text-highlight);
}

.search-input::placeholder {
Expand Down
27 changes: 4 additions & 23 deletions internal/feed/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
"time"
)

type githubReleaseResponseJson struct {
type githubReleaseLatestResponseJson struct {
TagName string `json:"tag_name"`
PublishedAt string `json:"published_at"`
HtmlUrl string `json:"html_url"`
Draft bool `json:"draft"`
PreRelease bool `json:"prerelease"`
Reactions struct {
Downvotes int `json:"-1"`
} `json:"reactions"`
Expand All @@ -39,7 +37,7 @@ func FetchLatestReleasesFromGithub(repositories []string, token string) (AppRele
requests := make([]*http.Request, len(repositories))

for i, repository := range repositories {
request, _ := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/%s/releases?per_page=10", repository), nil)
request, _ := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repository), nil)

if token != "" {
request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
Expand All @@ -48,7 +46,7 @@ func FetchLatestReleasesFromGithub(repositories []string, token string) (AppRele
requests[i] = request
}

task := decodeJsonFromRequestTask[[]githubReleaseResponseJson](defaultClient)
task := decodeJsonFromRequestTask[githubReleaseLatestResponseJson](defaultClient)
job := newJob(task, requests).withWorkers(15)
responses, errs, err := workerPoolDo(job)

Expand All @@ -65,24 +63,7 @@ func FetchLatestReleasesFromGithub(repositories []string, token string) (AppRele
continue
}

releases := responses[i]

if len(releases) < 1 {
failed++
slog.Error("No releases found", "repository", repositories[i], "url", requests[i].URL)
continue
}

var liveRelease *githubReleaseResponseJson

for i := range releases {
release := &releases[i]

if !release.Draft && !release.PreRelease {
liveRelease = release
break
}
}
liveRelease := &responses[i]

if liveRelease == nil {
slog.Error("No live release found", "repository", repositories[i], "url", requests[i].URL)
Expand Down
33 changes: 33 additions & 0 deletions internal/feed/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/mmcdole/gofeed"
gofeedext "github.com/mmcdole/gofeed/extensions"
)

type RSSFeedItem struct {
Expand Down Expand Up @@ -145,6 +146,8 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) {

if item.Image != nil {
rssItem.ImageURL = item.Image.URL
} else if url := findThumbnailInItemExtensions(item); url != "" {
rssItem.ImageURL = url
} else if feed.Image != nil {
rssItem.ImageURL = feed.Image.URL
}
Expand All @@ -161,6 +164,36 @@ func getItemsFromRSSFeedTask(request RSSFeedRequest) ([]RSSFeedItem, error) {
return items, nil
}

func recursiveFindThumbnailInExtensions(extensions map[string][]gofeedext.Extension) string {
for _, exts := range extensions {
for _, ext := range exts {
if ext.Name == "thumbnail" || ext.Name == "image" {
if url, ok := ext.Attrs["url"]; ok {
return url
}
}

if ext.Children != nil {
if url := recursiveFindThumbnailInExtensions(ext.Children); url != "" {
return url
}
}
}
}

return ""
}

func findThumbnailInItemExtensions(item *gofeed.Item) string {
media, ok := item.Extensions["media"]

if !ok {
return ""
}

return recursiveFindThumbnailInExtensions(media)
}

func GetItemsFromRSSFeeds(requests []RSSFeedRequest) (RSSFeedItems, error) {
job := newJob(getItemsFromRSSFeedTask, requests).withWorkers(10)
feeds, errs, err := workerPoolDo(job)
Expand Down

0 comments on commit b37f8a8

Please sign in to comment.