Skip to content

Commit

Permalink
Merge pull request #66 from devpt-org/fix/lemmy-possible-downtime
Browse files Browse the repository at this point in the history
Hotfix: Prevenir encerramento abrupto do bot
  • Loading branch information
IvoPereira authored Jul 7, 2023
2 parents 2d34e40 + 79c55c8 commit 5d6d802
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions infrastructure/service/lemmyContentAggregatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ export default class LemmyContentAggregatorService implements ContentAggregatorS
private feedUrl = "https://lemmy.pt/api/v3/post/list?community_name=devpt&limit=10&page=1&sort=New";

async fetchLastPosts(): Promise<Post[]> {
const response = await fetch(this.feedUrl);
let unpinnedPosts = [];

const data = await response.json();
try {
const response = await fetch(this.feedUrl);

const unpinnedPosts = data.posts
.filter((item: any) => !item.post.featured_community && !item.post.featured_local)
.map(
(item: any) =>
new Post({
authorName: item.creator.display_name || item.creator.name,
title: item.post.name,
link: item.post.ap_id,
description: item.post.body,
createdAt: new Date(item.post.published),
})
);
const data = await response.json();

unpinnedPosts = data.posts
.filter((item: any) => !item.post.featured_community && !item.post.featured_local)
.map(
(item: any) =>
new Post({
authorName: item.creator.display_name || item.creator.name,
title: item.post.name,
link: item.post.ap_id,
description: item.post.body,
createdAt: new Date(item.post.published),
})
);
} catch (e) {}

return unpinnedPosts;
}
Expand Down

0 comments on commit 5d6d802

Please sign in to comment.