Skip to content

Commit

Permalink
frontend glue code
Browse files Browse the repository at this point in the history
  • Loading branch information
findus committed Nov 12, 2024
1 parent c61f93c commit da3481d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/index/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type (
}

ClientConfig struct {
AutoPrependLimit bool
AutoInsertLimitToQuery bool
}

indexReleaser []*index.Reader
Expand Down
12 changes: 11 additions & 1 deletion web/src/apiClient.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated type guards for "apiClient.ts".
* WARNING: Do not manually change this file.
*/
import { Error, SearchResult, SearchResponse, StreamData, Statistics, PcapsResponse, ConvertersResponse, ProcessStderr, PcapOverIPResponse, TagsResponse, GraphResponse } from "./apiClient";
import { Error, SearchResult, SearchResponse, StreamData, Statistics, PcapsResponse, ConvertersResponse, ProcessStderr, PcapOverIPResponse, TagsResponse, GraphResponse, ClientConfig } from "./apiClient";

export function isError(obj: unknown): obj is Error {
const typedObj = obj as Error
Expand Down Expand Up @@ -133,6 +133,16 @@ export function isStatistics(obj: unknown): obj is Statistics {
)
}

export function isClientConfig(obj: unknown): obj is ClientConfig {
const typedObj = obj as ClientConfig
return (
(typedObj !== null &&
typeof typedObj === "object" ||
typeof typedObj === "function") &&
typeof typedObj["AutoInsertLimitToQuery"] === "boolean"
)
}

export function isPcapsResponse(obj: unknown): obj is PcapsResponse {
const typedObj = obj as PcapsResponse
return (
Expand Down
9 changes: 9 additions & 0 deletions web/src/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from "axios";
import type { Base64, DateTimeString } from "@/types/common";
import {
isClientConfig,
isConvertersResponse,
isGraphResponse,
isPcapOverIPResponse,
Expand Down Expand Up @@ -82,6 +83,11 @@ export type Statistics = {
ConverterJobRunning: boolean;
};

/** @see {isClientConfig} ts-auto-guard:type-guard */
export type ClientConfig = {
AutoInsertLimitToQuery: boolean;
};

export type PcapInfo = {
Filename: string;
Filesize: number;
Expand Down Expand Up @@ -179,6 +185,9 @@ const APIClient = {
async getStatus() {
return this.performGuarded("get", `/status.json`, isStatistics);
},
async getClientConfig() {
return this.performGuarded("get", `/clientconfig.json`, isClientConfig);
},
async getPcaps() {
return this.performGuarded("get", `/pcaps.json`, isPcapsResponse);
},
Expand Down
8 changes: 8 additions & 0 deletions web/src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import APIClient, {
PcapOverIPEndpoint,
Statistics,
TagInfo,
ClientConfig,
} from "@/apiClient";

interface State {
status: Statistics | null;
clientConfig: ClientConfig | null;
pcaps: PcapInfo[] | null;
tags: TagInfo[] | null;
converters: ConverterStatistics[] | null;
Expand All @@ -23,6 +25,7 @@ export const useRootStore = defineStore("root", {
state: (): State => {
setupWebsocket();
return {
clientConfig: null,
status: null,
pcaps: null,
tags: null,
Expand Down Expand Up @@ -76,6 +79,11 @@ export const useRootStore = defineStore("root", {
}
}
},
async updateClientConfig() {
return APIClient.getClientConfig()
.then((data) => (this.clientConfig = data))
.catch(handleAxiosDefaultError);
},
async updateStatus() {
return APIClient.getStatus()
.then((data) => (this.status = data))
Expand Down

0 comments on commit da3481d

Please sign in to comment.