Skip to content

Commit

Permalink
fixed error with base url
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriem-BenIsmail committed Nov 19, 2024
1 parent 3126a81 commit 87dc382
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/docprovider/src/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
contentType: string;
format: string;
};
const DOCUMENT_TIMELINE_URL = 'api/collaboration/timeline';

export const TimelineSliderComponent: React.FC<Props> = ({
apiURL,
Expand Down Expand Up @@ -147,16 +148,21 @@ export const TimelineSliderComponent: React.FC<Props> = ({
function determineAction(currentTimestamp: number): 'undo' | 'redo' {
return currentTimestamp < currentTimestampIndex ? 'undo' : 'redo';
}

function extractFilenameFromURL(url: string): string {
try {
const parsedURL = new URL(url);
const pathname = parsedURL.pathname;
const segments = pathname.split('/');

return segments.slice(4 - segments.length).join('/');
const apiIndex = pathname.indexOf(DOCUMENT_TIMELINE_URL);
if (apiIndex === -1) {
throw new Error(
`API segment "${DOCUMENT_TIMELINE_URL}" not found in URL.`
);
}

return pathname.slice(apiIndex + DOCUMENT_TIMELINE_URL.length);
} catch (error) {
console.error('Invalid URL:', error);
console.error('Invalid URL or unable to extract filename:', error);
return '';
}
}
Expand Down

0 comments on commit 87dc382

Please sign in to comment.