Skip to content

armgit / ente

Public Imported from GitHub
0

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

Continue

Manav Rathi3f96209dbb89
diff --git a/web/apps/auth/src/services/remote.ts b/web/apps/auth/src/services/remote.ts
index 0202d997e3..93429be259 100644
--- a/web/apps/auth/src/services/remote.ts
+++ b/web/apps/auth/src/services/remote.ts
@@ -1,5 +1,5 @@
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { ApiError, CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
@@ -81,7 +81,7 @@ interface AuthKey {
export const getAuthKey = async (): Promise<AuthKey> => {
try {
const resp = await HTTPService.get(
- `${apiOrigin()}/authenticator/key`,
+ await apiURL("/authenticator/key"),
{},
{
"X-Auth-Token": getToken(),
@@ -108,7 +108,7 @@ export const getDiff = async (
): Promise<AuthEntity[]> => {
try {
const resp = await HTTPService.get(
- `${apiOrigin()}/authenticator/entity/diff`,
+ await apiURL("/authenticator/entity/diff"),
{
sinceTime,
limit,
diff --git a/web/apps/cast/src/services/render.ts b/web/apps/cast/src/services/render.ts
index 750b9bac85..5e86b3b8bc 100644
--- a/web/apps/cast/src/services/render.ts
+++ b/web/apps/cast/src/services/render.ts
@@ -17,7 +17,7 @@ import type {
} from "@/new/photos/types/file";
import { nameAndExtension } from "@/next/file";
import log from "@/next/log";
-import { apiOrigin, customAPIOrigin } from "@/next/origins";
+import { apiURL, customAPIOrigin } from "@/next/origins";
import { shuffled } from "@/utils/array";
import { ensure } from "@/utils/ensure";
import { wait } from "@/utils/promise";
@@ -164,7 +164,7 @@ const getEncryptedCollectionFiles = async (
let resp: AxiosResponse;
do {
resp = await HTTPService.get(
- `${apiOrigin()}/cast/diff`,
+ await apiURL("/cast/diff"),
{ sinceTime },
{
"Cache-Control": "no-cache",
diff --git a/web/apps/photos/src/services/billingService.ts b/web/apps/photos/src/services/billingService.ts
index 67004874a0..b25a10c872 100644
--- a/web/apps/photos/src/services/billingService.ts
+++ b/web/apps/photos/src/services/billingService.ts
@@ -1,5 +1,5 @@
import log from "@/next/log";
-import { apiOrigin, paymentsAppOrigin } from "@/next/origins";
+import { apiURL, paymentsAppOrigin } from "@/next/origins";
import HTTPService from "@ente/shared/network/HTTPService";
import {
LS_KEYS,
@@ -33,11 +33,11 @@ class billingService {
let response;
if (!token) {
response = await HTTPService.get(
- `${apiOrigin()}/billing/plans/v2`,
+ await apiURL("/billing/plans/v2"),
);
} else {
response = await HTTPService.get(
- `${apiOrigin()}/billing/user-plans`,
+ await apiURL("/billing/user-plans"),
null,
{
"X-Auth-Token": getToken(),
@@ -53,7 +53,7 @@ class billingService {
public async syncSubscription() {
try {
const response = await HTTPService.get(
- `${apiOrigin()}/billing/subscription`,
+ await apiURL("/billing/subscription"),
null,
{
"X-Auth-Token": getToken(),
@@ -97,7 +97,7 @@ class billingService {
public async cancelSubscription() {
try {
const response = await HTTPService.post(
- `${apiOrigin()}/billing/stripe/cancel-subscription`,
+ await apiURL("/billing/stripe/cancel-subscription"),
null,
null,
{
@@ -115,7 +115,7 @@ class billingService {
public async activateSubscription() {
try {
const response = await HTTPService.post(
- `${apiOrigin()}/billing/stripe/activate-subscription`,
+ await apiURL("/billing/stripe/activate-subscription"),
null,
null,
{
@@ -139,7 +139,7 @@ class billingService {
return;
}
const response = await HTTPService.post(
- `${apiOrigin()}/billing/verify-subscription`,
+ await apiURL("/billing/verify-subscription"),
{
paymentProvider: "stripe",
productID: null,
@@ -165,7 +165,7 @@ class billingService {
}
try {
await HTTPService.delete(
- `${apiOrigin()}/family/leave`,
+ await apiURL("/family/leave"),
null,
null,
{
@@ -197,7 +197,7 @@ class billingService {
try {
const redirectURL = this.getRedirectURL();
const response = await HTTPService.get(
- `${apiOrigin()}/billing/stripe/customer-portal`,
+ await apiURL("/billing/stripe/customer-portal"),
{ redirectURL },
{
"X-Auth-Token": getToken(),
diff --git a/web/apps/photos/src/services/deduplicationService.ts b/web/apps/photos/src/services/deduplicationService.ts
index d1edc4f642..613289c883 100644
--- a/web/apps/photos/src/services/deduplicationService.ts
+++ b/web/apps/photos/src/services/deduplicationService.ts
@@ -3,7 +3,7 @@ import { FILE_TYPE } from "@/media/file-type";
import type { Metadata } from "@/media/types/file";
import { EnteFile } from "@/new/photos/types/file";
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import HTTPService from "@ente/shared/network/HTTPService";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
@@ -146,7 +146,7 @@ function groupDupesByFileHashes(dupe: Duplicate) {
async function fetchDuplicateFileIDs() {
try {
const response = await HTTPService.get(
- `${apiOrigin()}/files/duplicates`,
+ await apiURL("/files/duplicates"),
null,
{
"X-Auth-Token": getToken(),
diff --git a/web/apps/photos/src/services/embeddingService.ts b/web/apps/photos/src/services/embeddingService.ts
index 2c91ca01c9..4aa6c39878 100644
--- a/web/apps/photos/src/services/embeddingService.ts
+++ b/web/apps/photos/src/services/embeddingService.ts
@@ -3,7 +3,7 @@ import { getAllLocalFiles } from "@/new/photos/services/files";
import { EnteFile } from "@/new/photos/types/file";
import { inWorker } from "@/next/env";
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { workerBridge } from "@/next/worker/worker-bridge";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { CustomError } from "@ente/shared/error";
@@ -285,7 +285,7 @@ export const getEmbeddingsDiff = async (
return;
}
const response = await HTTPService.get(
- `${apiOrigin()}/embeddings/diff`,
+ await apiURL("/embeddings/diff"),
{
sinceTime,
limit: DIFF_LIMIT,
@@ -314,7 +314,7 @@ export const putEmbedding = async (
throw Error(CustomError.TOKEN_MISSING);
}
const resp = await HTTPService.put(
- `${apiOrigin()}/embeddings`,
+ await apiURL("/embeddings"),
putEmbeddingReq,
null,
{
diff --git a/web/apps/photos/src/services/publicCollectionService.ts b/web/apps/photos/src/services/publicCollectionService.ts
index d33d89fc41..0528094d3f 100644
--- a/web/apps/photos/src/services/publicCollectionService.ts
+++ b/web/apps/photos/src/services/publicCollectionService.ts
@@ -1,6 +1,6 @@
import { EncryptedEnteFile, EnteFile } from "@/new/photos/types/file";
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { CustomError, parseSharingErrorCodes } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
@@ -252,7 +252,7 @@ const getPublicFiles = async (
break;
}
resp = await HTTPService.get(
- `${apiOrigin()}/public-collection/diff`,
+ await apiURL("/public-collection/diff"),
{
sinceTime: time,
},
@@ -307,7 +307,7 @@ export const getPublicCollection = async (
return;
}
const resp = await HTTPService.get(
- `${apiOrigin()}/public-collection/info`,
+ await apiURL("/public-collection/info"),
null,
{ "Cache-Control": "no-cache", "X-Auth-Access-Token": token },
);
@@ -357,7 +357,7 @@ export const verifyPublicCollectionPassword = async (
): Promise<string> => {
try {
const resp = await HTTPService.post(
- `${apiOrigin()}/public-collection/verify-password`,
+ await apiURL("/public-collection/verify-password"),
{ passHash: passwordHash },
null,
{ "Cache-Control": "no-cache", "X-Auth-Access-Token": token },
diff --git a/web/apps/photos/src/services/trashService.ts b/web/apps/photos/src/services/trashService.ts
index cd5b2aa9b9..b4920ed1ea 100644
--- a/web/apps/photos/src/services/trashService.ts
+++ b/web/apps/photos/src/services/trashService.ts
@@ -1,6 +1,6 @@
import { EnteFile } from "@/new/photos/types/file";
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import HTTPService from "@ente/shared/network/HTTPService";
import localForage from "@ente/shared/storage/localForage";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
@@ -89,7 +89,7 @@ export const updateTrash = async (
break;
}
resp = await HTTPService.get(
- `${apiOrigin()}/trash/v2/diff`,
+ await apiURL("/trash/v2/diff"),
{
sinceTime: time,
},
@@ -158,7 +158,7 @@ export const emptyTrash = async () => {
const lastUpdatedAt = await getLastSyncTime();
await HTTPService.post(
- `${apiOrigin()}/trash/empty`,
+ await apiURL("/trash/empty"),
{ lastUpdatedAt },
null,
{
diff --git a/web/apps/photos/src/services/upload/publicUploadHttpClient.ts b/web/apps/photos/src/services/upload/publicUploadHttpClient.ts
index e0f0bac3ea..063d645173 100644
--- a/web/apps/photos/src/services/upload/publicUploadHttpClient.ts
+++ b/web/apps/photos/src/services/upload/publicUploadHttpClient.ts
@@ -1,6 +1,6 @@
import { EnteFile } from "@/new/photos/types/file";
import log from "@/next/log";
-import { apiOrigin } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import { CustomError, handleUploadError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
import { retryHTTPCall } from "./uploadHttpClient";
@@ -20,19 +20,15 @@ class PublicUploadHttpClient {
if (!token) {
throw Error(CustomError.TOKEN_MISSING);
}
+ const url = await apiURL("/public-collection/file");
const response = await retryHTTPCall(
() =>
- HTTPService.post(
- `${apiOrigin()}/public-collection/file`,
- uploadFile,
- null,
- {
- "X-Auth-Access-Token": token,
- ...(passwordToken && {
- "X-Auth-Access-Token-JWT": passwordToken,
- }),
- },
- ),
+ HTTPService.post(url, uploadFile, null, {
+ "X-Auth-Access-Token": token,
+ ...(passwordToken && {
+ "X-Auth-Access-Token-JWT": passwordToken,
+ }),
+ }),
handleUploadError,
);
return response.data;
@@ -55,7 +51,7 @@ class PublicUploadHttpClient {
throw Error(CustomError.TOKEN_MISSING);
}
this.uploadURLFetchInProgress = HTTPService.get(
- `${apiOrigin()}/public-collection/upload-urls`,
+ await apiURL("/public-collection/upload-urls"),
{
count: Math.min(MAX_URL_REQUESTS, count * 2),
},
@@ -91,7 +87,7 @@ class PublicUploadHttpClient {
throw Error(CustomError.TOKEN_MISSING);
}
const response = await HTTPService.get(
- `${apiOrigin()}/public-collection/multipart-upload-urls`,
+ await apiURL("/public-collection/multipart-upload-urls"),
{
count,
},
diff --git a/web/apps/photos/src/services/userService.ts b/web/apps/photos/src/services/userService.ts
index 6ae112635a..03c6ced55e 100644
--- a/web/apps/photos/src/services/userService.ts
+++ b/web/apps/photos/src/services/userService.ts
@@ -1,5 +1,5 @@
import log from "@/next/log";
-import { apiOrigin, customAPIOrigin, familyAppOrigin } from "@/next/origins";
+import { apiURL, customAPIOrigin, familyAppOrigin } from "@/next/origins";
import { putAttributes } from "@ente/accounts/api/user";
import { ApiError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
@@ -23,7 +23,7 @@ export const getPublicKey = async (email: string) => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/public-key`,
+ await apiURL("/users/public-key"),
{ email },
{
"X-Auth-Token": token,
@@ -36,7 +36,7 @@ export const getPaymentToken = async () => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/payment-token`,
+ await apiURL("/users/payment-token"),
null,
{
"X-Auth-Token": token,
@@ -50,7 +50,7 @@ export const getFamiliesToken = async () => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/families-token`,
+ await apiURL("/users/families-token"),
null,
{
"X-Auth-Token": token,
@@ -68,7 +68,7 @@ export const getRoadmapRedirectURL = async () => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/roadmap/v2`,
+ await apiURL("/users/roadmap/v2"),
null,
{
"X-Auth-Token": token,
@@ -84,7 +84,7 @@ export const getRoadmapRedirectURL = async () => {
export const isTokenValid = async (token: string) => {
try {
const resp = await HTTPService.get(
- `${apiOrigin()}/users/session-validity/v2`,
+ await apiURL("/users/session-validity/v2"),
null,
{
"X-Auth-Token": token,
@@ -123,7 +123,7 @@ export const isTokenValid = async (token: string) => {
export const getTwoFactorStatus = async () => {
const resp = await HTTPService.get(
- `${apiOrigin()}/users/two-factor/status`,
+ await apiURL("/users/two-factor/status"),
null,
{
"X-Auth-Token": getToken(),
@@ -137,7 +137,7 @@ export const getUserDetailsV2 = async (): Promise<UserDetails> => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/details/v2`,
+ await apiURL("/users/details/v2"),
null,
{
"X-Auth-Token": token,
@@ -168,7 +168,7 @@ export const getAccountDeleteChallenge = async () => {
const token = getToken();
const resp = await HTTPService.get(
- `${apiOrigin()}/users/delete-challenge`,
+ await apiURL("/users/delete-challenge"),
null,
{
"X-Auth-Token": token,
@@ -193,7 +193,7 @@ export const deleteAccount = async (
}
await HTTPService.delete(
- `${apiOrigin()}/users/delete`,
+ await apiURL("/users/delete"),
{ challenge, reason, feedback },
null,
{
@@ -211,7 +211,7 @@ export const getFaceSearchEnabledStatus = async () => {
const token = getToken();
const resp: AxiosResponse<GetRemoteStoreValueResponse> =
await HTTPService.get(
- `${apiOrigin()}/remote-store`,
+ await apiURL("/remote-store"),
{
key: "faceSearchEnabled",
defaultValue: false,
@@ -231,7 +231,7 @@ export const updateFaceSearchEnabledStatus = async (newStatus: boolean) => {
try {
const token = getToken();
await HTTPService.post(
- `${apiOrigin()}/remote-store/update`,
+ await apiURL("/remote-store/update"),
{
key: "faceSearchEnabled",
value: newStatus.toString(),
@@ -262,7 +262,7 @@ export const getMapEnabledStatus = async () => {
const token = getToken();
const resp: AxiosResponse<GetRemoteStoreValueResponse> =
await HTTPService.get(
- `${apiOrigin()}/remote-store`,
+ await apiURL("/remote-store"),
{
key: "mapEnabled",
defaultValue: false,
@@ -282,7 +282,7 @@ export const updateMapEnabledStatus = async (newStatus: boolean) => {
try {
const token = getToken();
await HTTPService.post(
- `${apiOrigin()}/remote-store/update`,
+ await apiURL("/remote-store/update"),
{
key: "mapEnabled",
value: newStatus.toString(),
@@ -318,7 +318,7 @@ export async function getDisableCFUploadProxyFlag(): Promise<boolean> {
// In such cases, disable the Cloudflare upload proxy (which won't work for
// self-hosters), and instead just directly use the upload URLs that museum
// gives us.
- if (customAPIOrigin()) return true;
+ if (await customAPIOrigin()) return true;
try {
const featureFlags = (
diff --git a/web/packages/accounts/api/user.ts b/web/packages/accounts/api/user.ts
index 30106ad873..131ae73ef7 100644
--- a/web/packages/accounts/api/user.ts
+++ b/web/packages/accounts/api/user.ts
@@ -1,4 +1,4 @@
-import { apiOrigin, apiURL } from "@/next/origins";
+import { apiURL } from "@/next/origins";
import type { AppName } from "@/next/types/app";
import type {
RecoveryKey,
@@ -71,7 +71,7 @@ export const logout = async () => {
export const verifyTwoFactor = async (code: string, sessionID: string) => {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/two-factor/verify`,
+ await apiURL("/users/two-factor/verify"),
{
code,
sessionID,
@@ -88,7 +88,7 @@ export const recoverTwoFactor = async (
twoFactorType: TwoFactorType,
) => {
const resp = await HTTPService.get(
- `${apiOrigin()}/users/two-factor/recover`,
+ await apiURL("/users/two-factor/recover"),
{
sessionID,
twoFactorType,
@@ -103,7 +103,7 @@ export const removeTwoFactor = async (
twoFactorType: TwoFactorType,
) => {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/two-factor/remove`,
+ await apiURL("/users/two-factor/remove"),
{
sessionID,
secret,
@@ -115,7 +115,7 @@ export const removeTwoFactor = async (
export const changeEmail = async (email: string, ott: string) => {
await HTTPService.post(
- `${apiOrigin()}/users/change-email`,
+ await apiURL("/users/change-email"),
{
email,
ott,
@@ -128,7 +128,7 @@ export const changeEmail = async (email: string, ott: string) => {
};
export const sendOTTForEmailChange = async (email: string) => {
- await HTTPService.post(`${apiOrigin()}/users/ott`, {
+ await HTTPService.post(await apiURL("/users/ott"), {
email,
client: "web",
purpose: "change",
@@ -137,7 +137,7 @@ export const sendOTTForEmailChange = async (email: string) => {
export const setupTwoFactor = async () => {
const resp = await HTTPService.post(
- `${apiOrigin()}/users/two-factor/setup`,
+ await apiURL("/users/two-factor/setup"),
null,
undefined,
{
@@ -152,7 +152,7 @@ export const enableTwoFactor = async (
recoveryEncryptedTwoFactorSecret: B64EncryptionResult,
) => {
await HTTPService.post(
- `${apiOrigin()}/users/two-factor/enable`,
+ await apiURL("/users/two-factor/enable"),
{
code,
encryptedTwoFactorSecret:
@@ -167,9 +167,9 @@ export const enableTwoFactor = async (
);
};
-export const setRecoveryKey = (token: string, recoveryKey: RecoveryKey) =>
+export const setRecoveryKey = async (token: string, recoveryKey: RecoveryKey) =>
HTTPService.put(
- `${apiOrigin()}/users/recovery-key`,
+ await apiURL("/users/recovery-key"),
recoveryKey,
undefined,
{
@@ -179,7 +179,7 @@ export const setRecoveryKey = (token: string, recoveryKey: RecoveryKey) =>
export const disableTwoFactor = async () => {
await HTTPService.post(
- `${apiOrigin()}/users/two-factor/disable`,
+ await apiURL("/users/two-factor/disable"),
null,
undefined,
{