feat: Remove support for V1 unencrypted backend (#4189)
This commit is contained in:
parent
8d4f455cd3
commit
f1eb969565
1
.env
1
.env
@ -1,4 +1,3 @@
|
|||||||
REACT_APP_BACKEND_V1_GET_URL=https://json-dev.excalidraw.com/api/v1/
|
|
||||||
REACT_APP_BACKEND_V2_GET_URL=https://json-dev.excalidraw.com/api/v2/
|
REACT_APP_BACKEND_V2_GET_URL=https://json-dev.excalidraw.com/api/v2/
|
||||||
REACT_APP_BACKEND_V2_POST_URL=https://json-dev.excalidraw.com/api/v2/post/
|
REACT_APP_BACKEND_V2_POST_URL=https://json-dev.excalidraw.com/api/v2/post/
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
REACT_APP_BACKEND_V1_GET_URL=https://json.excalidraw.com/api/v1/
|
|
||||||
REACT_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/
|
REACT_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/
|
||||||
REACT_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/
|
REACT_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import { saveFilesToFirebase } from "./firebase";
|
|||||||
|
|
||||||
const byteToHex = (byte: number): string => `0${byte.toString(16)}`.slice(-2);
|
const byteToHex = (byte: number): string => `0${byte.toString(16)}`.slice(-2);
|
||||||
|
|
||||||
const BACKEND_GET = process.env.REACT_APP_BACKEND_V1_GET_URL;
|
|
||||||
const BACKEND_V2_GET = process.env.REACT_APP_BACKEND_V2_GET_URL;
|
const BACKEND_V2_GET = process.env.REACT_APP_BACKEND_V2_GET_URL;
|
||||||
const BACKEND_V2_POST = process.env.REACT_APP_BACKEND_V2_POST_URL;
|
const BACKEND_V2_POST = process.env.REACT_APP_BACKEND_V2_POST_URL;
|
||||||
|
|
||||||
@ -176,20 +175,16 @@ export const decryptImported = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const importFromBackend = async (
|
const importFromBackend = async (
|
||||||
id: string | null,
|
id: string,
|
||||||
privateKey?: string | null,
|
privateKey: string,
|
||||||
): Promise<ImportedDataState> => {
|
): Promise<ImportedDataState> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(`${BACKEND_V2_GET}${id}`);
|
||||||
privateKey ? `${BACKEND_V2_GET}${id}` : `${BACKEND_GET}${id}.json`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
window.alert(t("alerts.importBackendFailed"));
|
window.alert(t("alerts.importBackendFailed"));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
let data: ImportedDataState;
|
|
||||||
if (privateKey) {
|
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
|
|
||||||
let decrypted: ArrayBuffer;
|
let decrypted: ArrayBuffer;
|
||||||
@ -208,11 +203,7 @@ const importFromBackend = async (
|
|||||||
const string = new window.TextDecoder("utf-8").decode(
|
const string = new window.TextDecoder("utf-8").decode(
|
||||||
new Uint8Array(decrypted),
|
new Uint8Array(decrypted),
|
||||||
);
|
);
|
||||||
data = JSON.parse(string);
|
const data: ImportedDataState = JSON.parse(string);
|
||||||
} else {
|
|
||||||
// Legacy format
|
|
||||||
data = await response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elements: data.elements || null,
|
elements: data.elements || null,
|
||||||
@ -234,7 +225,7 @@ export const loadScene = async (
|
|||||||
localDataState: ImportedDataState | undefined | null,
|
localDataState: ImportedDataState | undefined | null,
|
||||||
) => {
|
) => {
|
||||||
let data;
|
let data;
|
||||||
if (id != null) {
|
if (id != null && privateKey != null) {
|
||||||
// the private key is used to decrypt the content from the server, take
|
// the private key is used to decrypt the content from the server, take
|
||||||
// extra care not to leak it
|
// extra care not to leak it
|
||||||
data = restore(
|
data = restore(
|
||||||
|
@ -184,10 +184,7 @@ const initializeScene = async (opts: {
|
|||||||
// otherwise, prompt whether user wants to override current scene
|
// otherwise, prompt whether user wants to override current scene
|
||||||
window.confirm(t("alerts.loadSceneOverridePrompt"))
|
window.confirm(t("alerts.loadSceneOverridePrompt"))
|
||||||
) {
|
) {
|
||||||
// Backwards compatibility with legacy url format
|
if (jsonBackendMatch) {
|
||||||
if (id) {
|
|
||||||
scene = await loadScene(id, null, localDataState);
|
|
||||||
} else if (jsonBackendMatch) {
|
|
||||||
scene = await loadScene(
|
scene = await loadScene(
|
||||||
jsonBackendMatch[1],
|
jsonBackendMatch[1],
|
||||||
jsonBackendMatch[2],
|
jsonBackendMatch[2],
|
||||||
|
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@ -19,7 +19,6 @@ interface Window {
|
|||||||
// https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.ts
|
// https://github.com/facebook/create-react-app/blob/ddcb7d5/packages/react-scripts/lib/react-app.d.ts
|
||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
interface ProcessEnv {
|
interface ProcessEnv {
|
||||||
readonly REACT_APP_BACKEND_V1_GET_URL: string;
|
|
||||||
readonly REACT_APP_BACKEND_V2_GET_URL: string;
|
readonly REACT_APP_BACKEND_V2_GET_URL: string;
|
||||||
readonly REACT_APP_BACKEND_V2_POST_URL: string;
|
readonly REACT_APP_BACKEND_V2_POST_URL: string;
|
||||||
readonly REACT_APP_SOCKET_SERVER_URL: string;
|
readonly REACT_APP_SOCKET_SERVER_URL: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user