@@ -25,6 +25,7 @@ export interface IGithubRepos {
2525 description : string ;
2626 id : number ;
2727 homepage : string ;
28+ banner : ( ) => string ;
2829}
2930
3031/**
@@ -34,6 +35,7 @@ export interface IGithubRepos {
3435 */
3536export function useGitHubAutomatedRepos ( usernameGitHub : string , keyWordDeploy : string ) {
3637 const [ repository , setRepository ] = useState < IGithubRepos [ ] > ( [ ] ) ;
38+
3739 useEffect ( ( ) => {
3840 fetch ( `https://api.github.com/users/${ usernameGitHub } /repos?sort=created&per_page=999` )
3941 . then ( ( response ) => response . json ( ) )
@@ -44,14 +46,30 @@ export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: s
4446
4547 dataFilter = repository . filter ( ( item : IGithubRepos ) => item . topics . includes ( keyWordDeploy as never ) ) ;
4648
49+ const typeImg = [ 'svg' , 'png' ] ;
50+ function checkImage ( usernameGitHub : string , repositoryName : string ) : string {
51+ let checkURL = '' ;
52+ typeImg . map ( ( type ) => {
53+ const url = `https://raw.githubusercontent.com/${ usernameGitHub } /${ repositoryName } /main/src/assets/imgs/banner.${ type } ` ;
54+ const http = new XMLHttpRequest ( ) ;
55+ http . open ( 'HEAD' , url , false ) ;
56+ http . send ( ) ;
57+
58+ if ( http . status === 200 ) {
59+ checkURL = url ;
60+ }
61+ } ) ;
62+ return checkURL ;
63+ }
64+
4765 return dataFilter . map ( ( item : IGithubRepos ) => ( {
4866 id : item . id ,
4967 name : item . name ,
5068 html_url : item . html_url ,
5169 description : item . description ,
5270 topics : item . topics ,
5371 homepage : item . homepage ,
54- banner : `https://raw.githubusercontent.com/ ${ usernameGitHub } / ${ item . name } /main/src/assets/imgs/banner.png` ,
72+ banner : checkImage ( usernameGitHub , item . name ) ,
5573 } ) ) ;
5674}
5775
0 commit comments