Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions excalidraw-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1155,9 +1155,7 @@ interface ExcalidrawAppProps {
const meetingDetails = {
sessionId: "example-session-id",
roomJid: "example-room-jid",
jwt: "example-jwt",
jid: "example-jid",
token: "token"
jwt: "example-jwt"
}

const ExcalidrawApp = (props?: ExcalidrawAppProps) => {
Expand Down
2 changes: 1 addition & 1 deletion excalidraw-app/collab/Collab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class Collab extends PureComponent<CollabProps, CollabState> {
// Initializing storage backend if storageBackendUrl & jwt are provided
const { storageBackendUrl , meetingDetails } = this.props;
// Session Id is required to initialize the storage backend
if (storageBackendUrl && meetingDetails?.sessionId && meetingDetails.token) {
if (storageBackendUrl && meetingDetails?.sessionId && meetingDetails.jwt) {
try {
initializeBackend(storageBackendUrl, meetingDetails);
} catch (error: any) {
Expand Down
30 changes: 15 additions & 15 deletions excalidraw-app/data/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let backendApi: { baseUrl: string; apiPrefix: string } | null = null;
let meetingDetailsCache: IMeetingDetails | null = null; // Cache for meeting details


// Initialize backend configuration with storageBackendUrl & meetingDetails (Token comes from meetingDetails)
// Initialize backend configuration with storageBackendUrl & meetingDetails
export const initializeBackend = (storageBackendUrl?: string, meetingDetails?: IMeetingDetails) => {
backendApi = {
baseUrl: storageBackendUrl || BACKEND_CONFIG.baseUrl,
Expand All @@ -60,8 +60,8 @@ const _getBackendApi = () => {
return backendApi;
};

const _getToken = () => {
return meetingDetailsCache?.token;
const _getJwt = () => {
return meetingDetailsCache?.jwt;
};

const _getMeetingDetails = (): IMeetingDetails | null => {
Expand All @@ -77,14 +77,14 @@ const apiCall = async (endpoint: string, options: RequestInit = {}) => {
const api = _getBackendApi();
const url = `${api.baseUrl}${api.apiPrefix}${endpoint}`;

// Adding token to headers if available
// Adding jwt to headers if available
const headers: Record<string, string> = {
...options.headers as Record<string, string>,
};

const token = _getToken();
if (token) {
headers['Authorization'] = `Bearer ${token}`;
const jwt = _getJwt();
if (jwt) {
headers['Authorization'] = `Bearer ${jwt}`;
}

const response = await fetch(url, {
Expand Down Expand Up @@ -135,9 +135,9 @@ const uploadFilesWithMulter = async (prefix: string, files: { id: FileId; buffer
formData.append('file', blob, id);

const headers: Record<string, string> = {};
const token = _getToken();
if (token) {
headers['Authorization'] = `Bearer ${token}`;
const jwt = _getJwt();
if (jwt) {
headers['Authorization'] = `Bearer ${jwt}`;
}

const response = await fetch(url, {
Expand Down Expand Up @@ -174,7 +174,7 @@ const uploadFilesWithMulter = async (prefix: string, files: { id: FileId; buffer

// Helper function to download files
const downloadFilesFromBackend = async (prefix: string, fileIds: readonly FileId[]) => {

// Early return if no files to download
if (!fileIds || fileIds.length === 0) {
return { loadedFiles: [], erroredFiles: [] };
Expand All @@ -191,16 +191,16 @@ const downloadFilesFromBackend = async (prefix: string, fileIds: readonly FileId
const erroredFiles: FileId[] = [];

const headers: Record<string, string> = {};
const token = _getToken();
if (token) {
headers['Authorization'] = `Bearer ${token}`;
const jwt = _getJwt();
if (jwt) {
headers['Authorization'] = `Bearer ${jwt}`;
}

await Promise.all(
[...new Set(fileIds)].map(async (id) => {
try {
const encodedFileId = encodeURIComponent(`${prefix}/${id}`);
const url = `${baseUrl}/sessions/${meetingDetails.sessionId}/files/${encodedFileId}`;
const url = `${baseUrl}/download/${encodedFileId}`;
const response = await fetch(url, {
method: 'GET',
headers,
Expand Down
6 changes: 3 additions & 3 deletions packages/excalidraw/collab/Collab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ class Collab extends PureComponent<ExcalidrawCollabProps, CollabState> {

// Initialize storage backend if storageBackendUrl & jwt are provided
const { storageBackendUrl, meetingDetails } = this.props;
if (storageBackendUrl && meetingDetails?.sessionId && meetingDetails.token) {
if (storageBackendUrl && meetingDetails?.sessionId && meetingDetails.jwt) {
try {
if (!meetingDetails.sessionId) {
console.warn("Missing sessionId in whiteboard");
}
if (!meetingDetails.token) {
console.warn("Missing token in whiteboard");
if (!meetingDetails.jwt) {
console.warn("Missing jwt in whiteboard");
}
initializeBackend(storageBackendUrl, meetingDetails);
} catch (error: any) {
Expand Down
2 changes: 0 additions & 2 deletions packages/excalidraw/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,6 @@ export interface IMeetingDetails {
sessionId: string;
roomJid: string;
jwt: string;
jid: string;
token?: string;
}

export type SceneData = {
Expand Down