mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
[PUI] Url fixes (#8615)
* Refactor URL generation - Use built-in URL function - Refactor "admin" button - Refactor API image - Refactor printing actions - Refactor attachment link * Refactor URL generation for icon packs
This commit is contained in:
parent
147ca53629
commit
21cd285599
@ -63,7 +63,10 @@ export default function AdminButton(props: Readonly<AdminButtonProps>) {
|
||||
}
|
||||
|
||||
// Generate the URL for the admin interface
|
||||
const url = `${host}/${server.server.django_admin}${modelDef.admin_url}${props.id}/`;
|
||||
const url = new URL(
|
||||
`${server.server.django_admin}${modelDef.admin_url}${props.id}/`,
|
||||
host
|
||||
);
|
||||
|
||||
if (event?.ctrlKey || event?.shiftKey) {
|
||||
// Open the link in a new tab
|
||||
|
@ -116,8 +116,8 @@ export function PrintingActions({
|
||||
|
||||
if (response.output) {
|
||||
// An output file was generated
|
||||
const url = `${host}${response.output}`;
|
||||
window.open(url, '_blank');
|
||||
const url = new URL(response.output, host);
|
||||
window.open(url.toString(), '_blank');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -154,8 +154,8 @@ export function PrintingActions({
|
||||
|
||||
if (response.output) {
|
||||
// An output file was generated
|
||||
const url = `${host}${response.output}`;
|
||||
window.open(url, '_blank');
|
||||
const url = new URL(response.output, host);
|
||||
window.open(url.toString(), '_blank');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ export function ApiImage(props: Readonly<ApiImageProps>) {
|
||||
const { host } = useLocalState.getState();
|
||||
|
||||
const imageUrl = useMemo(() => {
|
||||
return `${host}${props.src}`;
|
||||
return new URL(props.src, host).toString();
|
||||
}, [host, props.src]);
|
||||
|
||||
return (
|
||||
|
@ -68,7 +68,8 @@ export function AttachmentLink({
|
||||
return attachment;
|
||||
}
|
||||
|
||||
return `${host}${attachment}`;
|
||||
const u = new URL(attachment, host);
|
||||
return u.toString();
|
||||
}, [host, attachment, external]);
|
||||
|
||||
return (
|
||||
|
@ -137,7 +137,7 @@ export function AboutInvenTreeModal({
|
||||
{
|
||||
ref: 'api',
|
||||
title: <Trans>API Version</Trans>,
|
||||
link: `${host}api-doc/`,
|
||||
link: new URL('/api-doc/', host).toString(),
|
||||
copy: true
|
||||
},
|
||||
{
|
||||
|
@ -13,14 +13,11 @@ export async function loadExternalPluginSource(source: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If the source is a relative URL, prefix it with the host URL
|
||||
if (source.startsWith('/')) {
|
||||
source = `${host}${source}`;
|
||||
}
|
||||
const url = new URL(source, host).toString();
|
||||
|
||||
const module = await import(/* @vite-ignore */ source)
|
||||
const module = await import(/* @vite-ignore */ url)
|
||||
.catch((error) => {
|
||||
console.error(`ERR: Failed to load plugin from ${source}:`, error);
|
||||
console.error(`ERR: Failed to load plugin from ${url}:`, error);
|
||||
return null;
|
||||
})
|
||||
.then((module) => {
|
||||
|
@ -44,9 +44,7 @@ export const useIconState = create<IconState>()((set, get) => ({
|
||||
const src = Object.entries(pack.fonts as Record<string, string>)
|
||||
.map(
|
||||
([format, url]) =>
|
||||
`url(${
|
||||
url.startsWith('/') ? host + url : url
|
||||
}) format("${format}")`
|
||||
`url(${new URL(url, host).toString()}) format("${format}")`
|
||||
)
|
||||
.join(',\n');
|
||||
const font = new FontFace(fontName, `${src};`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user