Normalize server feature set

This commit is contained in:
jeffvli 2024-03-03 22:15:49 -08:00
parent dae2f9bd0a
commit f1f6ccfd02
9 changed files with 63 additions and 30 deletions

View file

@ -3,6 +3,7 @@ import { z } from 'zod';
import { toast } from '/@/renderer/components';
import { useAuthStore } from '/@/renderer/store';
import { ServerListItem } from '/@/renderer/api/types';
import { ServerFeature } from '/@/renderer/api/features.types';
// Since ts-rest client returns a strict response type, we need to add the headers to the body object
export const resultWithHeaders = <ItemType extends z.ZodTypeAny>(itemSchema: ItemType) => {
@ -39,19 +40,10 @@ export const authenticationFailure = (currentServer: ServerListItem | null) => {
}
};
export const hasFeature = (
server: ServerListItem | null,
feature: string,
version = 1,
): boolean => {
export const hasFeature = (server: ServerListItem | null, feature: ServerFeature): boolean => {
if (!server || !server.features) {
return false;
}
const versions = server.features[feature];
if (!versions || versions.length === 0) {
return false;
}
return versions.includes(version);
return server.features[feature];
};