mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 18:46:00 +00:00
ask password works!
This commit is contained in:
@@ -16,6 +16,7 @@ let apiDisabled = false;
|
||||
const disabledOnOauth = isOauthCallback();
|
||||
|
||||
const volatileConnectionMap = {};
|
||||
const volatileConnectionMapInv = {};
|
||||
|
||||
export function disableApi() {
|
||||
apiDisabled = true;
|
||||
@@ -27,12 +28,17 @@ export function enableApi() {
|
||||
|
||||
export function setVolatileConnectionRemapping(existingConnectionId, volatileConnectionId) {
|
||||
volatileConnectionMap[existingConnectionId] = volatileConnectionId;
|
||||
volatileConnectionMapInv[volatileConnectionId] = existingConnectionId;
|
||||
}
|
||||
|
||||
export function getVolatileRemapping(conid) {
|
||||
return volatileConnectionMap[conid] || conid;
|
||||
}
|
||||
|
||||
export function getVolatileRemappingInv(conid) {
|
||||
return volatileConnectionMapInv[conid] || conid;
|
||||
}
|
||||
|
||||
function wantEventSource() {
|
||||
if (!eventSource) {
|
||||
eventSource = new EventSource(`${resolveApi()}/stream`);
|
||||
@@ -64,7 +70,7 @@ function processApiResponse(route, args, resp) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
function transformApiArgs(args) {
|
||||
export function transformApiArgs(args) {
|
||||
return _.mapValues(args, (v, k) => {
|
||||
if (k == 'conid' && v && volatileConnectionMap[v]) return volatileConnectionMap[v];
|
||||
if (k == 'conidArray' && _.isArray(v)) return v.map(x => volatileConnectionMap[x] || x);
|
||||
@@ -72,6 +78,14 @@ function transformApiArgs(args) {
|
||||
});
|
||||
}
|
||||
|
||||
export function transformApiArgsInv(args) {
|
||||
return _.mapValues(args, (v, k) => {
|
||||
if (k == 'conid' && v && volatileConnectionMapInv[v]) return volatileConnectionMapInv[v];
|
||||
if (k == 'conidArray' && _.isArray(v)) return v.map(x => volatileConnectionMapInv[x] || x);
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
export async function apiCall(route: string, args: {} = undefined) {
|
||||
if (apiLogging) {
|
||||
console.log('>>> API CALL', route, args);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { apiOn } from './api';
|
||||
import { apiOn, transformApiArgsInv } from './api';
|
||||
import getAsArray from './getAsArray';
|
||||
import stableStringify from 'json-stable-stringify';
|
||||
|
||||
@@ -34,7 +34,7 @@ function cacheSet(cacheKey, value, reloadTrigger, generation) {
|
||||
function cacheClean(reloadTrigger) {
|
||||
cacheGeneration += 1;
|
||||
for (const item of getAsArray(reloadTrigger)) {
|
||||
const itemString = stableStringify(item);
|
||||
const itemString = stableStringify(transformApiArgsInv(item));
|
||||
const keys = cachedKeysByReloadTrigger[itemString];
|
||||
if (keys) {
|
||||
for (const key of keys) {
|
||||
@@ -80,7 +80,8 @@ export async function loadCachedValue(reloadTrigger, cacheKey, func) {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error when using cached promise', err);
|
||||
cacheClean(cacheKey);
|
||||
// cacheClean(cacheKey);
|
||||
cacheClean(reloadTrigger);
|
||||
const res = await func();
|
||||
cacheSet(cacheKey, res, reloadTrigger, generation);
|
||||
return res;
|
||||
@@ -113,11 +114,10 @@ export async function unsubscribeCacheChange(reloadTrigger, cacheKey, reloadHand
|
||||
}
|
||||
|
||||
export function dispatchCacheChange(reloadTrigger) {
|
||||
// console.log('CHANGE', reloadTrigger);
|
||||
cacheClean(reloadTrigger);
|
||||
|
||||
for (const item of getAsArray(reloadTrigger)) {
|
||||
const itemString = stableStringify(item);
|
||||
const itemString = stableStringify(transformApiArgsInv(item));
|
||||
if (subscriptionsByReloadTrigger[itemString]) {
|
||||
for (const handler of subscriptionsByReloadTrigger[itemString]) {
|
||||
handler();
|
||||
@@ -126,4 +126,13 @@ export function dispatchCacheChange(reloadTrigger) {
|
||||
}
|
||||
}
|
||||
|
||||
export function batchDispatchCacheTriggers(predicate) {
|
||||
for (const key in subscriptionsByReloadTrigger) {
|
||||
const relaodTrigger = JSON.parse(key);
|
||||
if (predicate(relaodTrigger)) {
|
||||
dispatchCacheChange(relaodTrigger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apiOn('changed-cache', reloadTrigger => dispatchCacheChange(reloadTrigger));
|
||||
|
||||
@@ -29,12 +29,12 @@ export function subscribeConnectionPingers() {
|
||||
openedConnections.subscribe(value => {
|
||||
doServerPing(value);
|
||||
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
|
||||
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000);
|
||||
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 20 * 1000);
|
||||
});
|
||||
|
||||
currentDatabase.subscribe(value => {
|
||||
doDatabasePing(value);
|
||||
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
|
||||
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000);
|
||||
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 20 * 1000);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user