web/src/utils/fetch-docker-instructions.ts

78 lines · 1697 bytes

 1
 2
 3export const fetchDockerData = async (serviceName: string): Promise<TemplateResponse | null> => {
 4  const endpoint = `https://docker-info.as93.workers.dev/${serviceName}`;
 5  try {
 6    return await fetch(endpoint).then((res) => res.json());
 7  } catch (error) {
 8    console.error('Error fetching docker data:', error);
 9    return null;
10  }
11};
12
13interface DockerTemplatePort {
14  privatePort: number;
15  publicPort: number;
16  type: string; // Typically TCP/UDP
17}
18
19interface DockerTemplateEnvironmentVariable {
20  name: string;
21  label?: string;
22  default?: string;
23  description?: string;
24}
25
26interface DockerTemplateVolume {
27  bind: string;
28  container: string;
29  readonly?: boolean;
30}
31
32interface DockerTemplate {
33  name?: string;
34  title: string;
35  description?: string;
36  logo?: string;
37  image: string;
38  categories?: string[];
39  ports?: DockerTemplatePort[];
40  env?: DockerTemplateEnvironmentVariable[];
41  volumes?: DockerTemplateVolume[];
42  restart_policy?: string; // Typically "no", "always", "unless-stopped", "on-failure"
43}
44
45interface DockerHubData {
46  user: string;
47  name: string;
48  namespace: string;
49  repository_type: string;
50  status: number;
51  description: string;
52  is_private: boolean;
53  is_automated: boolean;
54  can_edit: boolean;
55  star_count: number;
56  pull_count: number;
57  last_updated: string;
58  date_registered: string;
59  build_status: string;
60  permissions: {
61    read: boolean;
62    write: boolean;
63    admin: boolean;
64  };
65}
66
67interface DockerUsage {
68  dockerRunCommand: string;
69  dockerComposeFile: string;
70}
71
72export interface TemplateResponse {
73  found: boolean;
74  error: string | null;
75  template?: DockerTemplate;
76  dockerHubData?: DockerHubData;
77  usage?: DockerUsage;
78}