@@ -6,15 +6,51 @@ import { Public } from './_common/decorators/public.decorator';
66import { ApiBearerAuth , ApiOperation , ApiQuery , ApiResponse } from '@nestjs/swagger' ;
77import { LRUCache } from 'lru-cache' ;
88
9+ interface GithubAuthor {
10+ login : string ;
11+ id : number ;
12+ node_id : string ;
13+ avatar_url : string ;
14+ gravatar_id : string ;
15+ url : string ;
16+ html_url : string ;
17+ followers_url : string ;
18+ following_url : string ;
19+ gists_url : string ;
20+ starred_url : string ;
21+ subscriptions_url : string ;
22+ organizations_url : string ;
23+ repos_url : string ;
24+ events_url : string ;
25+ received_events_url : string ;
26+ type : string ;
27+ user_view_type : string ;
28+ site_admin : boolean ;
29+ }
30+
31+ interface GithubAsset {
32+ [ key : string ] : any ;
33+ }
34+
935interface GithubUpdate {
10- name ?: string ;
11- commit ?: {
12- sha ?: string ;
13- url ?: string ;
14- } ;
15- zipball_url ?: string ;
16- tarball_url ?: string ;
17- node_id ?: string ;
36+ url : string ;
37+ assets_url : string ;
38+ upload_url : string ;
39+ html_url : string ;
40+ id : number ;
41+ author : GithubAuthor ;
42+ node_id : string ;
43+ tag_name : string ;
44+ target_commitish : string ;
45+ name : string ;
46+ draft : boolean ;
47+ prerelease : boolean ;
48+ created_at : string ;
49+ published_at : string ;
50+ assets : GithubAsset [ ] ;
51+ tarball_url : string ;
52+ zipball_url : string ;
53+ body : string ;
1854}
1955
2056const storage = new LRUCache ( {
@@ -47,24 +83,25 @@ export class AppController extends AbstractController {
4783 @Param ( 'project' ) project ?: string ,
4884 @Query ( 'current' ) current ?: string ,
4985 ) : Promise < Response > {
50- let data : GithubUpdate [ ] | object = { } ;
86+ let data = < GithubUpdate > { } ;
5187 // console.log('this.storage', storage.get(project))
5288 if ( storage . has ( project ) ) {
5389 this . logger . log ( `Fetching ${ project } tags from cache` ) ;
54- data = storage . get ( project ) as GithubUpdate [ ] | object ;
90+ data = storage . get ( project ) as GithubUpdate ;
5591 } else {
5692 this . logger . log ( `Fetching ${ project } tags` ) ;
57- const update = await fetch ( `https://api.github.com/repos/Libertech-FR/${ project } /tags ` , {
93+ const update = await fetch ( `https://api.github.com/repos/Libertech-FR/${ project } /releases/latest ` , {
5894 signal : AbortSignal . timeout ( 1000 ) ,
5995 } ) ;
6096 data = await update . json ( ) ;
97+ console . log ( 'update' , data )
6198 storage . set ( project , data ) ;
6299 // console.log('this.storage', storage.get(project))
63100 }
64- if ( ! Array . isArray ( data ) ) {
65- throw new BadRequestException ( `Invalid data from Github <${ JSON . stringify ( data ) } >` ) ;
66- }
67- const lastVersion = data [ 0 ] . name . replace ( / ^ v / , '' ) ;
101+ // if (!Array.isArray(data)) {
102+ // throw new BadRequestException(`Invalid data from Github <${JSON.stringify(data)}>`);
103+ // }
104+ const lastVersion = data . tag_name . replace ( / ^ v / , '' ) ;
68105 const pkgInfo = this . appService . getInfo ( ) ;
69106 const currentVersion = current || pkgInfo . version ;
70107
0 commit comments