mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 21:26:00 +00:00
html files for pages
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -31,4 +31,6 @@ yarn-error.log*
|
||||
app/src/nativeModulesContent.js
|
||||
packages/api/src/nativeModulesContent.js
|
||||
packages/api/src/packagedPluginsContent.js
|
||||
.VSCodeCounter
|
||||
.VSCodeCounter
|
||||
|
||||
pacgaes/web/public/*.html
|
||||
8
packages/web/build-index.js
Normal file
8
packages/web/build-index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const template = fs.readFileSync('./index.html.tpl', 'utf-8');
|
||||
|
||||
for (const page of ['', 'not-logged', 'error', 'admin-login', 'login', 'admin', 'license']) {
|
||||
const text = template.replace(/{{page}}/g, page);
|
||||
fs.writeFileSync(`public/${page || 'index'}.html`, text);
|
||||
}
|
||||
@@ -22,6 +22,11 @@
|
||||
<link rel="stylesheet" href="build/fonts/materialdesignicons.css" />
|
||||
<link rel="stylesheet" href="build/diff2html.min.css" />
|
||||
|
||||
<script lang="javascript">
|
||||
window.dbgate_page = '{{page}}';
|
||||
</script>
|
||||
|
||||
|
||||
<script defer src="build/bundle.js"></script>
|
||||
|
||||
<style>
|
||||
@@ -2,10 +2,11 @@
|
||||
"name": "dbgate-web",
|
||||
"version": "5.0.0-alpha.1",
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"dev": "cross-env API_URL=http://localhost:3000 rollup -c -w",
|
||||
"build": "yarn build:index && rollup -c",
|
||||
"dev": "yarn build:index && cross-env API_URL=http://localhost:3000 rollup -c -w",
|
||||
"start": "sirv public --port 5001",
|
||||
"validate": "svelte-check",
|
||||
"build:index": "node build-index.js",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
});
|
||||
if (resp.error) {
|
||||
internalRedirectTo(
|
||||
`/?page=not-logged&error=${encodeURIComponent(resp.error)}&is-admin=${isAdminPage ? 'true' : ''}`
|
||||
`/not-logged.html?error=${encodeURIComponent(resp.error)}&is-admin=${isAdminPage ? 'true' : ''}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -111,13 +111,13 @@
|
||||
if (accessToken) {
|
||||
localStorage.setItem(isAdminPage ? 'adminAccessToken' : 'accessToken', accessToken);
|
||||
if (isAdminPage) {
|
||||
internalRedirectTo('/?page=admin');
|
||||
internalRedirectTo('/admin.html');
|
||||
} else {
|
||||
internalRedirectTo('/');
|
||||
}
|
||||
return;
|
||||
}
|
||||
internalRedirectTo(`/?page=not-logged`);
|
||||
internalRedirectTo(`/not-logged.html`);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export function handleOauthCallback() {
|
||||
internalRedirectTo('/');
|
||||
} else {
|
||||
console.log('Error when processing OAUTH callback', error || errorMessage);
|
||||
internalRedirectTo(`/?page=not-logged&error=${error || errorMessage}`);
|
||||
internalRedirectTo(`/not-logged.html?error=${error || errorMessage}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,9 +81,9 @@ export function handleOauthCallback() {
|
||||
if (authResp.success) {
|
||||
window.close();
|
||||
} else if (authResp.error) {
|
||||
internalRedirectTo(`/?page=error&error=${encodeURIComponent(authResp.error)}`);
|
||||
internalRedirectTo(`/error.html?error=${encodeURIComponent(authResp.error)}`);
|
||||
} else {
|
||||
internalRedirectTo(`/?page=error`);
|
||||
internalRedirectTo(`/error.html`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -105,9 +105,9 @@ export function handleOauthCallback() {
|
||||
localStorage.setItem('accessToken', authResp.accessToken);
|
||||
internalRedirectTo('/');
|
||||
} else if (authResp.error) {
|
||||
internalRedirectTo(`/?page=error&error=${encodeURIComponent(authResp.error)}`);
|
||||
internalRedirectTo(`/error.html?error=${encodeURIComponent(authResp.error)}`);
|
||||
} else {
|
||||
internalRedirectTo(`/?page=error`);
|
||||
internalRedirectTo(`/error.html`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,15 +119,15 @@ export function handleOauthCallback() {
|
||||
|
||||
export async function handleAuthOnStartup(config, isAdminPage = false) {
|
||||
if (config.configurationError) {
|
||||
internalRedirectTo(`/?page=error`);
|
||||
internalRedirectTo(`/error.html`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.isLicenseValid) {
|
||||
if (config.storageDatabase || getElectron()) {
|
||||
internalRedirectTo(`/?page=license`);
|
||||
internalRedirectTo(`/license.html`);
|
||||
} else {
|
||||
internalRedirectTo(`/?page=error`);
|
||||
internalRedirectTo(`/error.html`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ export async function handleAuthOnStartup(config, isAdminPage = false) {
|
||||
}
|
||||
|
||||
export async function redirectToAdminLogin() {
|
||||
internalRedirectTo('/?page=admin-login');
|
||||
internalRedirectTo('/admin-login.html');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,12 +165,12 @@ export async function redirectToLogin(config = null, force = false) {
|
||||
|
||||
if (getAuthCategory(config) == 'token') {
|
||||
if (!force) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
if (params.get('page') == 'login' || params.get('page') == 'admin-login' || params.get('page') == 'not-logged') {
|
||||
const page = window['dbgate_page']
|
||||
if (page == 'login' || page == 'admin-login' || page == 'not-logged') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
internalRedirectTo('/?page=login');
|
||||
internalRedirectTo('/login.html');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -201,13 +201,13 @@ export async function doLogout() {
|
||||
|
||||
if (category == 'admin') {
|
||||
localStorage.removeItem('adminAccessToken');
|
||||
internalRedirectTo('/?page=admin-login&is-admin=true');
|
||||
internalRedirectTo('/admin-login.html?is-admin=true');
|
||||
} else if (category == 'token') {
|
||||
localStorage.removeItem('accessToken');
|
||||
if (config.logoutUrl) {
|
||||
window.location.href = config.logoutUrl;
|
||||
} else {
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
internalRedirectTo('/not-logged.html');
|
||||
}
|
||||
} else if (category == 'basic') {
|
||||
window.location.href = 'config/logout';
|
||||
|
||||
@@ -9,9 +9,6 @@ import NotLoggedPage from './NotLoggedPage.svelte';
|
||||
import ErrorPage from './ErrorPage.svelte';
|
||||
import EnterLicensePage from './EnterLicensePage.svelte';
|
||||
|
||||
const params = new URLSearchParams(location.search);
|
||||
const page = params.get('page');
|
||||
|
||||
const isOauthCallback = handleOauthCallback();
|
||||
|
||||
localStorageGarbageCollector();
|
||||
@@ -21,7 +18,7 @@ function createApp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (page) {
|
||||
switch (window['dbgate_page']) {
|
||||
case 'login':
|
||||
return new LoginPage({
|
||||
target: document.body,
|
||||
|
||||
@@ -175,13 +175,13 @@ export async function apiCall(route: string, args: {} = undefined) {
|
||||
});
|
||||
|
||||
if (resp.status == 401 && !apiDisabled) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const page = window['dbgate_page'];
|
||||
|
||||
disableApi();
|
||||
console.log('Disabling API', route);
|
||||
if (params.get('page') != 'login' && params.get('page') != 'admin-login' && params.get('page') != 'not-logged') {
|
||||
if (page != 'login' && page != 'admin-login' && page != 'not-logged') {
|
||||
// unauthorized
|
||||
if (params.get('page') == 'admin') {
|
||||
if (page == 'admin') {
|
||||
redirectToAdminLogin();
|
||||
} else {
|
||||
redirectToLogin();
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
let isAdminPageCache;
|
||||
|
||||
export function isAdminPage() {
|
||||
if (isAdminPageCache == null) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const urlPage = params.get('page');
|
||||
|
||||
isAdminPageCache = urlPage == 'admin';
|
||||
}
|
||||
return isAdminPageCache;
|
||||
return window['dbgate_page'] == 'admin';
|
||||
}
|
||||
|
||||
export function getOpenedTabsStorageName() {
|
||||
|
||||
Reference in New Issue
Block a user