Skip to content

Commit

Permalink
fix: fix api fields
Browse files Browse the repository at this point in the history
  • Loading branch information
TinsFox committed Sep 18, 2024
1 parent a401dc5 commit 48b87fe
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 57 deletions.
7 changes: 4 additions & 3 deletions lib/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function makeRequestSource(source: string) {

export async function request<T = any>(sources: string, init?: RequestInit) {
const url = makeRequestSource(sources);

try {
const serverResponse = await fetch(
url,
Expand All @@ -27,7 +28,7 @@ export async function request<T = any>(sources: string, init?: RequestInit) {
const jsonResponse = await serverResponse.json();
return jsonResponse as T;
} catch (e) {
console.log(e);
console.log('request error', url, e);
}
}

Expand All @@ -44,7 +45,7 @@ export function queryImages(
) {
const query = {
...payload,
source: type,
type: type,
query: tag,
};
return request<{ total: number; results: ImageDetail[] }>(
Expand Down Expand Up @@ -73,7 +74,7 @@ export function queryImageOrgDetailWithTag(name: string, tags?: string) {
});
}

export function queryImageDetailTags(name: string) {
export function queryImageTags(name: string) {
return request<{ results: ImageDetailForTag[]; count: number }>(
`v2/repositories/${name}/tags?${stringify({
page: 1,
Expand Down
109 changes: 55 additions & 54 deletions types/image.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,75 @@
export enum SYSTEM {
LINUX = 'linux',
UNKNOWN = 'unknown',
WINDOWS = 'windows'
WINDOWS = 'windows',
}

export type OperatingSystem = {
name: SYSTEM
label: Uppercase<SYSTEM>
}
name: SYSTEM;
label: Uppercase<SYSTEM>;
};

export type Repository = {
name: string
namespace: string
description: string
type: ImageType
pull_count: string
is_automated: boolean
is_official: boolean
is_trusted: boolean
last_pushed_at: string
last_pulled_at: string
}
name: string;
namespace: string;
description: string;
type: ImageType;
pull_count: string;
is_automated: boolean;
is_official: boolean;
is_trusted: boolean;
last_pushed_at: string;
last_pulled_at: string;
};

export type Architecture = {
name: string
label: string
}
name: string;
label: string;
};

export type RatePlanItem = {
id: string
repositories: Repository[]
operating_systems: OperatingSystem[]
architectures: Architecture[]
}
id: string;
repositories: Repository[];
operating_systems: OperatingSystem[];
architectures: Architecture[];
};

export type CategoryItem = {
slug: string
name: string
}
slug: string;
name: string;
};

export type ImageType = 'store' | 'community' | 'image' | 'verified_publisher'
export type ImageType = 'store' | 'community' | 'image' | 'verified_publisher';

export type ImageDetail = {
id: string
name: string
slug: string
type: ImageType
created_at: string
updated_at: string
short_description: string
source: ImageType
star_count: number
extension_reviewed: boolean
id: string;
name: string;
slug: string;
type: ImageType;
created_at: string;
updated_at: string;
short_description: string;
source: ImageType;
star_count: number;
extension_reviewed: boolean;
logo_url: {
large: string
small: string
}
categories: CategoryItem[]
rate_plans: RatePlanItem[]
}
large: string;
small: string;
};
categories: CategoryItem[];
rate_plans: RatePlanItem[];
};

export type ImageDetailForTag = ImageDetail & {
full_description: string
hub_user: string
namespace: string
pull_count: number
repository_type: ImageType
star_count: number
status: number
user: string
last_updated: string
content_types: ImageType[]
}
full_description: string;
hub_user: string;
namespace: string;
pull_count: number;
repository_type: ImageType;
star_count: number;
status: number;
user: string;
last_updated: string;
content_types: ImageType[];
description: string;
};

0 comments on commit 48b87fe

Please sign in to comment.