diff options
| author | JustZvan <justzvan@justzvan.xyz> | 2026-02-06 13:22:33 +0100 |
|---|---|---|
| committer | JustZvan <justzvan@justzvan.xyz> | 2026-02-06 13:22:33 +0100 |
| commit | 7eb8ccae48b0cc18a9dcaa9c3626a02df8e6d919 (patch) | |
| tree | 57b7dd06ac9aa7053c671d916f7183e3b4fa9410 /api/controls.ts | |
feat: initial commit!
Diffstat (limited to 'api/controls.ts')
| -rw-r--r-- | api/controls.ts | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/api/controls.ts b/api/controls.ts new file mode 100644 index 0000000..53db7a1 --- /dev/null +++ b/api/controls.ts @@ -0,0 +1,101 @@ +import { apiClient } from "./client"; +import { ControlsData, SafetyControl } from "./types"; + +export async function getControlsData(): Promise<ControlsData> { + const deviceId = apiClient.getSelectedDeviceId(); + + if (!deviceId) { + // Return default controls if no device selected + return { + safetyControls: getDefaultControls(), + }; + } + + try { + const response = await apiClient.get<{ + success: boolean; + safetyControls: SafetyControl[]; + }>(`/parent/controls/${deviceId}`); + + return { + safetyControls: response.safetyControls, + }; + } catch (e) { + console.error("Failed to fetch controls data", e); + return { + safetyControls: getDefaultControls(), + }; + } +} + +export async function updateSafetyControl( + key: string, + value: boolean +): Promise<void> { + const deviceId = apiClient.getSelectedDeviceId(); + + if (!deviceId) { + console.warn("No device selected, cannot update control"); + return; + } + + try { + await apiClient.post(`/parent/controls/${deviceId}`, { key, value }); + } catch (e) { + console.error(`Failed to update ${key}`, e); + throw e; + } +} + +function getDefaultControls(): SafetyControl[] { + return [ + { + key: "disable_buddy", + title: "Disable Buddy", + description: "Temporarily disable Buddy", + defaultValue: false, + }, + { + key: "adult_sites", + title: "Adult sites", + description: "Block adult websites.", + defaultValue: true, + }, + { + key: "family_link_anti_circumvention", + title: "Anti-Circumvention", + description: "Prevent disabling of Family Link protections.", + defaultValue: false, + }, + { + key: "filtering", + title: "Content filtering", + description: "Block unsafe or adult content.", + defaultValue: true, + }, + { + key: "new_people", + title: "New contact alerts", + description: "Get notified when your child chats with someone new.", + defaultValue: true, + }, + { + key: "block_strangers", + title: "Block communications with strangers", + description: "Block or scan communications with strangers.", + defaultValue: false, + }, + { + key: "notify_dangerous_messages", + title: "Dangerous messages notifications", + description: "Notify when messages are potentially dangerous.", + defaultValue: true, + }, + { + key: "notify_new_contact_added", + title: "New contact added notifications", + description: "Notify when a new contact is added.", + defaultValue: true, + }, + ]; +} |