mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
import axios from '@/portainer/services/axios';
|
|
import { ServiceId } from '@/react/docker/services/types';
|
|
import { ContainerId } from '@/react/docker/containers/types';
|
|
|
|
import { ImageStatus, ResourceID, ResourceType } from './types';
|
|
|
|
export function useImageNotification(
|
|
environmentId: number,
|
|
resourceId: ResourceID,
|
|
resourceType: ResourceType,
|
|
nodeName: string,
|
|
enabled = false
|
|
) {
|
|
return useQuery(
|
|
[
|
|
'environments',
|
|
environmentId,
|
|
'docker',
|
|
'images',
|
|
resourceType,
|
|
resourceId,
|
|
'status',
|
|
],
|
|
() =>
|
|
resourceType === ResourceType.SERVICE
|
|
? getServiceImagesStatus(environmentId, resourceId)
|
|
: getContainerImagesStatus(environmentId, resourceId, nodeName),
|
|
{
|
|
enabled,
|
|
}
|
|
);
|
|
}
|
|
|
|
async function getContainerImagesStatus(
|
|
environmentId: EnvironmentId,
|
|
containerID: ContainerId,
|
|
nodeName: string
|
|
) {
|
|
try {
|
|
let headers = {};
|
|
if (nodeName !== '') {
|
|
headers = { 'X-PortainerAgent-Target': nodeName };
|
|
}
|
|
const { data } = await axios.get<ImageStatus>(
|
|
`/docker/${environmentId}/containers/${containerID}/image_status`,
|
|
{ headers }
|
|
);
|
|
return data;
|
|
} catch (e) {
|
|
return {
|
|
Status: 'unknown',
|
|
Message: `Unable to retrieve image status for container: ${containerID}`,
|
|
};
|
|
}
|
|
}
|
|
|
|
async function getServiceImagesStatus(
|
|
environmentId: EnvironmentId,
|
|
serviceID: ServiceId
|
|
) {
|
|
try {
|
|
const { data } = await axios.get<ImageStatus>(
|
|
`/docker/${environmentId}/services/${serviceID}/image_status`
|
|
);
|
|
return data;
|
|
} catch (e) {
|
|
return {
|
|
Status: 'unknown',
|
|
Message: `Unable to retrieve image status for service: ${serviceID}`,
|
|
};
|
|
}
|
|
}
|