Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Assert a pong

Manav Rathi815666bbe7b1
diff --git a/web/packages/new/photos/components/DevSettings.tsx b/web/packages/new/photos/components/DevSettings.tsx
index e52a824512..c07290cd0e 100644
--- a/web/packages/new/photos/components/DevSettings.tsx
+++ b/web/packages/new/photos/components/DevSettings.tsx
@@ -13,6 +13,7 @@ import {
import { useFormik } from "formik";
import { t } from "i18next";
import React from "react";
+import { z } from "zod";
import { FocusVisibleButton } from "./FocusVisibleButton";
import { SlideTransition } from "./SlideTransition";
@@ -143,6 +144,12 @@ const updateAPIOrigin = async (origin: string) => {
const url = `${origin}/ping`;
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`);
+ const json = PingResponse.parse(await res.json());
+ if (json.message != "pong") throw new Error("Invalid response");
+
localStorage.setItem("apiOrigin", origin);
- return true;
};
+
+const PingResponse = z.object({
+ message: z.string().nullish(),
+});