mirror of
https://github.com/gosticks/web.git
synced 2026-07-04 16:10:15 +00:00
Move API type definitions to new api.d.ts file
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
@@ -16,7 +16,7 @@ import NavButton from "./NavButton";
|
||||
import NavDropdown from "./NavDropdown";
|
||||
import { StatusContext } from "./context";
|
||||
import { CancelablePromise, makeCancelable } from "../../util";
|
||||
import api, { ApiStatus, Status, StatusAction } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
import React from "react";
|
||||
import { PreferencesContext } from "./context";
|
||||
import { WebLayout } from "../../util/api";
|
||||
|
||||
/**
|
||||
* Update the web interface layout
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React, { ReactNode } from "react";
|
||||
import { WithAPIData } from "./WithAPIData";
|
||||
import api, { ApiPreferences, ApiStatus, Status } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
|
||||
export interface StatusContextType {
|
||||
status: Status;
|
||||
|
||||
@@ -13,7 +13,7 @@ import ReactDOM from "react-dom";
|
||||
import { Line } from "react-chartjs-2";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import { padNumber } from "../../util";
|
||||
import api, { ApiClientsGraph } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import ChartTooltip from "./ChartTooltip";
|
||||
import { WithAPIData } from "../common/WithAPIData";
|
||||
import { ChartDataSets, ChartOptions } from "chart.js";
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import React, { Component } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import { padNumber } from "../../util";
|
||||
import api, { ApiHistoryGraphItem } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import { WithAPIData } from "../common/WithAPIData";
|
||||
import { ChartData, ChartOptions } from "chart.js";
|
||||
import { Line } from "react-chartjs-2";
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import React, { Component, Fragment } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import { WithAPIData } from "../common/WithAPIData";
|
||||
import api, { ApiSummary } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
|
||||
export interface SummaryStatsProps {
|
||||
totalQueries: string;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import api, { ApiTopBlocked, ApiTopDomainItem } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import TopTable from "./TopTable";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import api, { ApiClient, ApiTopClients } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import TopTable from "./TopTable";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import api, { ApiTopDomainItem, ApiTopDomains } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import TopTable from "./TopTable";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
transformData,
|
||||
TranslatedClientsGraph
|
||||
} from "../ClientsGraph";
|
||||
import { ApiClientsGraph } from "../../../util/api";
|
||||
|
||||
const fakeData: ApiClientsGraph = {
|
||||
over_time: [
|
||||
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
transformData,
|
||||
TranslatedSummaryStats
|
||||
} from "../SummaryStats";
|
||||
import { ApiSummary } from "../../../util/api";
|
||||
|
||||
const tick = global.tick;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
import React from "react";
|
||||
import { generateRows, transformData } from "../TopBlocked";
|
||||
import { ApiTopBlocked } from "../../../util/api";
|
||||
|
||||
const fakeData: ApiTopBlocked = {
|
||||
top_domains: [
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
import React from "react";
|
||||
import { generateRows, transformData } from "../TopClients";
|
||||
import { ApiTopClients } from "../../../util/api";
|
||||
|
||||
const fakeData: ApiTopClients = {
|
||||
top_clients: [
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
import React from "react";
|
||||
import { generateRows, transformData } from "../TopDomains";
|
||||
import { ApiTopDomains } from "../../../util/api";
|
||||
|
||||
const fakeData: ApiTopDomains = {
|
||||
top_domains: [
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
makeCancelable,
|
||||
padNumber
|
||||
} from "../../util";
|
||||
import api, { ApiHistoryResponse, ApiQuery } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import "react-table/react-table.css";
|
||||
import "bootstrap-daterangepicker/daterangepicker.css";
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import React, { ChangeEvent, Component, FormEvent } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import { CancelablePromise, ignoreCancel, makeCancelable } from "../../util";
|
||||
import api, { ApiDhcpSettings, ApiResultResponse } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import {
|
||||
Button,
|
||||
Col,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import React, { Component, FormEvent } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import { CancelablePromise, ignoreCancel, makeCancelable } from "../../util";
|
||||
import api, { ApiDnsSettings, ApiResultResponse } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import DnsList from "./DnsList";
|
||||
import { Button, Col, Form, FormGroup } from "reactstrap";
|
||||
import ConditionalForwardingSettings, {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import api, { ApiFtlDbResponse } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import { WithAPIData } from "../common/WithAPIData";
|
||||
|
||||
export interface FTLInfoProps {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { Subtract, WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import api, { ApiNetworkSettings } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import { Col, Form, FormGroup, Input, Label } from "reactstrap";
|
||||
import { WithAPIData } from "../common/WithAPIData";
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import React, { ChangeEvent, Component, FormEvent } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import { CancelablePromise, ignoreCancel, makeCancelable } from "../../util";
|
||||
import api, { ApiPreferences, ApiResultResponse } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import Alert, { AlertType } from "../common/Alert";
|
||||
import { Button, Col, Form, FormGroup, Input, Label } from "reactstrap";
|
||||
import { PreferencesContext } from "../common/context";
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import React, { Component } from "react";
|
||||
import { WithNamespaces, withNamespaces } from "react-i18next";
|
||||
import api, { ApiVersions } from "../../util/api";
|
||||
import api from "../../util/api";
|
||||
import VersionCard from "./VersionCard";
|
||||
import { WithAPIData } from "../common/WithAPIData";
|
||||
|
||||
|
||||
198
src/types/api.d.ts
vendored
Normal file
198
src/types/api.d.ts
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
/* Pi-hole: A black hole for Internet advertisements
|
||||
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
* Network-wide ad blocking via your own hardware.
|
||||
*
|
||||
* Web Interface
|
||||
* Type definitions for API objects
|
||||
*
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
interface ApiQuery {
|
||||
timestamp: number;
|
||||
type: number;
|
||||
status: number;
|
||||
domain: string;
|
||||
client: string;
|
||||
dnssec: number;
|
||||
reply: number;
|
||||
response_time: number;
|
||||
}
|
||||
|
||||
interface ApiHistoryResponse {
|
||||
cursor: null | string;
|
||||
history: Array<ApiQuery>;
|
||||
}
|
||||
|
||||
interface ApiNetworkSettings {
|
||||
interface: string;
|
||||
ipv4_address: string;
|
||||
ipv6_address: string;
|
||||
hostname: string;
|
||||
}
|
||||
|
||||
interface ApiVersion {
|
||||
branch: string;
|
||||
hash: string;
|
||||
tag: string;
|
||||
}
|
||||
|
||||
interface ApiVersions {
|
||||
api: ApiVersion;
|
||||
core: ApiVersion;
|
||||
ftl: ApiVersion;
|
||||
web: ApiVersion;
|
||||
}
|
||||
|
||||
interface ApiDnsSettings {
|
||||
upstream_dns: Array<string>;
|
||||
options: {
|
||||
fqdn_required: boolean;
|
||||
bogus_priv: boolean;
|
||||
dnssec: boolean;
|
||||
listening_type: string;
|
||||
};
|
||||
conditional_forwarding: {
|
||||
enabled: boolean;
|
||||
router_ip: string;
|
||||
domain: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface ApiDhcpSettings {
|
||||
active: boolean;
|
||||
ip_start: string;
|
||||
ip_end: string;
|
||||
router_ip: string;
|
||||
lease_time: number;
|
||||
domain: string;
|
||||
ipv6_support: boolean;
|
||||
}
|
||||
|
||||
interface ApiFtlDbResponse {
|
||||
filesize: number;
|
||||
queries: number;
|
||||
sqlite_version: string;
|
||||
}
|
||||
|
||||
interface ApiSuccessResponse {
|
||||
status: "success";
|
||||
}
|
||||
|
||||
interface ApiError {
|
||||
key: string;
|
||||
message: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
interface ApiErrorResponse {
|
||||
error: ApiError;
|
||||
}
|
||||
|
||||
type ApiResultResponse = ApiSuccessResponse | ApiErrorResponse;
|
||||
|
||||
type WebLayout = "boxed" | "traditional";
|
||||
|
||||
interface ApiPreferences {
|
||||
layout: WebLayout;
|
||||
language: string;
|
||||
}
|
||||
|
||||
type Status = "enabled" | "disabled" | "unknown";
|
||||
type StatusAction = "enable" | "disable";
|
||||
|
||||
interface ApiStatus {
|
||||
status: Status;
|
||||
}
|
||||
|
||||
interface ApiClientsGraph {
|
||||
over_time: Array<ApiClientOverTime>;
|
||||
clients: Array<ApiClientGraphInfo>;
|
||||
}
|
||||
|
||||
interface ApiClientOverTime {
|
||||
timestamp: number;
|
||||
data: Array<number>;
|
||||
}
|
||||
|
||||
interface ApiClientGraphInfo {
|
||||
name: string;
|
||||
ip: string;
|
||||
}
|
||||
|
||||
interface ApiHistoryGraphItem {
|
||||
timestamp: number;
|
||||
total_queries: number;
|
||||
blocked_queries: number;
|
||||
}
|
||||
|
||||
interface ApiQueryType {
|
||||
name: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface ApiSummary {
|
||||
gravity_size: number;
|
||||
total_queries: {
|
||||
A: number;
|
||||
AAAA: number;
|
||||
ANY: number;
|
||||
SRV: number;
|
||||
SOA: number;
|
||||
PTR: number;
|
||||
TXT: number;
|
||||
[key: string]: number;
|
||||
};
|
||||
blocked_queries: number;
|
||||
percent_blocked: number;
|
||||
unique_domains: number;
|
||||
forwarded_queries: number;
|
||||
cached_queries: number;
|
||||
reply_types: {
|
||||
IP: number;
|
||||
CNAME: number;
|
||||
DOMAIN: number;
|
||||
NODATA: number;
|
||||
NXDOMAIN: number;
|
||||
[key: string]: number;
|
||||
};
|
||||
total_clients: number;
|
||||
active_clients: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
interface ApiUpstreams {
|
||||
upstreams: Array<{
|
||||
name: string;
|
||||
ip: string;
|
||||
count: number;
|
||||
}>;
|
||||
forwarded_queries: number;
|
||||
total_queries: number;
|
||||
}
|
||||
|
||||
interface ApiTopDomainItem {
|
||||
domain: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface ApiTopBlocked {
|
||||
top_domains: Array<ApiTopDomainItem>;
|
||||
blocked_queries: number;
|
||||
}
|
||||
|
||||
interface ApiTopDomains {
|
||||
top_domains: Array<ApiTopDomainItem>;
|
||||
total_queries: number;
|
||||
}
|
||||
|
||||
interface ApiTopClients {
|
||||
top_clients: Array<ApiClient>;
|
||||
total_queries: number;
|
||||
}
|
||||
|
||||
interface ApiClient {
|
||||
name: string;
|
||||
ip: string;
|
||||
count: number;
|
||||
}
|
||||
10
src/types/global.d.ts
vendored
10
src/types/global.d.ts
vendored
@@ -1,3 +1,13 @@
|
||||
/* Pi-hole: A black hole for Internet advertisements
|
||||
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
|
||||
* Network-wide ad blocking via your own hardware.
|
||||
*
|
||||
* Web Interface
|
||||
* Type definitions for the `global` variable
|
||||
*
|
||||
* This file is copyright under the latest version of the EUPL.
|
||||
* Please see LICENSE file for your rights under this license. */
|
||||
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
tick(): Promise<any>
|
||||
|
||||
189
src/util/api.tsx
189
src/util/api.tsx
@@ -11,195 +11,6 @@
|
||||
import http, { paramsToString } from "./http";
|
||||
import config from "../config";
|
||||
|
||||
export interface ApiQuery {
|
||||
timestamp: number;
|
||||
type: number;
|
||||
status: number;
|
||||
domain: string;
|
||||
client: string;
|
||||
dnssec: number;
|
||||
reply: number;
|
||||
response_time: number;
|
||||
}
|
||||
|
||||
export interface ApiHistoryResponse {
|
||||
cursor: null | string;
|
||||
history: Array<ApiQuery>;
|
||||
}
|
||||
|
||||
export interface ApiNetworkSettings {
|
||||
interface: string;
|
||||
ipv4_address: string;
|
||||
ipv6_address: string;
|
||||
hostname: string;
|
||||
}
|
||||
|
||||
export interface ApiVersion {
|
||||
branch: string;
|
||||
hash: string;
|
||||
tag: string;
|
||||
}
|
||||
|
||||
export interface ApiVersions {
|
||||
api: ApiVersion;
|
||||
core: ApiVersion;
|
||||
ftl: ApiVersion;
|
||||
web: ApiVersion;
|
||||
}
|
||||
|
||||
export interface ApiDnsSettings {
|
||||
upstream_dns: Array<string>;
|
||||
options: {
|
||||
fqdn_required: boolean;
|
||||
bogus_priv: boolean;
|
||||
dnssec: boolean;
|
||||
listening_type: string;
|
||||
};
|
||||
conditional_forwarding: {
|
||||
enabled: boolean;
|
||||
router_ip: string;
|
||||
domain: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ApiDhcpSettings {
|
||||
active: boolean;
|
||||
ip_start: string;
|
||||
ip_end: string;
|
||||
router_ip: string;
|
||||
lease_time: number;
|
||||
domain: string;
|
||||
ipv6_support: boolean;
|
||||
}
|
||||
|
||||
export interface ApiFtlDbResponse {
|
||||
filesize: number;
|
||||
queries: number;
|
||||
sqlite_version: string;
|
||||
}
|
||||
|
||||
export interface ApiSuccessResponse {
|
||||
status: "success";
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
key: string;
|
||||
message: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
export interface ApiErrorResponse {
|
||||
error: ApiError;
|
||||
}
|
||||
|
||||
export type ApiResultResponse = ApiSuccessResponse | ApiErrorResponse;
|
||||
|
||||
export type WebLayout = "boxed" | "traditional";
|
||||
|
||||
export interface ApiPreferences {
|
||||
layout: WebLayout;
|
||||
language: string;
|
||||
}
|
||||
|
||||
export type Status = "enabled" | "disabled" | "unknown";
|
||||
export type StatusAction = "enable" | "disable";
|
||||
|
||||
export interface ApiStatus {
|
||||
status: Status;
|
||||
}
|
||||
|
||||
export interface ApiClientsGraph {
|
||||
over_time: Array<ApiClientOverTime>;
|
||||
clients: Array<ApiClientGraphInfo>;
|
||||
}
|
||||
|
||||
export interface ApiClientOverTime {
|
||||
timestamp: number;
|
||||
data: Array<number>;
|
||||
}
|
||||
|
||||
export interface ApiClientGraphInfo {
|
||||
name: string;
|
||||
ip: string;
|
||||
}
|
||||
|
||||
export interface ApiHistoryGraphItem {
|
||||
timestamp: number;
|
||||
total_queries: number;
|
||||
blocked_queries: number;
|
||||
}
|
||||
|
||||
export interface ApiQueryType {
|
||||
name: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface ApiSummary {
|
||||
gravity_size: number;
|
||||
total_queries: {
|
||||
A: number;
|
||||
AAAA: number;
|
||||
ANY: number;
|
||||
SRV: number;
|
||||
SOA: number;
|
||||
PTR: number;
|
||||
TXT: number;
|
||||
[key: string]: number;
|
||||
};
|
||||
blocked_queries: number;
|
||||
percent_blocked: number;
|
||||
unique_domains: number;
|
||||
forwarded_queries: number;
|
||||
cached_queries: number;
|
||||
reply_types: {
|
||||
IP: number;
|
||||
CNAME: number;
|
||||
DOMAIN: number;
|
||||
NODATA: number;
|
||||
NXDOMAIN: number;
|
||||
[key: string]: number;
|
||||
};
|
||||
total_clients: number;
|
||||
active_clients: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface ApiUpstreams {
|
||||
upstreams: Array<{
|
||||
name: string;
|
||||
ip: string;
|
||||
count: number;
|
||||
}>;
|
||||
forwarded_queries: number;
|
||||
total_queries: number;
|
||||
}
|
||||
|
||||
export interface ApiTopDomainItem {
|
||||
domain: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface ApiTopBlocked {
|
||||
top_domains: Array<ApiTopDomainItem>;
|
||||
blocked_queries: number;
|
||||
}
|
||||
|
||||
export interface ApiTopDomains {
|
||||
top_domains: Array<ApiTopDomainItem>;
|
||||
total_queries: number;
|
||||
}
|
||||
|
||||
export interface ApiTopClients {
|
||||
top_clients: Array<ApiClient>;
|
||||
total_queries: number;
|
||||
}
|
||||
|
||||
export interface ApiClient {
|
||||
name: string;
|
||||
ip: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export default {
|
||||
loggedIn: false,
|
||||
authenticate(key: string) {
|
||||
|
||||
Reference in New Issue
Block a user