mirror of
https://github.com/skooner-k8s/skooner.git
synced 2026-08-28 19:27:15 +00:00
Merge pull request #211 from tianni4104/master
make protobuff the default method
This commit is contained in:
@@ -2,7 +2,7 @@ import _ from 'lodash';
|
||||
import {getToken, logout} from './auth';
|
||||
import log from '../utils/log';
|
||||
import {ApiItem} from '../utils/types';
|
||||
import {isProtoEligible, isProtoEnabled, protoParser} from '../utils/protoHelpers';
|
||||
import {isProtoEligible, protoParser} from '../utils/protoHelpers';
|
||||
|
||||
type StreamCallback<T> = (data: T) => void;
|
||||
type ErrorCallback = (err: Error) => void;
|
||||
@@ -62,7 +62,7 @@ async function requestInner(path: string, params?: any, autoLogoutOnAuthError =
|
||||
}
|
||||
|
||||
export async function request(path: string, params?: any, autoLogoutOnAuthError = true) {
|
||||
if (isProtoEligible(path) && isProtoEnabled()) {
|
||||
if (isProtoEligible(path)) {
|
||||
return requestProto(path, params, autoLogoutOnAuthError);
|
||||
}
|
||||
return requestJson(path, params, autoLogoutOnAuthError);
|
||||
|
||||
@@ -18,36 +18,36 @@ export const kindMap: {
|
||||
| typeof EventList
|
||||
| typeof NodeList
|
||||
| typeof PodList,
|
||||
path: string
|
||||
paths: string[]
|
||||
}
|
||||
} = {
|
||||
NodeMetrics: {
|
||||
proto: NodeMetrics,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/node',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/node'],
|
||||
},
|
||||
NodeMetricsList: {
|
||||
proto: NodeMetricsList,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/nodes',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/nodes'],
|
||||
},
|
||||
PodMetrics: {
|
||||
proto: PodMetrics,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/pod',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/pod'],
|
||||
},
|
||||
PodMetricsList: {
|
||||
proto: PodMetricsList,
|
||||
path: '/apis/metrics.k8s.io/v1beta1/pods',
|
||||
paths: ['/apis/metrics.k8s.io/v1beta1/pods'],
|
||||
},
|
||||
EventList: {
|
||||
proto: EventList,
|
||||
path: 'api/v1/events',
|
||||
paths: ['api/v1/events'],
|
||||
},
|
||||
NodeList: {
|
||||
proto: NodeList,
|
||||
path: 'api/v1/nodes',
|
||||
paths: ['api/v1/nodes'],
|
||||
},
|
||||
PodList: {
|
||||
proto: PodList,
|
||||
path: 'api/v1/pods',
|
||||
paths: ['api/v1/pods', 'v1beta1/namespaces/kube-system/pods', 'v1/namespaces/kube-system/pods'],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -67,23 +67,11 @@ export function protoParser(raw: Uint8Array) {
|
||||
return {};
|
||||
}
|
||||
|
||||
export function isProtoEnabled(): boolean {
|
||||
return window.localStorage.getItem('protoEnabled') === 'true';
|
||||
}
|
||||
|
||||
export function isProtoEligible(url: string) {
|
||||
for (const value of Object.values(kindMap)) {
|
||||
if (url.includes(value.path)) {
|
||||
if (value.paths.some(path => url.includes(path))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function enableProto(): void {
|
||||
window.localStorage.setItem('protoEnabled', 'true');
|
||||
}
|
||||
|
||||
export function disableProto(): void {
|
||||
window.localStorage.setItem('protoEnabled', 'false');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user