File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Original file line number Diff line number Diff line change 1
1
import Post from "../../domain/service/contentAggregatorService/post" ;
2
2
import ContentAggregatorService from "../../domain/service/contentAggregatorService/contentAggregatorService" ;
3
3
4
+ interface LemmyPostAuthor {
5
+ display_name : string ;
6
+ name : string ;
7
+ }
8
+
9
+ interface LemmyPostData {
10
+ featured_community : boolean ;
11
+ featured_local : boolean ;
12
+ name : string ;
13
+ ap_id : string ;
14
+ body : string ;
15
+ published : string ;
16
+ }
17
+
18
+ interface LemmyPost {
19
+ creator : LemmyPostAuthor ;
20
+ post : LemmyPostData ;
21
+ }
22
+
23
+ interface LemmyApiResponse {
24
+ posts : LemmyPost [ ] ;
25
+ }
26
+
4
27
export default class LemmyContentAggregatorService implements ContentAggregatorService {
5
28
private feedUrl = "https://lemmy.pt/api/v3/post/list?community_name=devpt&limit=10&page=1&sort=New" ;
6
29
7
30
async fetchLastPosts ( ) : Promise < Post [ ] > {
8
- let unpinnedPosts = [ ] ;
31
+ let unpinnedPosts : Post [ ] = [ ] ;
9
32
10
33
try {
11
34
const response = await fetch ( this . feedUrl ) ;
12
-
13
- const data = await response . json ( ) ;
35
+ const data : LemmyApiResponse = await response . json ( ) ;
14
36
15
37
unpinnedPosts = data . posts
16
- . filter ( ( item : any ) => ! item . post . featured_community && ! item . post . featured_local )
38
+ . filter ( ( item : LemmyPost ) => ! item . post . featured_community && ! item . post . featured_local )
17
39
. map (
18
- ( item : any ) =>
40
+ ( item : LemmyPost ) =>
19
41
new Post ( {
20
42
authorName : item . creator . display_name || item . creator . name ,
21
43
title : item . post . name ,
You can’t perform that action at this time.
0 commit comments