mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 17:46:00 +00:00
connecting to cloud database
This commit is contained in:
@@ -8,9 +8,10 @@ const {
|
|||||||
} = require('../utility/cloudIntf');
|
} = require('../utility/cloudIntf');
|
||||||
const connections = require('./connections');
|
const connections = require('./connections');
|
||||||
const socket = require('../utility/socket');
|
const socket = require('../utility/socket');
|
||||||
const { decryptConnection, recryptConnection, getInternalEncryptor } = require('../utility/crypting');
|
const { recryptConnection, getInternalEncryptor } = require('../utility/crypting');
|
||||||
const { getConnectionLabel, getLogger, extractErrorLogData } = require('dbgate-tools');
|
const { getConnectionLabel, getLogger, extractErrorLogData } = require('dbgate-tools');
|
||||||
const logger = getLogger('cloud');
|
const logger = getLogger('cloud');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publicFiles_meta: true,
|
publicFiles_meta: true,
|
||||||
@@ -47,8 +48,8 @@ module.exports = {
|
|||||||
|
|
||||||
getContent_meta: true,
|
getContent_meta: true,
|
||||||
async getContent({ folid, cntid }) {
|
async getContent({ folid, cntid }) {
|
||||||
const resp = await callCloudApiGet(`content/${folid}/${cntid}`);
|
const { content, name, type } = await callCloudApiGet(`content/${folid}/${cntid}`);
|
||||||
return resp;
|
return { content, name, type };
|
||||||
},
|
},
|
||||||
|
|
||||||
putContent_meta: true,
|
putContent_meta: true,
|
||||||
@@ -95,10 +96,11 @@ module.exports = {
|
|||||||
const conn = await connections.getCore({ conid });
|
const conn = await connections.getCore({ conid });
|
||||||
const folderEncryptor = getCloudFolderEncryptor(folid);
|
const folderEncryptor = getCloudFolderEncryptor(folid);
|
||||||
const recryptedConn = recryptConnection(conn, getInternalEncryptor(), folderEncryptor);
|
const recryptedConn = recryptConnection(conn, getInternalEncryptor(), folderEncryptor);
|
||||||
|
const connToSend = _.omit(recryptedConn, ['_id']);
|
||||||
await this.putContent({
|
await this.putContent({
|
||||||
folid,
|
folid,
|
||||||
cntid: conid,
|
cntid: undefined,
|
||||||
content: JSON.stringify(recryptedConn),
|
content: JSON.stringify(connToSend),
|
||||||
name: getConnectionLabel(conn),
|
name: getConnectionLabel(conn),
|
||||||
type: 'connection',
|
type: 'connection',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -423,6 +423,16 @@ module.exports = {
|
|||||||
return volatile;
|
return volatile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cloudMatch = conid.match(/^cloud\:\/\/(.+)\/(.+)$/);
|
||||||
|
if (cloudMatch) {
|
||||||
|
const cloud = require('./cloud');
|
||||||
|
const { content } = await cloud.getContent({ folid: cloudMatch[1], cntid: cloudMatch[2] });
|
||||||
|
return {
|
||||||
|
...JSON.parse(content),
|
||||||
|
_id: conid,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const storage = require('./storage');
|
const storage = require('./storage');
|
||||||
|
|
||||||
const storageConnection = await storage.getConnection({ conid });
|
const storageConnection = await storage.getConnection({ conid });
|
||||||
|
|||||||
@@ -148,6 +148,9 @@ module.exports = {
|
|||||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||||
if (existing) return existing;
|
if (existing) return existing;
|
||||||
const connection = await connections.getCore({ conid });
|
const connection = await connections.getCore({ conid });
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error(`databaseConnections: Connection with conid="${conid}" not found`);
|
||||||
|
}
|
||||||
if (connection.passwordMode == 'askPassword' || connection.passwordMode == 'askUser') {
|
if (connection.passwordMode == 'askPassword' || connection.passwordMode == 'askUser') {
|
||||||
throw new MissingCredentialsError({ conid, passwordMode: connection.passwordMode });
|
throw new MissingCredentialsError({ conid, passwordMode: connection.passwordMode });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ module.exports = {
|
|||||||
if (existing) return existing;
|
if (existing) return existing;
|
||||||
const connection = await connections.getCore({ conid });
|
const connection = await connections.getCore({ conid });
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error(`Connection with conid="${conid}" not found`);
|
throw new Error(`serverConnections: Connection with conid="${conid}" not found`);
|
||||||
}
|
}
|
||||||
if (connection.singleDatabase) {
|
if (connection.singleDatabase) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
|
import { cloudConnectionsStore } from '../stores';
|
||||||
|
import { apiCall } from '../utility/api';
|
||||||
import AppObjectCore from './AppObjectCore.svelte';
|
import AppObjectCore from './AppObjectCore.svelte';
|
||||||
|
|
||||||
export const extractKey = data => data.cntid;
|
export const extractKey = data => data.cntid;
|
||||||
@@ -10,15 +12,44 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { filterName } from 'dbgate-tools';
|
import { filterName } from 'dbgate-tools';
|
||||||
|
import ConnectionAppObject, { openConnection } from './ConnectionAppObject.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
export let passProps;
|
||||||
|
|
||||||
function createMenu() {
|
function createMenu() {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleOpenContent() {
|
||||||
|
switch (data.type) {
|
||||||
|
case 'connection':
|
||||||
|
const conn = await apiCall('connections/get', { conid: data.conid });
|
||||||
|
$cloudConnectionsStore[data.conid] = conn;
|
||||||
|
openConnection(conn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AppObjectCore {...$$restProps} {data} icon={'img connection'} title={data.name} menu={createMenu}></AppObjectCore>
|
{#if data.conid && $cloudConnectionsStore[data.conid]}
|
||||||
|
<ConnectionAppObject
|
||||||
|
{passProps}
|
||||||
|
data={{
|
||||||
|
...$cloudConnectionsStore[data.conid],
|
||||||
|
status: data.status,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<AppObjectCore
|
||||||
|
{...$$restProps}
|
||||||
|
{data}
|
||||||
|
icon={'img connection'}
|
||||||
|
title={data.name}
|
||||||
|
menu={createMenu}
|
||||||
|
on:click={handleOpenContent}
|
||||||
|
></AppObjectCore>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.info {
|
.info {
|
||||||
|
|||||||
10
packages/web/src/appobj/SubCloudItemsList.svelte
Normal file
10
packages/web/src/appobj/SubCloudItemsList.svelte
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { cloudConnectionsStore } from '../stores';
|
||||||
|
import SubDatabaseList from './SubDatabaseList.svelte';
|
||||||
|
|
||||||
|
export let data;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if data.conid && $cloudConnectionsStore[data.conid]}
|
||||||
|
<SubDatabaseList {...$$props} data={$cloudConnectionsStore[data.conid]} />
|
||||||
|
{/if}
|
||||||
@@ -184,6 +184,8 @@ export const focusedTreeDbKey = writable<{ key: string; root: string; type: stri
|
|||||||
|
|
||||||
export const cloudSigninToken = writableSettingsValue(null, 'cloudSigninToken');
|
export const cloudSigninToken = writableSettingsValue(null, 'cloudSigninToken');
|
||||||
|
|
||||||
|
export const cloudConnectionsStore = writable({});
|
||||||
|
|
||||||
// export const cloudSigninToken = getElectron()
|
// export const cloudSigninToken = getElectron()
|
||||||
// ? writableSettingsValue(null, 'cloudSigninToken')
|
// ? writableSettingsValue(null, 'cloudSigninToken')
|
||||||
// : writableWithStorage(null, 'cloudSigninToken');
|
// : writableWithStorage(null, 'cloudSigninToken');
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import AppObjectList from '../appobj/AppObjectList.svelte';
|
import AppObjectList from '../appobj/AppObjectList.svelte';
|
||||||
import * as publicCloudFileAppObject from '../appobj/PublicCloudFileAppObject.svelte';
|
import * as publicCloudFileAppObject from '../appobj/PublicCloudFileAppObject.svelte';
|
||||||
import * as cloudContentAppObject from '../appobj/CloudContentAppObject.svelte';
|
import * as cloudContentAppObject from '../appobj/CloudContentAppObject.svelte';
|
||||||
import { useCloudContentList, usePublicCloudFiles } from '../utility/metadataLoaders';
|
import { useCloudContentList, usePublicCloudFiles, useServerStatus } from '../utility/metadataLoaders';
|
||||||
import { _t } from '../translations';
|
import { _t } from '../translations';
|
||||||
|
|
||||||
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
|
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
|
||||||
@@ -17,19 +17,41 @@
|
|||||||
import InlineButton from '../buttons/InlineButton.svelte';
|
import InlineButton from '../buttons/InlineButton.svelte';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
import { cloudSigninToken } from '../stores';
|
import { cloudConnectionsStore, cloudSigninToken, expandedConnections, openedConnections } from '../stores';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import SubDatabaseList from '../appobj/SubDatabaseList.svelte';
|
||||||
|
import { plusExpandIcon } from '../icons/expandIcons';
|
||||||
|
import { volatileConnectionMapStore } from '../utility/api';
|
||||||
|
import SubCloudItemsList from '../appobj/SubCloudItemsList.svelte';
|
||||||
|
|
||||||
let publicFilter = '';
|
let publicFilter = '';
|
||||||
let cloudFilter = '';
|
let cloudFilter = '';
|
||||||
|
|
||||||
$: publicFiles = usePublicCloudFiles();
|
const publicFiles = usePublicCloudFiles();
|
||||||
$: cloudContentList = useCloudContentList();
|
const cloudContentList = useCloudContentList();
|
||||||
|
const serverStatus = useServerStatus();
|
||||||
|
|
||||||
$: emptyCloudContent = ($cloudContentList || []).filter(x => !x.items?.length).map(x => x.folid);
|
$: emptyCloudContent = ($cloudContentList || []).filter(x => !x.items?.length).map(x => x.folid);
|
||||||
$: cloudContentFlat = ($cloudContentList || []).flatMap(fld => fld.items ?? []);
|
$: cloudContentFlat = ($cloudContentList || [])
|
||||||
|
.flatMap(fld => fld.items ?? [])
|
||||||
|
.map(data => {
|
||||||
|
if (data.type == 'connection') {
|
||||||
|
const conid = `cloud://${data.folid}/${data.cntid}`;
|
||||||
|
const status = $serverStatus ? $serverStatus[$volatileConnectionMapStore[conid] || conid] : undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
conid,
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
});
|
||||||
$: contentGroupTitleMap = _.fromPairs(($cloudContentList || []).map(x => [x.folid, x.name]));
|
$: contentGroupTitleMap = _.fromPairs(($cloudContentList || []).map(x => [x.folid, x.name]));
|
||||||
|
|
||||||
|
$: console.log('cloudContentFlat', cloudContentFlat);
|
||||||
|
|
||||||
async function handleRefreshPublic() {
|
async function handleRefreshPublic() {
|
||||||
await apiCall('cloud/refresh-public-files');
|
await apiCall('cloud/refresh-public-files');
|
||||||
}
|
}
|
||||||
@@ -67,6 +89,17 @@
|
|||||||
groupFunc={data => data.folid}
|
groupFunc={data => data.folid}
|
||||||
mapGroupTitle={folid => contentGroupTitleMap[folid]}
|
mapGroupTitle={folid => contentGroupTitleMap[folid]}
|
||||||
filter={publicFilter}
|
filter={publicFilter}
|
||||||
|
subItemsComponent={() => SubCloudItemsList}
|
||||||
|
expandIconFunc={plusExpandIcon}
|
||||||
|
isExpandable={data =>
|
||||||
|
data.conid &&
|
||||||
|
$cloudConnectionsStore[data.conid] &&
|
||||||
|
!$cloudConnectionsStore[data.conid].singleDatabase &&
|
||||||
|
$openedConnections.includes(data.conid)}
|
||||||
|
getIsExpanded={data => $expandedConnections.includes(data.conid) && !data.singleDatabase}
|
||||||
|
setIsExpanded={(data, value) => {
|
||||||
|
expandedConnections.update(old => (value ? [...old, data.conid] : old.filter(x => x != data.conid)));
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</WidgetsInnerContainer>
|
</WidgetsInnerContainer>
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user