refactor: add request handlers for centralized cached requests (#1504)
* feat: add object base64 hash method * chore: add script to add package * feat: add request-handler package * wip: add request handlers for all jobs and widget api procedures * wip: remove errors shown in logs, add missing decryption for secrets in cached-request-job-handler * wip: highly improve request handler, add request handlers for calendar, media-server, indexer-manager and more, add support for multiple inputs from job handler creator * refactor: move media-server requests to request-handler, add invalidation logic for dns-hole and media requests * refactor: remove unused integration item middleware * feat: add invalidation to switch entity action of smart-home * fix: lint issues * chore: use integration-kind-by-category instead of union for request-handlers * fix: build not working for tasks and websocket * refactor: add more logs * refactor: readd timestamp logic for diconnect status * fix: lint and typecheck issue * chore: address pull request feedback
This commit is contained in:
@@ -21,3 +21,20 @@ export const useTimeAgo = (timestamp: Date) => {
|
||||
|
||||
return timeAgo;
|
||||
};
|
||||
|
||||
export const useIntegrationConnected = (updatedAt: Date, { timeout = 30000 }) => {
|
||||
const [connected, setConnected] = useState(Math.abs(dayjs(updatedAt).diff()) < timeout);
|
||||
|
||||
useEffect(() => {
|
||||
setConnected(Math.abs(dayjs(updatedAt).diff()) < timeout);
|
||||
|
||||
const delayUntilTimeout = timeout - Math.abs(dayjs(updatedAt).diff());
|
||||
const timeoutRef = setTimeout(() => {
|
||||
setConnected(false);
|
||||
}, delayUntilTimeout);
|
||||
|
||||
return () => clearTimeout(timeoutRef);
|
||||
}, [updatedAt, timeout]);
|
||||
|
||||
return connected;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { hashKey } from "@tanstack/query-core";
|
||||
|
||||
export function objectKeys<O extends object>(obj: O): (keyof O)[] {
|
||||
return Object.keys(obj) as (keyof O)[];
|
||||
}
|
||||
@@ -7,3 +9,7 @@ type Entries<T> = {
|
||||
}[keyof T][];
|
||||
|
||||
export const objectEntries = <T extends object>(obj: T) => Object.entries(obj) as Entries<T>;
|
||||
|
||||
export const hashObjectBase64 = (obj: object) => {
|
||||
return Buffer.from(hashKey([obj])).toString("base64");
|
||||
};
|
||||
|
||||
@@ -9,3 +9,5 @@ export type Modify<T, R extends Partial<Record<keyof T, unknown>>> = {
|
||||
export type RemoveReadonly<T> = {
|
||||
-readonly [P in keyof T]: T[P] extends Record<string, unknown> ? RemoveReadonly<T[P]> : T[P];
|
||||
};
|
||||
|
||||
export type MaybeArray<T> = T | T[];
|
||||
|
||||
Reference in New Issue
Block a user