gitea source for verification 2026-05-22
This commit is contained in:
15
web_src/js/standalone/devtest.ts
Normal file
15
web_src/js/standalone/devtest.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import {showInfoToast, showWarningToast, showErrorToast} from '../modules/toast.ts';
|
||||
|
||||
function initDevtestToast() {
|
||||
const levelMap: Record<string, any> = {info: showInfoToast, warning: showWarningToast, error: showErrorToast};
|
||||
for (const el of document.querySelectorAll('.toast-test-button')) {
|
||||
el.addEventListener('click', () => {
|
||||
const level = el.getAttribute('data-toast-level');
|
||||
const message = el.getAttribute('data-toast-message');
|
||||
levelMap[level](message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// NOTICE: keep in mind that this file is not in "index.js", they do not share the same module system.
|
||||
initDevtestToast();
|
||||
43
web_src/js/standalone/external-render-iframe.ts
Normal file
43
web_src/js/standalone/external-render-iframe.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/* To manually test:
|
||||
|
||||
[markup.in-iframe]
|
||||
ENABLED = true
|
||||
FILE_EXTENSIONS = .in-iframe
|
||||
RENDER_CONTENT_MODE = iframe
|
||||
RENDER_COMMAND = `echo '<div style="width: 100%; height: 2000px; border: 10px solid red; box-sizing: border-box;"><a href="/">a link</a> <a target="_blank" href="//gitea.com">external link</a></div>'`
|
||||
|
||||
;RENDER_COMMAND = cat /path/to/file.pdf
|
||||
;RENDER_CONTENT_SANDBOX = disabled
|
||||
|
||||
*/
|
||||
|
||||
function mainExternalRenderIframe() {
|
||||
const u = new URL(window.location.href);
|
||||
const iframeId = u.searchParams.get('gitea-iframe-id');
|
||||
|
||||
// iframe is in different origin, so we need to use postMessage to communicate
|
||||
const postIframeMsg = (cmd: string, data: Record<string, any> = {}) => {
|
||||
window.parent.postMessage({giteaIframeCmd: cmd, giteaIframeId: iframeId, ...data}, '*');
|
||||
};
|
||||
|
||||
const updateIframeHeight = () => postIframeMsg('resize', {iframeHeight: document.documentElement.scrollHeight});
|
||||
updateIframeHeight();
|
||||
window.addEventListener('DOMContentLoaded', updateIframeHeight);
|
||||
// the easiest way to handle dynamic content changes and easy to debug, can be fine-tuned in the future
|
||||
setInterval(updateIframeHeight, 1000);
|
||||
|
||||
// no way to open an absolute link with CSP frame-src, it also needs some tricks like "postMessage" or "copy the link to clipboard"
|
||||
const openIframeLink = (link: string, target: string) => postIframeMsg('open-link', {openLink: link, anchorTarget: target});
|
||||
document.addEventListener('click', (e) => {
|
||||
const el = e.target as HTMLAnchorElement;
|
||||
if (el.nodeName !== 'A') return;
|
||||
const href = el.getAttribute('href') || '';
|
||||
// safe links: "./any", "../any", "/any", "//host/any", "http://host/any", "https://host/any"
|
||||
if (href.startsWith('.') || href.startsWith('/') || href.startsWith('http://') || href.startsWith('https://')) {
|
||||
e.preventDefault();
|
||||
openIframeLink(href, el.getAttribute('target'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mainExternalRenderIframe();
|
||||
30
web_src/js/standalone/swagger.ts
Normal file
30
web_src/js/standalone/swagger.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import SwaggerUI from 'swagger-ui-dist/swagger-ui-es-bundle.js';
|
||||
import 'swagger-ui-dist/swagger-ui.css';
|
||||
|
||||
window.addEventListener('load', async () => {
|
||||
const url = document.querySelector('#swagger-ui').getAttribute('data-source');
|
||||
const res = await fetch(url);
|
||||
const spec = await res.json();
|
||||
|
||||
// Make the page's protocol be at the top of the schemes list
|
||||
const proto = window.location.protocol.slice(0, -1);
|
||||
spec.schemes.sort((a: string, b: string) => {
|
||||
if (a === proto) return -1;
|
||||
if (b === proto) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
SwaggerUI({
|
||||
spec,
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
docExpansion: 'none',
|
||||
defaultModelRendering: 'model', // don't show examples by default, because they may be incomplete
|
||||
presets: [
|
||||
SwaggerUI.presets.apis,
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUI.plugins.DownloadUrl,
|
||||
],
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user