@@ -10,27 +10,24 @@ import Link from "ink-link";
1010import { apiClient } from "../../apiClient.ts" ;
1111import { logAndQuit } from "../../helpers/errors.ts" ;
1212import { formatDate } from "../../helpers/format-time.ts" ;
13+ import type { components } from "../../schema.ts" ;
1314import { Row } from "../Row.tsx" ;
1415
1516dayjs . extend ( utc ) ;
1617dayjs . extend ( advanced ) ;
1718dayjs . extend ( timezone ) ;
1819
20+ type Image = components [ "schemas" ] [ "sfc-api_ImageListEntry" ] ;
21+ type Download = components [ "schemas" ] [ "sfc-api_ImageDownloadResponse" ] ;
22+
1923function ImageDisplay ( {
2024 image,
2125 download,
2226} : {
23- image : {
24- name : string ;
25- id : string ;
26- upload_status : string ;
27- sha256_hash : string | null ;
28- } ;
29- download : { url : string ; expires_at : number } | null ;
27+ image : Image ;
28+ download : Download | null ;
3029} ) {
31- const expiresAt = download ?. expires_at
32- ? new Date ( download . expires_at * 1000 )
33- : null ;
30+ const expiresAt = download ? new Date ( download . expires_at * 1000 ) : null ;
3431 const isExpired = expiresAt ? expiresAt < new Date ( ) : false ;
3532
3633 return (
@@ -43,7 +40,7 @@ function ImageDisplay({
4340
4441 < Box paddingX = { 1 } flexDirection = "column" >
4542 < Row head = "Status: " value = { formatStatusInk ( image . upload_status ) } />
46- { image . sha256_hash && < Row head = "SHA256: " value = { image . sha256_hash } /> }
43+ { image . sha256 && < Row head = "SHA256: " value = { image . sha256 } /> }
4744 { download && (
4845 < >
4946 < Row
@@ -92,50 +89,48 @@ function formatStatusInk(status: string): React.ReactElement {
9289 return < Text color = "cyan" > Completed</ Text > ;
9390 case "failed" :
9491 return < Text color = "red" > Failed</ Text > ;
92+ case "revoked" :
93+ return < Text color = "red" > Revoked</ Text > ;
9594 default :
9695 return < Text dimColor > Unknown</ Text > ;
9796 }
9897}
9998
100- const get = new Command ( "get" )
101- . description ( "Get image details and download URL" )
102- . argument ( "<id>" , "Image ID or name" )
103- . option ( "--json" , "Output JSON" )
104- . action ( async ( id , opts ) => {
105- const client = await apiClient ( ) ;
99+ export function createGet ( ) {
100+ return new Command ( "get" )
101+ . alias ( "show" )
102+ . description ( "Get image details and download URL" )
103+ . argument ( "<id>" , "Image ID or name" )
104+ . option ( "--json" , "Output JSON" )
105+ . action ( async ( id , opts ) => {
106+ const client = await apiClient ( ) ;
106107
107- const { data : image , response } = await client . GET ( "/v2/images/{id}" , {
108- params : { path : { id } } ,
109- } ) ;
110- if ( ! response . ok || ! image ) {
111- logAndQuit (
112- `Failed to get image: ${ response . status } ${ response . statusText } ` ,
108+ const { data : image , response } = await client . GET (
109+ "/preview/v2/images/{id}" ,
110+ { params : { path : { id } } } ,
113111 ) ;
114- }
115-
116- // Fetch download URL if image is completed
117- let download = null ;
118- if ( image . upload_status === "completed" ) {
119- const { data : downloadData , response : downloadResponse } =
120- await client . GET ( "/v2/images/{id}/download" , {
121- params : { path : { id } } ,
122- } ) ;
123- if ( downloadResponse . ok && downloadData ) {
124- download = downloadData ;
112+ if ( ! response . ok || ! image ) {
113+ logAndQuit (
114+ `Failed to get image: ${ response . status } ${ response . statusText } ` ,
115+ ) ;
125116 }
126- }
127117
128- if ( opts . json ) {
129- console . log ( JSON . stringify ( { ...image , download } , null , 2 ) ) ;
130- return ;
131- }
118+ let download : Download | null = null ;
119+ if ( image . upload_status === "completed" ) {
120+ const { data : downloadData } = await client . GET (
121+ "/preview/v2/images/{id}/download" ,
122+ { params : { path : { id } } } ,
123+ ) ;
124+ if ( downloadData ) {
125+ download = downloadData ;
126+ }
127+ }
132128
133- render (
134- < ImageDisplay
135- image = { { ...image , sha256_hash : image . sha256_hash ?? null } }
136- download = { download }
137- /> ,
138- ) ;
139- } ) ;
129+ if ( opts . json ) {
130+ console . log ( JSON . stringify ( { ...image , download } , null , 2 ) ) ;
131+ return ;
132+ }
140133
141- export default get ;
134+ render ( < ImageDisplay image = { image } download = { download } /> ) ;
135+ } ) ;
136+ }
0 commit comments