zu fabricjs gewechselt, noch nicht funktionsfähig

This commit is contained in:
Codex Agent
2025-10-31 20:19:09 +01:00
parent 06df61f706
commit eb0c31c90b
33 changed files with 7718 additions and 2062 deletions

View File

@@ -115,60 +115,72 @@ if (import.meta.env.DEV || import.meta.env.VITE_ENABLE_TENANT_SWITCHER === 'true
globalThis.fotospielDemoAuth = api;
}
function requestAuthorization(url: string, fallbackRedirect?: string): Promise<URL> {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.withCredentials = true;
xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = () => {
if (xhr.readyState !== XMLHttpRequest.DONE) {
return;
async function requestAuthorization(url: string, fallbackRedirect?: string): Promise<URL> {
const requestUrl = new URL(url, window.location.origin);
let response: Response;
try {
response = await fetch(requestUrl.toString(), {
method: 'GET',
credentials: 'include',
headers: {
Accept: 'application/json, text/plain, */*',
'X-Requested-With': 'XMLHttpRequest',
},
redirect: 'manual',
});
} catch (error) {
throw new Error('Authorize request failed');
}
const status = response.status;
const isSuccess = (status >= 200 && status < 400) || status === 0;
if (!isSuccess) {
throw new Error(`Authorize failed with ${status}`);
}
const contentType = response.headers.get('Content-Type') ?? '';
if (contentType.includes('application/json')) {
try {
const payload = (await response.json()) as {
code?: string;
state?: string | null;
redirect_url?: string | null;
};
const target = payload.redirect_url ?? fallbackRedirect;
if (!target) {
throw new Error('Authorize response missing redirect target');
}
const contentType = xhr.getResponseHeader('Content-Type') ?? '';
const responseUrl = xhr.responseURL || xhr.getResponseHeader('Location');
if ((xhr.status >= 200 && xhr.status < 400) || xhr.status === 0) {
if (responseUrl) {
resolve(new URL(responseUrl, window.location.origin));
return;
}
if (contentType.includes('application/json')) {
try {
const payload = JSON.parse(xhr.responseText ?? '{}') as {
code?: string;
state?: string | null;
redirect_url?: string | null;
};
const target = payload.redirect_url ?? fallbackRedirect;
if (!target) {
throw new Error('Authorize response missing redirect target');
}
const finalUrl = new URL(target, window.location.origin);
if (payload.code && !finalUrl.searchParams.has('code')) {
finalUrl.searchParams.set('code', payload.code);
}
if (payload.state && !finalUrl.searchParams.has('state')) {
finalUrl.searchParams.set('state', payload.state);
}
resolve(finalUrl);
return;
} catch (error) {
reject(error instanceof Error ? error : new Error(String(error)));
return;
}
}
const finalUrl = new URL(target, window.location.origin);
if (payload.code && !finalUrl.searchParams.has('code')) {
finalUrl.searchParams.set('code', payload.code);
}
if (payload.state && !finalUrl.searchParams.has('state')) {
finalUrl.searchParams.set('state', payload.state);
}
reject(new Error(`Authorize failed with ${xhr.status}`));
};
xhr.onerror = () => reject(new Error('Authorize request failed'));
xhr.send();
});
return finalUrl;
} catch (error) {
throw error instanceof Error ? error : new Error(String(error));
}
}
const locationHeader = response.headers.get('Location');
if (locationHeader) {
return new URL(locationHeader, window.location.origin);
}
if (response.url && response.url !== requestUrl.toString()) {
return new URL(response.url, window.location.origin);
}
if (fallbackRedirect) {
return new URL(fallbackRedirect, window.location.origin);
}
throw new Error('Authorize response missing redirect target');
}
function verifyState(returnedState: string | null, expectedState: string): void {