mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 06:24:44 +02:00

* update scramble * cleanup application api endpoints * cleanup client api endpoints * fix security schema and make docs homepage nicer * remove duplicate myclabs/deep-copy * style(api-docs): use Blade template and Tailwind for styling * Publish scramble view * Use localStorage theme instead of config * Update routes/docs.php Co-authored-by: Lance Pioch <git@lance.sh> --------- Co-authored-by: Quinten <67589015+QuintenQVD0@users.noreply.github.com> Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Co-authored-by: Lance Pioch <git@lance.sh>
73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<title>{{ $config->get('ui.title', config('app.name') . ' - API Docs') }}</title>
|
|
|
|
<script src="https://unpkg.com/@stoplight/elements@8.3.4/web-components.min.js"></script>
|
|
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements@8.3.4/styles.min.css">
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') === 'system'
|
|
? (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
|
|
: localStorage.getItem('theme') ?? 'dark';
|
|
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
|
|
const originalFetch = window.fetch;
|
|
|
|
// intercept TryIt requests and add the XSRF-TOKEN header,
|
|
// which is necessary for Sanctum cookie-based authentication to work correctly
|
|
window.fetch = (url, options) => {
|
|
const CSRF_TOKEN_COOKIE_KEY = "XSRF-TOKEN";
|
|
const CSRF_TOKEN_HEADER_KEY = "X-XSRF-TOKEN";
|
|
const getCookieValue = (key) => {
|
|
const cookie = document.cookie.split(';').find((cookie) => cookie.trim().startsWith(key));
|
|
return cookie?.split("=")[1];
|
|
};
|
|
|
|
const updateFetchHeaders = (
|
|
headers,
|
|
headerKey,
|
|
headerValue,
|
|
) => {
|
|
if (headers instanceof Headers) {
|
|
headers.set(headerKey, headerValue);
|
|
} else if (Array.isArray(headers)) {
|
|
headers.push([headerKey, headerValue]);
|
|
} else if (headers) {
|
|
headers[headerKey] = headerValue;
|
|
}
|
|
};
|
|
const csrfToken = getCookieValue(CSRF_TOKEN_COOKIE_KEY);
|
|
if (csrfToken) {
|
|
const { headers = new Headers() } = options || {};
|
|
updateFetchHeaders(headers, CSRF_TOKEN_HEADER_KEY, decodeURIComponent(csrfToken));
|
|
return originalFetch(url, {
|
|
...options,
|
|
headers,
|
|
});
|
|
}
|
|
|
|
return originalFetch(url, options);
|
|
};
|
|
</script>
|
|
</head>
|
|
<body style="height: 100vh; overflow-y: hidden">
|
|
<elements-api
|
|
id="docs"
|
|
tryItCredentialsPolicy="{{ $config->get('ui.try_it_credentials_policy', 'include') }}"
|
|
router="hash"
|
|
@if($config->get('ui.hide_try_it')) hideTryIt="true" @endif
|
|
logo="{{ $config->get('ui.logo') }}"
|
|
/>
|
|
<script>
|
|
(async () => {
|
|
const docs = document.getElementById('docs');
|
|
docs.apiDescriptionDocument = @json($spec);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|