Skip to content

Commit

Permalink
changed api routes
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 committed Sep 25, 2023
1 parent 4394fdf commit e374a99
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 140 deletions.
87 changes: 0 additions & 87 deletions api/src/providers/providerStatusProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,93 +42,6 @@ export async function getNetworkCapacity() {
};
}

export async function getProviders() {
const nowUtc = toUTC(new Date());

const providers = await Provider.findAll({
where: {
isOnline: true,
deletedHeight: null
},
include: [
{
model: ProviderAttribute
},
{
model: ProviderAttributeSignature
},
{
model: ProviderSnapshot,
attributes: ["isOnline", "id", "checkDate"],
required: false,
separate: true,
where: {
checkDate: {
[Op.gte]: add(nowUtc, { days: -1 })
}
}
}
]
});
const filteredProviders = providers.filter((value, index, self) => self.map((x) => x.hostUri).indexOf(value.hostUri) === index);

return filteredProviders.map((x) => {
const isValidVersion = x.cosmosSdkVersion ? semver.gte(x.cosmosSdkVersion, "v0.45.9") : false;
const name = x.isOnline ? new URL(x.hostUri).hostname : null;

return {
owner: x.owner,
name: name,
hostUri: x.hostUri,
createdHeight: x.createdHeight,
email: x.email,
website: x.website,
lastCheckDate: x.lastCheckDate,
deploymentCount: x.deploymentCount,
leaseCount: x.leaseCount,
cosmosSdkVersion: x.cosmosSdkVersion,
akashVersion: x.akashVersion,
ipRegion: x.ipRegion,
ipRegionCode: x.ipRegionCode,
ipCountry: x.ipCountry,
ipCountryCode: x.ipCountryCode,
ipLat: x.ipLat,
ipLon: x.ipLon,
attributes: x.providerAttributes.map((attr) => ({
key: attr.key,
value: attr.value,
auditedBy: x.providerAttributeSignatures.filter((pas) => pas.key === attr.key && pas.value === attr.value).map((pas) => pas.auditor)
})),
activeStats: {
cpu: x.activeCPU,
gpu: x.activeGPU,
memory: x.activeMemory,
storage: x.activeStorage
},
pendingStats: {
cpu: isValidVersion ? x.pendingCPU : 0,
gpu: isValidVersion ? x.pendingGPU : 0,
memory: isValidVersion ? x.pendingMemory : 0,
storage: isValidVersion ? x.pendingStorage : 0
},
availableStats: {
cpu: isValidVersion ? x.availableCPU : 0,
gpu: isValidVersion ? x.availableGPU : 0,
memory: isValidVersion ? x.availableMemory : 0,
storage: isValidVersion ? x.availableStorage : 0
},
uptime7d: x.uptime7d,
uptime: x.providerSnapshots.map((ps) => ({
id: ps.id,
isOnline: ps.isOnline,
checkDate: ps.checkDate
})),
isValidVersion,
isOnline: x.isOnline
};
});
}

export const getProviderList = async () => {
const providers = await Provider.findAll({
where: {
Expand Down
12 changes: 2 additions & 10 deletions api/src/routers/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getValidator,
getValidators
} from "@src/providers/apiNodeProvider";
import { getNetworkCapacity, getProviderDetail, getProviderList, getProviders } from "@src/providers/providerStatusProvider";
import { getNetworkCapacity, getProviderDetail, getProviderList } from "@src/providers/providerStatusProvider";
import { getDashboardData, getGraphData, getProviderActiveLeasesGraphData, getProviderGraphData } from "@src/db/statsProvider";
import { round } from "@src/utils/math";
import { isValidBech32Address } from "@src/utils/addresses";
Expand Down Expand Up @@ -227,22 +227,14 @@ apiRouter.get(

apiRouter.get(
"/providers",
asyncHandler(async (req, res) => {
const providers = await getProviders();
res.send(providers);
})
);

apiRouter.get(
"/providerList",
asyncHandler(async (req, res) => {
const providers = await cacheResponse(60, cacheKeys.getProviderList, getProviderList);
res.send(providers);
})
);

apiRouter.get(
"/providerDetail/:address",
"/providers/:address",
asyncHandler(async (req, res) => {
if (!req.params.address) {
res.status(400).send("Address is undefined.");
Expand Down
1 change: 0 additions & 1 deletion deploy-web/src/pages/deployments/[dseq].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const DeploymentDetailPage: React.FunctionComponent<Props> = ({ dseq }) => {
const hasLeases = leases && leases.length > 0;
const { isLocalCertMatching, localCert, isCreatingCert, createCertificate } = useCertificate();
const [deploymentManifest, setDeploymentManifest] = useState(null);
// const { providers, getProviders, isLoadingProviders } = useAkashProviders();
const { data: providers, isFetching: isLoadingProviders, refetch: getProviders } = useProviderList();
const isActive = deployment?.state === "active" && leases?.some(x => x.state === "active");

Expand Down
2 changes: 1 addition & 1 deletion deploy-web/src/pages/providers/[owner]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export default ProviderDetailPage;

export async function getServerSideProps({ params, query }) {
const apiUrl = getNetworkBaseApiUrl(query.network as string);
const response = await axios.get(`${apiUrl}/providerDetail/${params?.owner}`);
const response = await axios.get(`${apiUrl}/providers/${params?.owner}`);

return {
props: {
Expand Down
41 changes: 2 additions & 39 deletions deploy-web/src/queries/useProvidersQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useQuery } from "react-query";
import { QueryKeys } from "./queryKeys";
import axios, { AxiosResponse } from "axios";
import { useSettings } from "../context/SettingsProvider";
import { ApiUrlService, loadWithPagination } from "@src/utils/apiUtils";
import { ApiUrlService } from "@src/utils/apiUtils";
import { getNetworkCapacityDto, providerStatusToDto } from "@src/utils/providerUtils";
import { PROVIDER_PROXY_URL } from "@src/utils/constants";
import { ApiProviderDetail, ApiProviderList, Auditor, RpcProvider } from "@src/types/provider";
import { ApiProviderDetail, ApiProviderList, Auditor } from "@src/types/provider";
import { ProviderAttributesSchema } from "@src/types/providerAttributes";

async function getProviderDetail(owner: string): Promise<ApiProviderDetail> {
Expand All @@ -20,42 +19,6 @@ export function useProviderDetail(owner: string, options) {
return useQuery(QueryKeys.getProviderDetailKey(owner), () => getProviderDetail(owner), options);
}

// async function getProviders(apiEndpoint: string): Promise<Array<RpcProvider>> {
// if (apiEndpoint) {
// const providers = await loadWithPagination(ApiUrlService.providers(apiEndpoint), "providers", 1000);

// return providers;
// } else {
// return null;
// }
// }

// export function useProviders(options = {}) {
// const { settings } = useSettings();
// return useQuery(QueryKeys.getProvidersKey(), () => getProviders(settings.apiEndpoint), {
// ...options,
// refetchInterval: false,
// refetchIntervalInBackground: false,
// refetchOnWindowFocus: false,
// refetchOnReconnect: false
// });
// }

// async function getDataNodeProviders() {
// const response = await axios.get(ApiUrlService.apiProviders());
// return response.data;
// }

// export function useDataNodeProviders(options) {
// return useQuery(QueryKeys.getDataNodeProvidersKey(), () => getDataNodeProviders(), {
// ...options,
// refetchInterval: 15000,
// refetchIntervalInBackground: false,
// refetchOnWindowFocus: true,
// refetchOnReconnect: false
// });
// }

async function getProviderStatus(providerUri: string) {
if (!providerUri) return null;

Expand Down
4 changes: 2 additions & 2 deletions deploy-web/src/utils/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export class ApiUrlService {
return `${apiEndpoint}/akash/provider/${networkVersion}/providers`;
}
static providerList() {
return `${BASE_API_URL}/providerList`;
return `${BASE_API_URL}/providers`;
}
static providerDetail(owner: string) {
return `${BASE_API_URL}/providerDetail/${owner}`;
return `${BASE_API_URL}/providers/${owner}`;
}
static block(apiEndpoint: string, id: string) {
return `${apiEndpoint}/blocks/${id}`;
Expand Down

0 comments on commit e374a99

Please sign in to comment.