SYNC: configurable export watermark

This commit is contained in:
SPRINX0\prochazka
2025-04-01 10:40:45 +02:00
committed by Diflow
parent 3f98f9ff39
commit 4bc9b70882
4 changed files with 25 additions and 4 deletions

View File

@@ -195,8 +195,8 @@ module.exports = {
}, },
exportDiagram_meta: true, exportDiagram_meta: true,
async exportDiagram({ filePath, html, css, themeType, themeClassName }) { async exportDiagram({ filePath, html, css, themeType, themeClassName, watermark }) {
await fs.writeFile(filePath, getDiagramExport(html, css, themeType, themeClassName)); await fs.writeFile(filePath, getDiagramExport(html, css, themeType, themeClassName, watermark));
return true; return true;
}, },

View File

@@ -1,4 +1,11 @@
const getDiagramExport = (html, css, themeType, themeClassName) => { const getDiagramExport = (html, css, themeType, themeClassName, watermark) => {
const watermarkHtml = watermark
? `
<div style="position: fixed; bottom: 0; right: 0; padding: 5px; font-size: 12px; color: var(--theme-font-2); background-color: var(--theme-bg-2); border-top-left-radius: 5px; border: 1px solid var(--theme-border);">
${watermark}
</div>
`
: '';
return `<html> return `<html>
<meta charset='utf-8'> <meta charset='utf-8'>
@@ -17,6 +24,7 @@ const getDiagramExport = (html, css, themeType, themeClassName) => {
<body class='${themeType == 'dark' ? 'theme-type-dark' : 'theme-type-light'} ${themeClassName}'> <body class='${themeType == 'dark' ? 'theme-type-dark' : 'theme-type-light'} ${themeClassName}'>
${html} ${html}
${watermarkHtml}
</body> </body>
</html>`; </html>`;

View File

@@ -59,3 +59,5 @@ export function chooseTopTables(tables: TableInfo[], count: number, tableFilter:
} }
export const DIAGRAM_ZOOMS = [0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1, 1.25, 1.5, 1.75, 2]; export const DIAGRAM_ZOOMS = [0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1, 1.25, 1.5, 1.75, 2];
export const DIAGRAM_DEFAULT_WATERMARK = 'Powered by [dbgate.io](https://dbgate.io)';

View File

@@ -47,7 +47,7 @@
import { showModal } from '../modals/modalTools'; import { showModal } from '../modals/modalTools';
import ChooseColorModal from '../modals/ChooseColorModal.svelte'; import ChooseColorModal from '../modals/ChooseColorModal.svelte';
import { currentThemeDefinition } from '../stores'; import { currentThemeDefinition } from '../stores';
import { chooseTopTables, DIAGRAM_ZOOMS, extendDatabaseInfoFromApps } from 'dbgate-tools'; import { chooseTopTables, DIAGRAM_DEFAULT_WATERMARK, DIAGRAM_ZOOMS, extendDatabaseInfoFromApps } from 'dbgate-tools';
import SearchInput from '../elements/SearchInput.svelte'; import SearchInput from '../elements/SearchInput.svelte';
import CloseSearchButton from '../buttons/CloseSearchButton.svelte'; import CloseSearchButton from '../buttons/CloseSearchButton.svelte';
import DragColumnMemory from './DragColumnMemory.svelte'; import DragColumnMemory from './DragColumnMemory.svelte';
@@ -763,6 +763,16 @@
); );
} }
function getWatermarkHtml() {
const replaceLinks = text => text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" style="color: var(--theme-font-link)" target="_blank">$1</a>');
if (value?.style?.omitExportWatermark) return null;
if (value?.style?.exportWatermark) {
return replaceLinks(value?.style?.exportWatermark);
}
return replaceLinks(DIAGRAM_DEFAULT_WATERMARK);
}
export async function exportDiagram() { export async function exportDiagram() {
const cssLinks = ['global.css', 'build/bundle.css']; const cssLinks = ['global.css', 'build/bundle.css'];
let css = ''; let css = '';
@@ -784,6 +794,7 @@
css, css,
themeType: $currentThemeDefinition?.themeType, themeType: $currentThemeDefinition?.themeType,
themeClassName: $currentThemeDefinition?.themeClassName, themeClassName: $currentThemeDefinition?.themeClassName,
watermark: getWatermarkHtml(),
}); });
}); });
} }