Skip to content

armgit / ente

Public Imported from GitHub
0

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

more

Manav Rathi94f4dcb9beeb
diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.ts
index 859dd9abf7..12aeb485df 100644
--- a/web/apps/accounts/src/services/passkey.ts
+++ b/web/apps/accounts/src/services/passkey.ts
@@ -1,5 +1,5 @@
import { isDevBuild } from "@/next/env";
-import { apiOrigin, apiURL } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { clientPackageName } from "@/next/types/app";
import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";
import { ensure } from "@/utils/ensure";
@@ -82,7 +82,7 @@ export const renamePasskey = async (
name: string,
) => {
const params = new URLSearchParams({ friendlyName: name });
- const url = `${apiOrigin()}/passkeys/${id}`;
+ const url = await apiURL(`passkeys/${id}`);
const res = await fetch(`${url}?${params.toString()}`, {
method: "PATCH",
headers: accountsAuthenticatedRequestHeaders(token),
@@ -98,7 +98,7 @@ export const renamePasskey = async (
* @param id The `id` of the existing passkey to delete.
*/
export const deletePasskey = async (token: string, id: string) => {
- const url = `${apiOrigin()}/passkeys/${id}`;
+ const url = await apiURL(`passkeys/${id}`);
const res = await fetch(url, {
method: "DELETE",
headers: accountsAuthenticatedRequestHeaders(token),
@@ -149,7 +149,7 @@ interface BeginPasskeyRegistrationResponse {
}
const beginPasskeyRegistration = async (token: string) => {
- const url = `${apiOrigin()}/passkeys/registration/begin`;
+ const url = await apiURL("passkeys/registration/begin");
const res = await fetch(url, {
method: "POST",
headers: accountsAuthenticatedRequestHeaders(token),
@@ -293,7 +293,7 @@ const finishPasskeyRegistration = async ({
const transports = attestationResponse.getTransports();
const params = new URLSearchParams({ friendlyName, sessionID });
- const url = `${apiOrigin()}/passkeys/registration/finish`;
+ const url = await apiURL("passkeys/registration/finish");
const res = await fetch(`${url}?${params.toString()}`, {
method: "POST",
headers: accountsAuthenticatedRequestHeaders(token),
@@ -414,7 +414,7 @@ export const passkeySessionAlreadyClaimedErrorMessage =
export const beginPasskeyAuthentication = async (
passkeySessionID: string,
): Promise<BeginPasskeyAuthenticationResponse> => {
- const url = `${apiOrigin()}/users/two-factor/passkeys/begin`;
+ const url = await apiURL("users/two-factor/passkeys/begin");
const res = await fetch(url, {
method: "POST",
body: JSON.stringify({ sessionID: passkeySessionID }),
@@ -504,7 +504,7 @@ export const finishPasskeyAuthentication = async ({
ceremonySessionID,
clientPackage,
});
- const url = `${apiOrigin()}/users/two-factor/passkeys/finish`;
+ const url = await apiURL("users/two-factor/passkeys/finish");
const res = await fetch(`${url}?${params.toString()}`, {
method: "POST",
headers: {
diff --git a/web/packages/accounts/api/srp.ts b/web/packages/accounts/api/srp.ts
index d221309f05..068f1732fd 100644
--- a/web/packages/accounts/api/srp.ts
+++ b/web/packages/accounts/api/srp.ts
@@ -1,5 +1,5 @@
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import type {
CompleteSRPSetupRequest,
CompleteSRPSetupResponse,
@@ -21,7 +21,7 @@ export const getSRPAttributes = async (
): Promise<SRPAttributes | null> => {
try {
const resp = await HTTPService.get(
- `${apiOrigin()}/users/srp/attributes`,
+ await apiURL("users/srp/attributes"),
{
email,
},
@@ -39,7 +39,7 @@ export const startSRPSetup = async (
): Promise<SetupSRPResponse> => {
try {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/srp/setup`,
+ await apiURL("users/srp/setup"),
setupSRPRequest,
undefined,
{
@@ -60,7 +60,7 @@ export const completeSRPSetup = async (
) => {
try {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/srp/complete`,
+ await apiURL("users/srp/complete"),
completeSRPSetupRequest,
undefined,
{
@@ -77,7 +77,7 @@ export const completeSRPSetup = async (
export const createSRPSession = async (srpUserID: string, srpA: string) => {
try {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/srp/create-session`,
+ await apiURL("users/srp/create-session"),
{
srpUserID,
srpA,
@@ -97,7 +97,7 @@ export const verifySRPSession = async (
) => {
try {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/srp/verify-session`,
+ await apiURL("users/srp/verify-session"),
{
sessionID,
srpUserID,
@@ -125,7 +125,7 @@ export const updateSRPAndKeys = async (
): Promise<UpdateSRPAndKeysResponse> => {
try {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/srp/update`,
+ await apiURL("users/srp/update"),
updateSRPAndKeyRequest,
undefined,
{
diff --git a/web/packages/accounts/api/user.ts b/web/packages/accounts/api/user.ts
index 3303778730..ec04dd28d3 100644
--- a/web/packages/accounts/api/user.ts
+++ b/web/packages/accounts/api/user.ts
@@ -1,4 +1,4 @@
-import { apiOrigin } from "@/next/origins";
+import { apiOrigin, apiURL } from "@/next/origins";
import type { AppName } from "@/next/types/app";
import type {
RecoveryKey,
@@ -14,25 +14,32 @@ import { getToken } from "@ente/shared/storage/localStorage/helpers";
import type { KeyAttributes } from "@ente/shared/user/types";
import { HttpStatusCode } from "axios";
-export const sendOtt = (appName: AppName, email: string) => {
- return HTTPService.post(`${apiOrigin()}/users/ott`, {
+export const sendOtt = async (appName: AppName, email: string) => {
+ return HTTPService.post(await apiURL("users/ott"), {
email,
client: appName == "auth" ? "totp" : "web",
});
};
-export const verifyOtt = (email: string, ott: string, referral: string) => {
+export const verifyOtt = async (
+ email: string,
+ ott: string,
+ referral: string,
+) => {
const cleanedReferral = `web:${referral?.trim() || ""}`;
- return HTTPService.post(`${apiOrigin()}/users/verify-email`, {
+ return HTTPService.post(await apiURL("users/verify-email"), {
email,
ott,
source: cleanedReferral,
});
};
-export const putAttributes = (token: string, keyAttributes: KeyAttributes) =>
+export const putAttributes = async (
+ token: string,
+ keyAttributes: KeyAttributes,
+) =>
HTTPService.put(
- `${apiOrigin()}/users/attributes`,
+ await apiURL("users/attributes"),
{ keyAttributes },
undefined,
{
@@ -43,7 +50,7 @@ export const putAttributes = (token: string, keyAttributes: KeyAttributes) =>
export const logout = async () => {
try {
const token = getToken();
- await HTTPService.post(`${apiOrigin()}/users/logout`, null, undefined, {
+ await HTTPService.post(await apiURL("users/logout"), null, undefined, {
"X-Auth-Token": token,
});
} catch (e) {
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index 56b0e78ba4..84453b6b47 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -1,6 +1,6 @@
import { clientPackageHeaderIfPresent } from "@/next/http";
import log from "@/next/log";
-import { accountsAppOrigin, apiOrigin } from "@/next/origins";
+import { accountsAppOrigin, apiURL } from "@/next/origins";
import type { AppName } from "@/next/types/app";
import { clientPackageName } from "@/next/types/app";
import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";
@@ -139,7 +139,7 @@ export const isPasskeyRecoveryEnabled = async () => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/two-factor/recovery-status`,
+ await apiURL("users/two-factor/recovery-status"),
{},
{
"X-Auth-Token": token,
@@ -166,7 +166,7 @@ const configurePasskeyRecovery = async (
const token = getToken();
const resp = await HTTPService.post(
- `${apiOrigin()}/users/two-factor/passkeys/configure-recovery`,
+ await apiURL("users/two-factor/passkeys/configure-recovery"),
{
secret,
userSecretCipher,
@@ -196,7 +196,7 @@ const getAccountsToken = async () => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/accounts-token`,
+ await apiURL("users/accounts-token"),
undefined,
{
"X-Auth-Token": token,
@@ -234,7 +234,7 @@ export const passkeySessionExpiredErrorMessage = "Passkey session has expired";
export const checkPasskeyVerificationStatus = async (
sessionID: string,
): Promise<TwoFactorAuthorizationResponse | undefined> => {
- const url = `${apiOrigin()}/users/two-factor/passkeys/get-token`;
+ const url = await apiURL("users/two-factor/passkeys/get-token");
const params = new URLSearchParams({ sessionID });
const res = await fetch(`${url}?${params.toString()}`, {
headers: clientPackageHeaderIfPresent(),
diff --git a/web/packages/accounts/services/session.ts b/web/packages/accounts/services/session.ts
index 3780f8b1e0..65493cdb26 100644
--- a/web/packages/accounts/services/session.ts
+++ b/web/packages/accounts/services/session.ts
@@ -1,6 +1,6 @@
import { authenticatedRequestHeaders } from "@/next/http";
import { ensureLocalUser } from "@/next/local-user";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { ensure } from "@/utils/ensure";
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
import type { KeyAttributes } from "@ente/shared/user/types";
@@ -62,7 +62,7 @@ type SessionValidity =
* subsequently.
*/
export const checkSessionValidity = async (): Promise<SessionValidity> => {
- const url = `${apiOrigin()}/users/session-validity/v2`;
+ const url = await apiURL("users/session-validity/v2");
const res = await fetch(url, {
headers: authenticatedRequestHeaders(),
});
diff --git a/web/packages/new/photos/services/embedding.ts b/web/packages/new/photos/services/embedding.ts
index e20515e0a9..64f21268c0 100644
--- a/web/packages/new/photos/services/embedding.ts
+++ b/web/packages/new/photos/services/embedding.ts
@@ -1,5 +1,5 @@
import { authenticatedRequestHeaders } from "@/next/http";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { nullToUndefined } from "@/utils/transform";
// import ComlinkCryptoWorker from "@ente/shared/crypto";
import { z } from "zod";
@@ -166,7 +166,7 @@ const getEmbeddingsDiff = async (
sinceTime: `${sinceTime}`,
limit: `${diffLimit}`,
});
- const url = `${apiOrigin()}/embeddings/diff`;
+ const url = await apiURL("embeddings/diff");
const res = await fetch(`${url}?${params.toString()}`, {
headers: authenticatedRequestHeaders(),
});
diff --git a/web/packages/new/photos/services/feature-flags.ts b/web/packages/new/photos/services/feature-flags.ts
index 8bef610f88..a29dc87506 100644
--- a/web/packages/new/photos/services/feature-flags.ts
+++ b/web/packages/new/photos/services/feature-flags.ts
@@ -2,7 +2,7 @@ import { isDevBuild } from "@/next/env";
import { authenticatedRequestHeaders } from "@/next/http";
import { localUser } from "@/next/local-user";
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { nullToUndefined } from "@/utils/transform";
import { z } from "zod";
@@ -65,7 +65,7 @@ const fetchAndSaveFeatureFlags = () =>
.then(saveFlagJSONString);
const fetchFeatureFlags = async () => {
- const url = `${apiOrigin()}/remote-store/feature-flags`;
+ const url = await apiURL("remote-store/feature-flags");
const res = await fetch(url, {
headers: authenticatedRequestHeaders(),
});
diff --git a/web/packages/shared/network/cast.ts b/web/packages/shared/network/cast.ts
index 7b2af75907..551d2ad3e3 100644
--- a/web/packages/shared/network/cast.ts
+++ b/web/packages/shared/network/cast.ts
@@ -1,5 +1,5 @@
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { ApiError } from "../error";
import { getToken } from "../storage/localStorage/helpers";
import HTTPService from "./HTTPService";
@@ -11,7 +11,7 @@ class CastGateway {
let resp;
try {
resp = await HTTPService.get(
- `${apiOrigin()}/cast/cast-data/${code}`,
+ await apiURL(`cast/cast-data/${code}`),
);
} catch (e) {
log.error("failed to getCastData", e);
@@ -24,7 +24,7 @@ class CastGateway {
try {
const token = getToken();
await HTTPService.delete(
- apiOrigin() + "/cast/revoke-all-tokens/",
+ await apiURL("cast/revoke-all-tokens"),
undefined,
undefined,
{
@@ -42,7 +42,7 @@ class CastGateway {
try {
const token = getToken();
resp = await HTTPService.get(
- `${apiOrigin()}/cast/device-info/${code}`,
+ await apiURL(`cast/device-info/${code}`),
undefined,
{
"X-Auth-Token": token,
@@ -59,12 +59,9 @@ class CastGateway {
}
public async registerDevice(publicKey: string): Promise<string> {
- const resp = await HTTPService.post(
- apiOrigin() + "/cast/device-info/",
- {
- publicKey: publicKey,
- },
- );
+ const resp = await HTTPService.post(await apiURL("cast/device-info"), {
+ publicKey: publicKey,
+ });
return resp.data.deviceCode;
}
@@ -76,7 +73,7 @@ class CastGateway {
) {
const token = getToken();
await HTTPService.post(
- apiOrigin() + "/cast/cast-data/",
+ await apiURL("cast/cast-data"),
{
deviceCode: `${code}`,
encPayload: castPayload,