Skip to content

armgit / ente

Public Imported from GitHub
0

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

Conv

Manav Rathif85246c8d659
diff --git a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx
index a244fbd68c..ca4a0d272d 100644
--- a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx
+++ b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx
@@ -4,7 +4,7 @@ import { boxSeal } from "@/base/crypto";
import log from "@/base/log";
import type { Collection } from "@/media/collection";
import { photosDialogZIndex } from "@/new/photos/components/utils/z-index";
-import castGateway from "@/new/photos/services/cast";
+import castGateway, { revokeAllCastTokens } from "@/new/photos/services/cast";
import { loadCast } from "@/new/photos/utils/chromecast-sender";
import SingleInputForm, {
type SingleInputFormProps,
@@ -38,11 +38,18 @@ export const AlbumCastDialog: React.FC<AlbumCastDialogProps> = ({
const [browserCanCast, setBrowserCanCast] = useState(false);
- // Make API call to clear all previous sessions on component mount.
useEffect(() => {
- castGateway.revokeAllTokens();
-
- // Otherwise tsc complains about unknown property chrome.
+ // Make API call to clear all previous sessions (if any) on component
+ // mount so that the user can start a new session.
+ //
+ // This is usually not going to have any effect, so we don't need to
+ // wait for it to finish (or do anything specific if it fails).
+ void revokeAllCastTokens();
+
+ // Determine if Chromecast is supported by the current browser
+ // (effectively, only Chrome).
+ //
+ // Override, otherwise tsc complains about unknown property `chrome`.
// eslint-disable-next-line @typescript-eslint/dot-notation
setBrowserCanCast(typeof window["chrome"] !== "undefined");
}, []);
diff --git a/web/packages/new/photos/services/cast.ts b/web/packages/new/photos/services/cast.ts
index 76b92dcb4f..e145c96c1e 100644
--- a/web/packages/new/photos/services/cast.ts
+++ b/web/packages/new/photos/services/cast.ts
@@ -1,27 +1,20 @@
+import { authenticatedRequestHeaders } from "@/base/http";
import log from "@/base/log";
import { apiURL } from "@/base/origins";
import { ApiError } from "@ente/shared/error";
-import { getToken } from "@ente/shared/storage/localStorage/helpers";
import HTTPService from "@ente/shared/network/HTTPService";
+import { getToken } from "@ente/shared/storage/localStorage/helpers";
-class CastGateway {
- public async revokeAllTokens() {
- try {
- const token = getToken();
- await HTTPService.delete(
- await apiURL("/cast/revoke-all-tokens"),
- undefined,
- undefined,
- {
- "X-Auth-Token": token,
- },
- );
- } catch (e) {
- log.error("removeAllTokens failed", e);
- // swallow error
- }
- }
+/**
+ * Revoke all existing outstanding cast tokens for the current user on remote.
+ */
+export const revokeAllCastTokens = async () =>
+ fetch(await apiURL("/cast/revoke-all-tokens"), {
+ method: "DELETE",
+ headers: await authenticatedRequestHeaders(),
+ });
+class CastGateway {
public async getPublicKey(code: string): Promise<string> {
let resp;
try {