@@ -5,6 +5,7 @@ import { Endpoint, nullSchema } from '@/api-helpers/global';
55const dockerRepoName = 'middlewareeng/middleware' ;
66const githubOrgName = 'middlewarehq' ;
77const githubRepoName = 'middleware' ;
8+ const latestTagName = 'latest' ;
89
910const endpoint = new Endpoint ( nullSchema ) ;
1011
@@ -26,13 +27,6 @@ type CheckNewVersionResponse = {
2627 current_docker_image_build_date : Date ;
2728} ;
2829
29- type DockerHubAPIResponse = {
30- count : number ;
31- next : string | null ;
32- previous : string | null ;
33- results : TagResult [ ] ;
34- } ;
35-
3630type TagResult = {
3731 creator : number ;
3832 id : number ;
@@ -69,7 +63,7 @@ type DockerImage = {
6963type TagCompressed = {
7064 name : string ;
7165 last_updated : string ;
72- digest : string ;
66+ digest ? : string ;
7367} ;
7468
7569function getProjectVersionInfo ( ) : ProjectVersionInfo {
@@ -82,15 +76,17 @@ function getProjectVersionInfo(): ProjectVersionInfo {
8276 } ;
8377}
8478
85- async function fetchDockerHubTags ( ) : Promise < TagCompressed [ ] > {
86- const dockerHubUrl = `https://hub.docker.com/v2/repositories/${ dockerRepoName } /tags/` ;
87- const response = await axios . get < DockerHubAPIResponse > ( dockerHubUrl ) ;
79+ async function fetchDockerHubLatestTag ( ) : Promise < TagCompressed > {
80+ const latestTagUrl = `https://hub.docker.com/v2/repositories/${ dockerRepoName } /tags/${ latestTagName } ` ;
81+ const latestTag = ( await axios . get < TagResult > ( latestTagUrl ) ) . data ;
82+
83+ const amdArchImage = latestTag . images . find ( ( i ) => i . architecture === 'amd64' ) ;
8884
89- return response . data . results . map ( ( tag ) => ( {
90- name : tag . name ,
91- digest : tag . images [ 0 ] . digest ,
92- last_updated : tag . last_updated
93- } ) ) ;
85+ return {
86+ name : latestTag . name ,
87+ digest : amdArchImage ? .digest ,
88+ last_updated : latestTag . last_updated
89+ } ;
9490}
9591
9692function isUpdateAvailable ( {
@@ -122,16 +118,14 @@ function isUpdateAvailable({
122118async function checkNewImageRelease ( ) : Promise < CheckNewVersionResponse > {
123119 const versionInfo = getProjectVersionInfo ( ) ;
124120
125- const [ dockerRemoteTags ] = await Promise . all ( [ fetchDockerHubTags ( ) ] ) ;
121+ const latestTag = await fetchDockerHubLatestTag ( ) ;
126122
127- dockerRemoteTags . sort (
128- ( a , b ) =>
129- new Date ( b . last_updated ) . getTime ( ) - new Date ( a . last_updated ) . getTime ( )
130- ) ;
131- const latestTag = dockerRemoteTags [ 0 ] ;
132123 const latestRemoteDate = new Date ( latestTag . last_updated ) ;
133124
134- const latestDockerImageLink = `https://hub.docker.com/layers/${ dockerRepoName } /${ latestTag . name } /images/${ latestTag . digest } ` ;
125+ let latestDockerImageLink = `https://hub.docker.com/r/${ dockerRepoName } /tags` ;
126+ if ( latestTag . digest ) {
127+ latestDockerImageLink = `https://hub.docker.com/layers/${ dockerRepoName } /${ latestTag . name } /images/${ latestTag . digest } ` ;
128+ }
135129
136130 const githubRepLink = `https://github.com/${ githubOrgName } /${ githubRepoName } ` ;
137131
0 commit comments