mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-30 19:45:23 +02:00
refactor(billing): remove unused functions and streamline Hostinger server data handling
This commit is contained in:
@@ -55,6 +55,8 @@ export * from "./utils/backups/utils";
|
||||
export * from "./utils/backups/web-server";
|
||||
export * from "./utils/backups/compose";
|
||||
export * from "./templates/processors";
|
||||
export * from "./services/hostinger";
|
||||
export * from "./services/hetzner";
|
||||
|
||||
export * from "./utils/notifications/build-error";
|
||||
export * from "./utils/notifications/build-success";
|
||||
|
||||
118
packages/server/src/services/hetzner.ts
Normal file
118
packages/server/src/services/hetzner.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
const HETZNER_API_URL = "https://api.hetzner.cloud/v1";
|
||||
|
||||
interface HetznerLocation {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
country: string;
|
||||
city: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
network_zone: string;
|
||||
}
|
||||
|
||||
interface HetznerServerType {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
cores: number;
|
||||
memory: number;
|
||||
disk: number;
|
||||
prices: {
|
||||
location: string;
|
||||
price_hourly: {
|
||||
net: string;
|
||||
gross: string;
|
||||
};
|
||||
price_monthly: {
|
||||
net: string;
|
||||
gross: string;
|
||||
};
|
||||
}[];
|
||||
storage_type: string;
|
||||
cpu_type: string;
|
||||
architecture: string;
|
||||
}
|
||||
|
||||
interface HetznerServer {
|
||||
id: number;
|
||||
name: string;
|
||||
status: string;
|
||||
created: string;
|
||||
server_type: {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
cores: number;
|
||||
memory: number;
|
||||
disk: number;
|
||||
};
|
||||
public_net: {
|
||||
ipv4: {
|
||||
ip: string;
|
||||
};
|
||||
ipv6: {
|
||||
ip: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchHetznerLocations(
|
||||
apiKey: string,
|
||||
): Promise<HetznerLocation[]> {
|
||||
const response = await fetch(`${HETZNER_API_URL}/locations`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch Hetzner locations: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { locations?: HetznerLocation[] };
|
||||
return data.locations || [];
|
||||
}
|
||||
|
||||
export async function fetchHetznerServerTypes(
|
||||
apiKey: string,
|
||||
): Promise<HetznerServerType[]> {
|
||||
const response = await fetch(`${HETZNER_API_URL}/server_types`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch Hetzner server types: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as {
|
||||
server_types?: HetznerServerType[];
|
||||
};
|
||||
return data.server_types || [];
|
||||
}
|
||||
|
||||
export async function fetchHetznerServers(
|
||||
apiKey: string,
|
||||
): Promise<HetznerServer[]> {
|
||||
const response = await fetch(`${HETZNER_API_URL}/servers`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch Hetzner servers: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { servers?: HetznerServer[] };
|
||||
return data.servers || [];
|
||||
}
|
||||
116
packages/server/src/services/hostinger.ts
Normal file
116
packages/server/src/services/hostinger.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
const HOSTINGER_API_URL = "https://developers.hostinger.com";
|
||||
|
||||
interface HostingerCatalogItem {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string;
|
||||
prices: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
currency: string;
|
||||
price: number; // en centavos
|
||||
first_period_price: number; // precio promocional en centavos
|
||||
period: number;
|
||||
period_unit: string;
|
||||
}>;
|
||||
metadata: {
|
||||
cpus: string;
|
||||
memory: string;
|
||||
bandwidth: string;
|
||||
disk_space: string;
|
||||
network: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface HostingerServer {
|
||||
id: string;
|
||||
name: string;
|
||||
status: string;
|
||||
created_at: string;
|
||||
ip_address: string;
|
||||
plan: {
|
||||
name: string;
|
||||
cpu: number;
|
||||
ram: number;
|
||||
storage: number;
|
||||
};
|
||||
location: string;
|
||||
}
|
||||
|
||||
interface HostingerDataCenter {
|
||||
id: number;
|
||||
name: string;
|
||||
location: string;
|
||||
country: string;
|
||||
}
|
||||
|
||||
// Obtener catalog items (productos VPS con precios reales)
|
||||
export async function fetchHostingerCatalog(
|
||||
apiKey: string,
|
||||
): Promise<HostingerCatalogItem[]> {
|
||||
const response = await fetch(
|
||||
`${HOSTINGER_API_URL}/api/billing/v1/catalog?category=VPS`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
console.log(response);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch Hostinger catalog: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as HostingerCatalogItem[];
|
||||
console.log(data);
|
||||
return data || [];
|
||||
}
|
||||
|
||||
// Obtener VPS existentes
|
||||
export async function fetchHostingerServers(
|
||||
apiKey: string,
|
||||
): Promise<HostingerServer[]> {
|
||||
const response = await fetch(
|
||||
`${HOSTINGER_API_URL}/api/vps/v1/virtual-machines`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
// Si no hay servidores o falla, retornamos array vacío
|
||||
return [];
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { data?: HostingerServer[] };
|
||||
return data.data || [];
|
||||
}
|
||||
|
||||
// Obtener data centers disponibles
|
||||
export async function fetchHostingerDataCenters(
|
||||
apiKey: string,
|
||||
): Promise<HostingerDataCenter[]> {
|
||||
const response = await fetch(`${HOSTINGER_API_URL}/api/vps/v1/data-centers`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch Hostinger data centers: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as { data?: HostingerDataCenter[] };
|
||||
return data.data || [];
|
||||
}
|
||||
Reference in New Issue
Block a user