Dough Git

commit

Add location

commit
5e58df8435744886814eba7a58dae444a24f6c87
author
Clove Twilight <[email protected]>
date
2026-07-16 08:02

diff --git a/src/system/routes/devices.ts b/src/system/routes/devices.ts
index b7b0910..a558daa 100644
--- a/src/system/routes/devices.ts
+++ b/src/system/routes/devices.ts
@@ -19,6 +19,7 @@
  *   wifi     — the network name (1–128 chars); pass 0 to clear it (stored as null)
  *   watch    — 1 (connected) or 0 (not connected)
  *   airpods  — 1 (connected) or 0 (not connected)
+ *   location — the place name (1–128 chars); pass 0 to clear it (stored as null)
  */
 
 import { Hono } from "hono";
@@ -44,7 +45,7 @@ deviceRoutes.post("/", verifyBatteryAccess, async (c) => {
     return c.json({ detail: "Query param 'device' must be a string between 1 and 64 characters" }, 422);
   }
 
-  const patch: { level?: number; charging?: boolean; lowPowerMode?: boolean; wifi?: string | null; watch?: boolean; airpods?: boolean } = {};
+  const patch: { level?: number; charging?: boolean; lowPowerMode?: boolean; wifi?: string | null; watch?: boolean; airpods?: boolean; location?: string | null } = {};
 
   const levelRaw = c.req.query("level");
   if (levelRaw !== undefined) {
@@ -91,6 +92,18 @@ deviceRoutes.post("/", verifyBatteryAccess, async (c) => {
   }
   if (airpods !== undefined) patch.airpods = airpods;
 
+  const location = c.req.query("location");
+  if (location !== undefined) {
+    if (location === "0") {
+      patch.location = null;
+    } else {
+      if (location.length > 128) {
+        return c.json({ detail: "Query param 'location' must be 128 characters or fewer" }, 422);
+      }
+      patch.location = location;
+    }
+  }
+
   const record = await setDeviceLevel(device, patch);
   broadcastDeviceUpdate(record);
   return c.json({ success: true, ...record });
diff --git a/src/system/services/devices.ts b/src/system/services/devices.ts
index cc5b7ab..6c056d6 100644
--- a/src/system/services/devices.ts
+++ b/src/system/services/devices.ts
@@ -15,11 +15,12 @@ interface DeviceRecord {
   wifi?: string | null;
   watch?: boolean;
   airpods?: boolean;
+  location?: string | null;
   updated_at: string;
 }
 
 /** Fields a caller may set. All optional — only provided fields are updated. */
-type DevicePatch = Pick<DeviceRecord, "level" | "charging" | "lowPowerMode" | "wifi" | "watch" | "airpods">;
+type DevicePatch = Pick<DeviceRecord, "level" | "charging" | "lowPowerMode" | "wifi" | "watch" | "airpods" | "location">;
 
 type DevicesMap = Record<string, DeviceRecord>;
 
@@ -54,6 +55,7 @@ export async function setDeviceLevel(
     ...(patch.wifi !== undefined ? { wifi: patch.wifi } : {}),
     ...(patch.watch !== undefined ? { watch: patch.watch } : {}),
     ...(patch.airpods !== undefined ? { airpods: patch.airpods } : {}),
+    ...(patch.location !== undefined ? { location: patch.location } : {}),
     updated_at: new Date().toISOString(),
   };