Prune
This commit is contained in:
@@ -3,7 +3,7 @@ import { CssBaseline } from "@mui/material";
|
||||
import { ThemeProvider } from "@mui/material/styles";
|
||||
import { accountLogout } from "ente-accounts/services/logout";
|
||||
import type { User } from "ente-accounts/services/user";
|
||||
import { clientPackageName, staticAppTitle } from "ente-base/app";
|
||||
import { staticAppTitle } from "ente-base/app";
|
||||
import { CustomHead } from "ente-base/components/Head";
|
||||
import {
|
||||
LoadingIndicator,
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
import { authTheme } from "ente-base/components/utils/theme";
|
||||
import { BaseContext, deriveBaseContext } from "ente-base/context";
|
||||
import { logStartupBanner } from "ente-base/log-web";
|
||||
import HTTPService from "ente-shared/network/HTTPService";
|
||||
import { getData } from "ente-shared/storage/localStorage";
|
||||
import { t } from "i18next";
|
||||
import type { AppProps } from "next/app";
|
||||
@@ -35,7 +34,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
|
||||
useEffect(() => {
|
||||
const user = getData("user") as User | undefined | null;
|
||||
logStartupBanner(user?.id);
|
||||
HTTPService.setHeaders({ "X-Client-Package": clientPackageName });
|
||||
}, []);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { CssBaseline, Typography } from "@mui/material";
|
||||
import { styled, ThemeProvider } from "@mui/material/styles";
|
||||
import { useNotification } from "components/utils/hooks-app";
|
||||
import type { User } from "ente-accounts/services/user";
|
||||
import { clientPackageName, isDesktop, staticAppTitle } from "ente-base/app";
|
||||
import { isDesktop, staticAppTitle } from "ente-base/app";
|
||||
import { CenteredRow } from "ente-base/components/containers";
|
||||
import { CustomHead } from "ente-base/components/Head";
|
||||
import {
|
||||
@@ -39,7 +39,6 @@ import { runMigrations } from "ente-new/photos/services/migration";
|
||||
import { initML, isMLSupported } from "ente-new/photos/services/ml";
|
||||
import { getFamilyPortalRedirectURL } from "ente-new/photos/services/user-details";
|
||||
import { PhotosAppContext } from "ente-new/photos/types/context";
|
||||
import HTTPService from "ente-shared/network/HTTPService";
|
||||
import {
|
||||
getData,
|
||||
isLocalStorageAndIndexedDBMismatch,
|
||||
@@ -71,7 +70,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
|
||||
useEffect(() => {
|
||||
const user = getData("user") as User | undefined | null;
|
||||
logStartupBanner(user?.id);
|
||||
HTTPService.setHeaders({ "X-Client-Package": clientPackageName });
|
||||
void isLocalStorageAndIndexedDBMismatch().then((mismatch) => {
|
||||
if (mismatch) {
|
||||
log.error("Logging out (IndexedDB and local storage mismatch)");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import { HttpStatusCode } from "axios";
|
||||
import {
|
||||
AccountsPageContents,
|
||||
AccountsPageFooter,
|
||||
@@ -39,7 +38,6 @@ import { isDevBuild } from "ente-base/env";
|
||||
import { isHTTPErrorWithStatus } from "ente-base/http";
|
||||
import log from "ente-base/log";
|
||||
import { clearSessionStorage } from "ente-base/session";
|
||||
import { ApiError } from "ente-shared/error";
|
||||
import localForage from "ente-shared/storage/localForage";
|
||||
import { getData, setData, setLSUser } from "ente-shared/storage/localStorage";
|
||||
import {
|
||||
@@ -169,14 +167,6 @@ const Page: React.FC = () => {
|
||||
setFieldError(t("invalid_code_error"));
|
||||
} else if (isHTTPErrorWithStatus(e, 410)) {
|
||||
setFieldError(t("expired_code_error"));
|
||||
} else if (e instanceof ApiError) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
||||
if (e?.httpStatusCode === HttpStatusCode.Unauthorized) {
|
||||
setFieldError(t("invalid_code_error"));
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
||||
} else if (e?.httpStatusCode === HttpStatusCode.Gone) {
|
||||
setFieldError(t("expired_code_error"));
|
||||
}
|
||||
} else {
|
||||
log.error("OTT verification failed", e);
|
||||
throw e;
|
||||
|
||||
@@ -1,26 +1,3 @@
|
||||
import { HttpStatusCode } from "axios";
|
||||
|
||||
export interface ApiErrorResponse {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
httpStatusCode: number;
|
||||
errCode: string;
|
||||
|
||||
constructor(message: string, errCode: string, httpStatus: number) {
|
||||
super(message);
|
||||
this.name = "ApiError";
|
||||
this.errCode = errCode;
|
||||
this.httpStatusCode = httpStatus;
|
||||
}
|
||||
}
|
||||
|
||||
export function isApiErrorResponse(object: any): object is ApiErrorResponse {
|
||||
return object && "code" in object && "message" in object;
|
||||
}
|
||||
|
||||
export const CustomError = {
|
||||
TOKEN_EXPIRED: "token expired",
|
||||
TOO_MANY_REQUESTS: "too many requests",
|
||||
@@ -32,32 +9,3 @@ export const CustomError = {
|
||||
EXPORT_FOLDER_DOES_NOT_EXIST: "export folder does not exist",
|
||||
TWO_FACTOR_ENABLED: "two factor enabled",
|
||||
};
|
||||
|
||||
export const parseSharingErrorCodes = (error: any) => {
|
||||
let parsedMessage = null;
|
||||
if (error instanceof ApiError) {
|
||||
switch (error.httpStatusCode) {
|
||||
case HttpStatusCode.BadRequest:
|
||||
parsedMessage = CustomError.BAD_REQUEST;
|
||||
break;
|
||||
case HttpStatusCode.PaymentRequired:
|
||||
parsedMessage = CustomError.SUBSCRIPTION_NEEDED;
|
||||
break;
|
||||
case HttpStatusCode.NotFound:
|
||||
parsedMessage = CustomError.NOT_FOUND;
|
||||
break;
|
||||
case HttpStatusCode.Unauthorized:
|
||||
case HttpStatusCode.Gone:
|
||||
parsedMessage = CustomError.TOKEN_EXPIRED;
|
||||
break;
|
||||
case HttpStatusCode.TooManyRequests:
|
||||
parsedMessage = CustomError.TOO_MANY_REQUESTS;
|
||||
break;
|
||||
default:
|
||||
parsedMessage = `Something went wrong (statusCode:${error.httpStatusCode})`;
|
||||
}
|
||||
} else {
|
||||
parsedMessage = error.message;
|
||||
}
|
||||
return new Error(parsedMessage);
|
||||
};
|
||||
|
||||
@@ -1,223 +0,0 @@
|
||||
import axios, { type AxiosRequestConfig, type AxiosResponse } from "axios";
|
||||
import log from "ente-base/log";
|
||||
import { ApiError, isApiErrorResponse } from "../error";
|
||||
|
||||
type IHTTPHeaders = Record<string, any>;
|
||||
|
||||
type IQueryPrams = Record<string, any>;
|
||||
|
||||
/**
|
||||
* Service to manage all HTTP calls.
|
||||
*/
|
||||
class HTTPService {
|
||||
constructor() {
|
||||
axios.interceptors.response.use(
|
||||
(response) => Promise.resolve(response),
|
||||
(error) => {
|
||||
const config = error.config as AxiosRequestConfig;
|
||||
if (error.response) {
|
||||
const response = error.response as AxiosResponse;
|
||||
let apiError: ApiError;
|
||||
// The request was made and the server responded with a status code
|
||||
// that falls out of the range of 2xx
|
||||
if (isApiErrorResponse(response.data)) {
|
||||
const responseData = response.data;
|
||||
log.error(
|
||||
`HTTP Service Error - ${JSON.stringify({
|
||||
url: config?.url,
|
||||
method: config?.method,
|
||||
xRequestId: response.headers["x-request-id"],
|
||||
httpStatus: response.status,
|
||||
errMessage: responseData.message,
|
||||
errCode: responseData.code,
|
||||
})}`,
|
||||
error,
|
||||
);
|
||||
apiError = new ApiError(
|
||||
responseData.message,
|
||||
responseData.code,
|
||||
response.status,
|
||||
);
|
||||
} else {
|
||||
if (response.status >= 400 && response.status < 500) {
|
||||
apiError = new ApiError(
|
||||
"client error",
|
||||
"",
|
||||
response.status,
|
||||
);
|
||||
} else {
|
||||
apiError = new ApiError(
|
||||
"server error",
|
||||
"",
|
||||
response.status,
|
||||
);
|
||||
}
|
||||
}
|
||||
log.error(
|
||||
`HTTP Service Error - ${JSON.stringify({
|
||||
url: config.url,
|
||||
method: config.method,
|
||||
cfRay: response.headers["cf-ray"],
|
||||
xRequestId: response.headers["x-request-id"],
|
||||
httpStatus: response.status,
|
||||
})}`,
|
||||
apiError,
|
||||
);
|
||||
throw apiError;
|
||||
} else if (error.request) {
|
||||
// The request was made but no response was received
|
||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||
// http.ClientRequest in node.js
|
||||
log.info(
|
||||
`request failed - no response (${config.method} ${config.url}`,
|
||||
);
|
||||
return Promise.reject(error);
|
||||
} else {
|
||||
// Something happened in setting up the request that
|
||||
// triggered an Error
|
||||
log.info(
|
||||
`request failed - axios error (${config.method} ${config.url}`,
|
||||
);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* header object to be append to all api calls.
|
||||
*/
|
||||
private headers: IHTTPHeaders = { "content-type": "application/json" };
|
||||
|
||||
/**
|
||||
* Sets the headers to the given object.
|
||||
*/
|
||||
public setHeaders(headers: IHTTPHeaders) {
|
||||
this.headers = { ...this.headers, ...headers };
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a header to list of headers.
|
||||
*/
|
||||
public appendHeader(key: string, value: string) {
|
||||
this.headers = { ...this.headers, [key]: value };
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given header.
|
||||
*/
|
||||
public removeHeader(key: string) {
|
||||
this.headers[key] = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns axios interceptors.
|
||||
*/
|
||||
public getInterceptors() {
|
||||
return axios.interceptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic HTTP request.
|
||||
* This is done so that developer can use any functionality
|
||||
* provided by axios. Here, only the set headers are spread
|
||||
* over what was sent in config.
|
||||
*/
|
||||
public async request(config: AxiosRequestConfig, customConfig?: any) {
|
||||
config.headers = {
|
||||
...this.headers,
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-spread
|
||||
...config.headers,
|
||||
};
|
||||
if (customConfig?.cancel) {
|
||||
config.cancelToken = new axios.CancelToken(
|
||||
(c) => (customConfig.cancel.exec = c),
|
||||
);
|
||||
}
|
||||
return await axios({ ...config, ...customConfig });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request.
|
||||
*/
|
||||
public get(
|
||||
url: string,
|
||||
params?: IQueryPrams,
|
||||
headers?: IHTTPHeaders,
|
||||
customConfig?: any,
|
||||
) {
|
||||
return this.request(
|
||||
{ headers, method: "GET", params, url },
|
||||
customConfig,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post request
|
||||
*/
|
||||
public post(
|
||||
url: string,
|
||||
data?: any,
|
||||
params?: IQueryPrams,
|
||||
headers?: IHTTPHeaders,
|
||||
customConfig?: any,
|
||||
) {
|
||||
return this.request(
|
||||
{ data, headers, method: "POST", params, url },
|
||||
customConfig,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch request
|
||||
*/
|
||||
public patch(
|
||||
url: string,
|
||||
data?: any,
|
||||
params?: IQueryPrams,
|
||||
headers?: IHTTPHeaders,
|
||||
customConfig?: any,
|
||||
) {
|
||||
return this.request(
|
||||
{ data, headers, method: "PATCH", params, url },
|
||||
customConfig,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put request
|
||||
*/
|
||||
public put(
|
||||
url: string,
|
||||
data: any,
|
||||
params?: IQueryPrams,
|
||||
headers?: IHTTPHeaders,
|
||||
customConfig?: any,
|
||||
) {
|
||||
return this.request(
|
||||
{ data, headers, method: "PUT", params, url },
|
||||
customConfig,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete request
|
||||
*/
|
||||
public delete(
|
||||
url: string,
|
||||
data: any,
|
||||
params?: IQueryPrams,
|
||||
headers?: IHTTPHeaders,
|
||||
customConfig?: any,
|
||||
) {
|
||||
return this.request(
|
||||
{ data, headers, method: "DELETE", params, url },
|
||||
customConfig,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a Singleton Service.
|
||||
// This will help me maintain common headers / functionality
|
||||
// at a central place.
|
||||
export default new HTTPService();
|
||||
@@ -3,7 +3,6 @@
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"axios": "^1.9.0",
|
||||
"ente-base": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1469,11 +1469,6 @@ arraybuffer.prototype.slice@^1.0.4:
|
||||
get-intrinsic "^1.2.6"
|
||||
is-array-buffer "^3.0.4"
|
||||
|
||||
asynckit@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
||||
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
|
||||
|
||||
attr-accept@^2.2.2:
|
||||
version "2.2.5"
|
||||
resolved "https://registry.yarnpkg.com/attr-accept/-/attr-accept-2.2.5.tgz#d7061d958e6d4f97bf8665c68b75851a0713ab5e"
|
||||
@@ -1486,15 +1481,6 @@ available-typed-arrays@^1.0.7:
|
||||
dependencies:
|
||||
possible-typed-array-names "^1.0.0"
|
||||
|
||||
axios@^1.9.0:
|
||||
version "1.9.0"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-1.9.0.tgz#25534e3b72b54540077d33046f77e3b8d7081901"
|
||||
integrity sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==
|
||||
dependencies:
|
||||
follow-redirects "^1.15.6"
|
||||
form-data "^4.0.0"
|
||||
proxy-from-env "^1.1.0"
|
||||
|
||||
babel-plugin-macros@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-3.1.0.tgz#9ef6dc74deb934b4db344dc973ee851d148c50c1"
|
||||
@@ -1670,13 +1656,6 @@ color@^4.2.3:
|
||||
color-convert "^2.0.1"
|
||||
color-string "^1.9.0"
|
||||
|
||||
combined-stream@^1.0.8:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
|
||||
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
|
||||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
comlink@^4.4.2:
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/comlink/-/comlink-4.4.2.tgz#cbbcd82742fbebc06489c28a183eedc5c60a2bca"
|
||||
@@ -1817,11 +1796,6 @@ define-properties@^1.1.3, define-properties@^1.2.1:
|
||||
has-property-descriptors "^1.0.0"
|
||||
object-keys "^1.1.1"
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
|
||||
|
||||
detect-indent@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-7.0.1.tgz#cbb060a12842b9c4d333f1cac4aa4da1bb66bc25"
|
||||
@@ -2287,11 +2261,6 @@ flatted@^3.2.9:
|
||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.2.tgz#adba1448a9841bec72b42c532ea23dbbedef1a27"
|
||||
integrity sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA==
|
||||
|
||||
follow-redirects@^1.15.6:
|
||||
version "1.15.9"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
|
||||
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
|
||||
|
||||
for-each@^0.3.3:
|
||||
version "0.3.3"
|
||||
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
|
||||
@@ -2299,15 +2268,6 @@ for-each@^0.3.3:
|
||||
dependencies:
|
||||
is-callable "^1.1.3"
|
||||
|
||||
form-data@^4.0.0:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48"
|
||||
integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
formik@^2.4.6:
|
||||
version "2.4.6"
|
||||
resolved "https://registry.yarnpkg.com/formik/-/formik-2.4.6.tgz#4da75ca80f1a827ab35b08fd98d5a76e928c9686"
|
||||
@@ -3051,18 +3011,6 @@ micromatch@^4.0.4:
|
||||
braces "^3.0.3"
|
||||
picomatch "^2.3.1"
|
||||
|
||||
mime-db@1.52.0:
|
||||
version "1.52.0"
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
|
||||
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
|
||||
|
||||
mime-types@^2.1.12:
|
||||
version "2.1.35"
|
||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
|
||||
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
|
||||
dependencies:
|
||||
mime-db "1.52.0"
|
||||
|
||||
mimic-function@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/mimic-function/-/mimic-function-5.0.1.tgz#acbe2b3349f99b9deaca7fb70e48b83e94e67076"
|
||||
@@ -3397,11 +3345,6 @@ prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.8.1:
|
||||
object-assign "^4.1.1"
|
||||
react-is "^16.13.1"
|
||||
|
||||
proxy-from-env@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
|
||||
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
|
||||
|
||||
punycode@^2.1.0:
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
|
||||
|
||||
Reference in New Issue
Block a user