fix download path
This commit is contained in:
parent
36ae0438a1
commit
d5bb04a837
2 changed files with 13 additions and 6 deletions
|
|
@ -17,7 +17,7 @@ import {
|
|||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { PresentationGenerationApi } from "../../services/api/presentation-generation";
|
||||
import { apiFetch } from "@/lib/apiFetch";
|
||||
import { apiFetch, apiUrl } from "@/lib/apiFetch";
|
||||
import { OverlayLoader } from "@/components/ui/overlay-loader";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
|
|
@ -137,13 +137,14 @@ const Header = ({
|
|||
router.push(`/presentation?id=${presentation_id}&stream=true`);
|
||||
};
|
||||
const downloadLink = (path: string) => {
|
||||
const url = apiUrl(path);
|
||||
// if we have popup access give direct download if not redirect to the path
|
||||
if (window.opener) {
|
||||
window.open(path, '_blank');
|
||||
window.open(url, '_blank');
|
||||
} else {
|
||||
const link = document.createElement('a');
|
||||
link.href = path;
|
||||
link.download = path.split('/').pop() || 'download';
|
||||
link.href = url;
|
||||
link.download = url.split('/').pop() || 'download';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,18 @@
|
|||
*/
|
||||
const BASE_PATH = '/ppt-tool';
|
||||
|
||||
const PREFIXED_PATHS = ['/api/', '/app_data/', '/static/'];
|
||||
|
||||
function needsBasePath(path: string): boolean {
|
||||
return PREFIXED_PATHS.some((p) => path.startsWith(p));
|
||||
}
|
||||
|
||||
export function apiFetch(path: string, init?: RequestInit): Promise<Response> {
|
||||
const url = path.startsWith('/api/') ? `${BASE_PATH}${path}` : path;
|
||||
const url = needsBasePath(path) ? `${BASE_PATH}${path}` : path;
|
||||
return fetch(url, init);
|
||||
}
|
||||
|
||||
/** Returns the full URL with basePath — use for EventSource and other non-fetch calls. */
|
||||
export function apiUrl(path: string): string {
|
||||
return path.startsWith('/api/') ? `${BASE_PATH}${path}` : path;
|
||||
return needsBasePath(path) ? `${BASE_PATH}${path}` : path;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue