1
1
import ThunderstoreVersion from './ThunderstoreVersion' ;
2
2
3
3
export default class ThunderstoreMod extends ThunderstoreVersion {
4
- private versions : ThunderstoreVersion [ ] = [ ] ;
5
4
private rating : number = 0 ;
6
5
private owner : string = '' ;
7
6
private packageUrl : string = '' ;
@@ -14,6 +13,7 @@ export default class ThunderstoreMod extends ThunderstoreVersion {
14
13
private categories : string [ ] = [ ] ;
15
14
private hasNsfwContent : boolean = false ;
16
15
private donationLink : string | undefined ;
16
+ private latestVersion : string = '' ;
17
17
18
18
public static parseFromThunderstoreData ( data : any ) : ThunderstoreMod {
19
19
const mod = new ThunderstoreMod ( ) ;
@@ -24,43 +24,33 @@ export default class ThunderstoreMod extends ThunderstoreVersion {
24
24
mod . setDateUpdated ( data . date_updated ) ;
25
25
mod . setDeprecatedStatus ( data . is_deprecated ) ;
26
26
mod . setPinnedStatus ( data . is_pinned ) ;
27
- const versions = [ ] ;
28
- for ( const version of data . versions ) {
29
- versions . push ( new ThunderstoreVersion ( ) . make ( version ) ) ;
30
- }
31
- mod . setVersions ( versions ) ;
32
- mod . setDownloadCount (
33
- mod . versions
34
- . map ( version => version . getDownloadCount ( ) )
35
- . reduce ( ( x , y ) => x + y )
36
- ) ;
37
27
mod . setRating ( data . rating_score ) ;
38
28
mod . setTotalDownloads (
39
- mod . getVersions ( )
40
- . map ( x => x . getDownloadCount ( ) )
41
- . reduce ( ( x , y ) => x + y )
29
+ data . versions . reduce (
30
+ ( x : number , y : { downloads : number } ) => x + y . downloads ,
31
+ 0
32
+ )
42
33
) ;
43
34
mod . setPackageUrl ( data . package_url ) ;
44
35
mod . setCategories ( data . categories ) ;
45
36
mod . setNsfwFlag ( data . has_nsfw_content ) ;
46
37
mod . setDonationLink ( data . donation_link ) ;
38
+ mod . setLatestVersion ( data . versions [ 0 ] . version_number ) ;
39
+ mod . setDescription ( data . versions [ 0 ] . description ) ;
40
+ mod . setIcon ( data . versions [ 0 ] . icon ) ;
47
41
return mod ;
48
42
}
49
43
50
- public getVersions ( ) : ThunderstoreVersion [ ] {
51
- return this . versions ;
52
- }
53
-
54
- public setVersions ( versions : ThunderstoreVersion [ ] ) {
55
- this . versions = versions ;
44
+ public getLatestVersion ( ) : string {
45
+ return this . latestVersion ;
56
46
}
57
47
58
- public getLatestVersion ( ) : ThunderstoreVersion {
59
- return this . getVersions ( ) . reduce ( reduceToNewestVersion ) ;
48
+ public setLatestVersion ( versionNumber : string ) {
49
+ this . latestVersion = versionNumber ;
60
50
}
61
51
62
52
public getLatestDependencyString ( ) : string {
63
- return `${ this . getFullName ( ) } -${ this . getLatestVersion ( ) . toString ( ) } ` ;
53
+ return `${ this . getFullName ( ) } -${ this . getLatestVersion ( ) } ` ;
64
54
}
65
55
66
56
public getRating ( ) : number {
@@ -159,7 +149,3 @@ export default class ThunderstoreMod extends ThunderstoreVersion {
159
149
this . donationLink = url ;
160
150
}
161
151
}
162
-
163
- function reduceToNewestVersion ( v1 : ThunderstoreVersion , v2 : ThunderstoreVersion ) {
164
- return v1 . getVersionNumber ( ) . isNewerThan ( v2 . getVersionNumber ( ) ) ? v1 : v2 ;
165
- } ;
0 commit comments