mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 09:16:01 +00:00
refactor - handle cloud listeners
This commit is contained in:
@@ -59,6 +59,7 @@ module.exports = {
|
|||||||
async putContent({ folid, cntid, content, name, type }) {
|
async putContent({ folid, cntid, content, name, type }) {
|
||||||
const resp = await putCloudContent(folid, cntid, content, name, type);
|
const resp = await putCloudContent(folid, cntid, content, name, type);
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ module.exports = {
|
|||||||
async createFolder({ name }) {
|
async createFolder({ name }) {
|
||||||
const resp = await callCloudApiPost(`folders/create`, { name });
|
const resp = await callCloudApiPost(`folders/create`, { name });
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -80,6 +82,7 @@ module.exports = {
|
|||||||
|
|
||||||
const resp = await callCloudApiPost(`folders/grant/${mode}`, { invite });
|
const resp = await callCloudApiPost(`folders/grant/${mode}`, { invite });
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -87,6 +90,7 @@ module.exports = {
|
|||||||
async renameFolder({ folid, name }) {
|
async renameFolder({ folid, name }) {
|
||||||
const resp = await callCloudApiPost(`folders/rename`, { folid, name });
|
const resp = await callCloudApiPost(`folders/rename`, { folid, name });
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -94,6 +98,7 @@ module.exports = {
|
|||||||
async deleteFolder({ folid }) {
|
async deleteFolder({ folid }) {
|
||||||
const resp = await callCloudApiPost(`folders/delete`, { folid });
|
const resp = await callCloudApiPost(`folders/delete`, { folid });
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -106,6 +111,7 @@ module.exports = {
|
|||||||
refreshContent_meta: true,
|
refreshContent_meta: true,
|
||||||
async refreshContent() {
|
async refreshContent() {
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
};
|
};
|
||||||
@@ -156,6 +162,7 @@ module.exports = {
|
|||||||
removeCloudCachedConnection(folid, resp.cntid);
|
removeCloudCachedConnection(folid, resp.cntid);
|
||||||
cntid = resp.cntid;
|
cntid = resp.cntid;
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return {
|
return {
|
||||||
...recryptedConn,
|
...recryptedConn,
|
||||||
_id: `cloud://${folid}/${cntid}`,
|
_id: `cloud://${folid}/${cntid}`,
|
||||||
|
|||||||
@@ -320,6 +320,7 @@ async function putCloudContent(folid, cntid, content, name, type) {
|
|||||||
signinHolder
|
signinHolder
|
||||||
);
|
);
|
||||||
socket.emitChanged('cloud-content-changed');
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
socket.emit('cloud-content-updated');
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
import { handleAuthOnStartup } from './clientAuth';
|
import { handleAuthOnStartup } from './clientAuth';
|
||||||
import { initializeAppUpdates } from './utility/appUpdate';
|
import { initializeAppUpdates } from './utility/appUpdate';
|
||||||
import { _t } from './translations';
|
import { _t } from './translations';
|
||||||
|
import { installCloudListeners } from './utility/cloudListeners';
|
||||||
|
|
||||||
export let isAdminPage = false;
|
export let isAdminPage = false;
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@
|
|||||||
installNewVolatileConnectionListener();
|
installNewVolatileConnectionListener();
|
||||||
installNewCloudTokenListener();
|
installNewCloudTokenListener();
|
||||||
initializeAppUpdates();
|
initializeAppUpdates();
|
||||||
|
installCloudListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshPublicCloudFiles();
|
refreshPublicCloudFiles();
|
||||||
|
|||||||
@@ -457,4 +457,10 @@ focusedTreeDbKey.subscribe(value => {
|
|||||||
});
|
});
|
||||||
export const getFocusedTreeDbKey = () => focusedTreeDbKeyValue;
|
export const getFocusedTreeDbKey = () => focusedTreeDbKeyValue;
|
||||||
|
|
||||||
|
let cloudConnectionsStoreValue = {};
|
||||||
|
cloudConnectionsStore.subscribe(value => {
|
||||||
|
cloudConnectionsStoreValue = value;
|
||||||
|
});
|
||||||
|
export const getCloudConnectionsStore = () => cloudConnectionsStoreValue;
|
||||||
|
|
||||||
window['__changeCurrentTheme'] = theme => currentTheme.set(theme);
|
window['__changeCurrentTheme'] = theme => currentTheme.set(theme);
|
||||||
|
|||||||
48
packages/web/src/utility/cloudListeners.ts
Normal file
48
packages/web/src/utility/cloudListeners.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { derived } from 'svelte/store';
|
||||||
|
import {
|
||||||
|
cloudConnectionsStore,
|
||||||
|
currentDatabase,
|
||||||
|
getCloudConnectionsStore,
|
||||||
|
openedConnections,
|
||||||
|
openedSingleDatabaseConnections,
|
||||||
|
} from '../stores';
|
||||||
|
import { apiCall, apiOn } from './api';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export const possibleCloudConnectionSources = derived(
|
||||||
|
[currentDatabase, openedSingleDatabaseConnections, openedConnections],
|
||||||
|
([$currentDatabase, $openedSingleDatabaseConnections, $openedConnections]) => {
|
||||||
|
const conids = new Set<string>();
|
||||||
|
if ($currentDatabase?.connection?._id) {
|
||||||
|
conids.add($currentDatabase.connection._id);
|
||||||
|
}
|
||||||
|
$openedSingleDatabaseConnections.forEach(x => conids.add(x));
|
||||||
|
$openedConnections.forEach(x => conids.add(x));
|
||||||
|
return Array.from(conids).filter(x => x?.startsWith('cloud://'));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
async function loadCloudConnection(conid) {
|
||||||
|
const conn = await apiCall('connections/get', { conid });
|
||||||
|
cloudConnectionsStore.update(store => ({
|
||||||
|
...store,
|
||||||
|
[conid]: conn,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureCloudConnectionsLoaded(...conids) {
|
||||||
|
const conns = getCloudConnectionsStore();
|
||||||
|
_.uniq(conids).forEach(conid => {
|
||||||
|
if (!conns[conid]) {
|
||||||
|
loadCloudConnection(conid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function installCloudListeners() {
|
||||||
|
possibleCloudConnectionSources.subscribe(conids => {
|
||||||
|
ensureCloudConnectionsLoaded(...conids);
|
||||||
|
});
|
||||||
|
|
||||||
|
apiOn('cloud-content-updated', () => cloudConnectionsStore.set({}));
|
||||||
|
}
|
||||||
@@ -67,27 +67,27 @@
|
|||||||
await apiCall('cloud/refresh-content');
|
await apiCall('cloud/refresh-content');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCloudConnection(conid) {
|
// async function loadCloudConnection(conid) {
|
||||||
const conn = await apiCall('connections/get', { conid });
|
// const conn = await apiCall('connections/get', { conid });
|
||||||
$cloudConnectionsStore = {
|
// $cloudConnectionsStore = {
|
||||||
...$cloudConnectionsStore,
|
// ...$cloudConnectionsStore,
|
||||||
[conid]: conn,
|
// [conid]: conn,
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ensureCloudConnectionsLoaded(...conids) {
|
// function ensureCloudConnectionsLoaded(...conids) {
|
||||||
_.uniq(conids).forEach(conid => {
|
// _.uniq(conids).forEach(conid => {
|
||||||
if (conid?.startsWith('cloud://') && !$cloudConnectionsStore[conid]) {
|
// if (conid?.startsWith('cloud://') && !$cloudConnectionsStore[conid]) {
|
||||||
loadCloudConnection(conid);
|
// loadCloudConnection(conid);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
$: ensureCloudConnectionsLoaded(
|
// $: ensureCloudConnectionsLoaded(
|
||||||
$currentDatabase?.connection?._id,
|
// $currentDatabase?.connection?._id,
|
||||||
...$openedSingleDatabaseConnections,
|
// ...$openedSingleDatabaseConnections,
|
||||||
...$openedConnections
|
// ...$openedConnections
|
||||||
);
|
// );
|
||||||
|
|
||||||
// onMount(() => {
|
// onMount(() => {
|
||||||
// const currentConid = $currentDatabase?.connection?._id;
|
// const currentConid = $currentDatabase?.connection?._id;
|
||||||
|
|||||||
Reference in New Issue
Block a user