Skip to content

Commit 3bf7704

Browse files
authored
Merge pull request #2146 from makeplane/sync/ce-ee
Sync: Community Changes
2 parents 64b0f39 + ac14d57 commit 3bf7704

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

packages/services/src/auth/auth.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export class AuthService extends APIService {
2222
* Requests a CSRF token for form submission security
2323
* @returns {Promise<ICsrfTokenData>} Object containing the CSRF token
2424
* @throws {Error} Throws the complete error object if the request fails
25+
* @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors.
2526
*/
2627
async requestCSRFToken(): Promise<ICsrfTokenData> {
27-
return this.get("/auth/get-csrf-token/")
28+
return this.get("/auth/get-csrf-token/", { validateStatus: null })
2829
.then((response) => response.data)
2930
.catch((error) => {
3031
throw error;

packages/services/src/instance/instance.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export class InstanceService extends APIService {
2929
* Retrieves information about the current instance
3030
* @returns {Promise<IInstanceInfo>} Promise resolving to instance information
3131
* @throws {Error} If the API request fails
32+
* @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors.
3233
*/
3334
async info(): Promise<IInstanceInfo> {
34-
return this.get("/api/instances/")
35+
return this.get("/api/instances/", { validateStatus: null })
3536
.then((response) => response.data)
3637
.catch((error) => {
3738
throw error?.response?.data;
@@ -55,9 +56,10 @@ export class InstanceService extends APIService {
5556
* Fetches the list of instance admins
5657
* @returns {Promise<IInstanceAdmin[]>} Promise resolving to an array of instance admins
5758
* @throws {Error} If the API request fails
59+
* @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors.
5860
*/
5961
async admins(): Promise<IInstanceAdmin[]> {
60-
return this.get("/api/instances/admins/")
62+
return this.get("/api/instances/admins/", { validateStatus: null })
6163
.then((response) => response.data)
6264
.catch((error) => {
6365
throw error?.response?.data;

packages/services/src/user/user.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ export class UserService extends APIService {
2222
* Retrieves the current instance admin details
2323
* @returns {Promise<IUser>} Promise resolving to the current instance admin details
2424
* @throws {Error} If the API request fails
25+
* @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors.
2526
*/
2627
async adminDetails(): Promise<IUser> {
27-
return this.get("/api/instances/admins/me/")
28+
return this.get("/api/instances/admins/me/", { validateStatus: null })
2829
.then((response) => response?.data)
2930
.catch((error) => {
3031
throw error?.response?.data;
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useCallback, useEffect } from "react";
22
// plane editor
3-
import { EditorRefApi } from "@plane/editor";
3+
import { EditorRefApi, getBinaryDataFromDocumentEditorHTMLString } from "@plane/editor";
44
// plane types
55
import { TDocumentPayload } from "@plane/types";
66
// hooks
77
import useAutoSave from "@/hooks/use-auto-save";
88

99
type TArgs = {
1010
editorRef: React.RefObject<EditorRefApi>;
11-
fetchPageDescription: () => Promise<any>;
11+
fetchPageDescription: () => Promise<ArrayBuffer>;
1212
hasConnectionFailed: boolean;
1313
updatePageDescription: (data: TDocumentPayload) => Promise<void>;
1414
};
@@ -21,28 +21,35 @@ export const usePageFallback = (args: TArgs) => {
2121
const editor = editorRef.current;
2222
if (!editor) return;
2323

24-
const latestEncodedDescription = await fetchPageDescription();
25-
const latestDecodedDescription = latestEncodedDescription
26-
? new Uint8Array(latestEncodedDescription)
27-
: new Uint8Array();
28-
29-
editor.setProviderDocument(latestDecodedDescription);
30-
const { binary, html, json } = editor.getDocument();
31-
if (!binary || !json) return;
32-
const encodedBinary = Buffer.from(binary).toString("base64");
33-
34-
await updatePageDescription({
35-
description_binary: encodedBinary,
36-
description_html: html,
37-
description: json,
38-
});
39-
}, [hasConnectionFailed]);
24+
try {
25+
const latestEncodedDescription = await fetchPageDescription();
26+
let latestDecodedDescription: Uint8Array;
27+
if (latestEncodedDescription && latestEncodedDescription.byteLength > 0) {
28+
latestDecodedDescription = new Uint8Array(latestEncodedDescription);
29+
} else {
30+
latestDecodedDescription = getBinaryDataFromDocumentEditorHTMLString("<p></p>");
31+
}
32+
33+
editor.setProviderDocument(latestDecodedDescription);
34+
const { binary, html, json } = editor.getDocument();
35+
if (!binary || !json) return;
36+
const encodedBinary = Buffer.from(binary).toString("base64");
37+
38+
await updatePageDescription({
39+
description_binary: encodedBinary,
40+
description_html: html,
41+
description: json,
42+
});
43+
} catch (error) {
44+
console.error("Error in updating description using fallback logic:", error);
45+
}
46+
}, [editorRef, fetchPageDescription, hasConnectionFailed, updatePageDescription]);
4047

4148
useEffect(() => {
4249
if (hasConnectionFailed) {
4350
handleUpdateDescription();
4451
}
45-
}, [hasConnectionFailed]);
52+
}, [handleUpdateDescription, hasConnectionFailed]);
4653

4754
useAutoSave(handleUpdateDescription);
4855
};

0 commit comments

Comments
 (0)