mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 00:46:01 +00:00
load cloud folders
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
DEVMODE=1
|
DEVMODE=1
|
||||||
SHELL_SCRIPTING=1
|
SHELL_SCRIPTING=1
|
||||||
|
LOCAL_DBGATE_CLOUD=1
|
||||||
# LOCAL_DBGATE_IDENTITY=1
|
# LOCAL_DBGATE_IDENTITY=1
|
||||||
|
|
||||||
# CLOUD_UPGRADE_FILE=c:\test\upg\upgrade.zip
|
# CLOUD_UPGRADE_FILE=c:\test\upg\upgrade.zip
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
const { getPublicCloudFiles, getPublicFileData, refreshPublicFiles } = require('../utility/cloudIntf');
|
const {
|
||||||
|
getPublicCloudFiles,
|
||||||
|
getPublicFileData,
|
||||||
|
refreshPublicFiles,
|
||||||
|
callCloudApiGet,
|
||||||
|
callCloudApiPost,
|
||||||
|
} = require('../utility/cloudIntf');
|
||||||
|
const socket = require('../utility/socket');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publicFiles_meta: true,
|
publicFiles_meta: true,
|
||||||
@@ -20,4 +27,56 @@ module.exports = {
|
|||||||
status: 'ok',
|
status: 'ok',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
contentList_meta: true,
|
||||||
|
async contentList() {
|
||||||
|
const resp = callCloudApiGet('content-list');
|
||||||
|
console.log('contentList', resp);
|
||||||
|
return resp;
|
||||||
|
},
|
||||||
|
|
||||||
|
getContent_meta: true,
|
||||||
|
async getContent({ folid, cntid }) {
|
||||||
|
const resp = await callCloudApiGet(`content/${folid}/${cntid}`);
|
||||||
|
return resp;
|
||||||
|
},
|
||||||
|
|
||||||
|
putContent_meta: true,
|
||||||
|
async putContent({ folid, cntid, content, name, type }) {
|
||||||
|
await callCloudApiPost(`put-content`, { folid, cntid, content, name, type });
|
||||||
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
return {
|
||||||
|
status: 'ok',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
createFolder_meta: true,
|
||||||
|
async createFolder({ name }) {
|
||||||
|
await callCloudApiPost(`folders/create`, { name });
|
||||||
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
return {
|
||||||
|
status: 'ok',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
grantFolder_meta: true,
|
||||||
|
async grantFolder({ inviteLink }) {
|
||||||
|
const m = inviteLink.match(/^dbgate\:\/\/folder\/v1\/([a-zA-Z]+)\?mode=(read|write|admin)$/);
|
||||||
|
const invite = m[1];
|
||||||
|
const mode = m[2];
|
||||||
|
|
||||||
|
await callCloudApiPost(`folders/grant/${mode}`, { invite });
|
||||||
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
return {
|
||||||
|
status: 'ok',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
refreshContent_meta: true,
|
||||||
|
async refreshContent() {
|
||||||
|
socket.emitChanged('cloud-content-changed');
|
||||||
|
return {
|
||||||
|
status: 'ok',
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const DBGATE_IDENTITY_URL = process.env.LOCAL_DBGATE_IDENTITY
|
|||||||
: 'https://identity.dbgate.io';
|
: 'https://identity.dbgate.io';
|
||||||
|
|
||||||
const DBGATE_CLOUD_URL = process.env.LOCAL_DBGATE_CLOUD
|
const DBGATE_CLOUD_URL = process.env.LOCAL_DBGATE_CLOUD
|
||||||
? 'http://localhost:3109'
|
? 'http://localhost:3110'
|
||||||
: process.env.DEVWEB || process.env.DEVMODE
|
: process.env.DEVWEB || process.env.DEVMODE
|
||||||
? 'https://cloud.dbgate.udolni.net'
|
? 'https://cloud.dbgate.udolni.net'
|
||||||
: 'https://cloud.dbgate.io';
|
: 'https://cloud.dbgate.io';
|
||||||
@@ -130,7 +130,7 @@ async function getCloudSigninHeaders() {
|
|||||||
'x-cloud-login': value,
|
'x-cloud-login': value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {};
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateCloudFiles() {
|
async function updateCloudFiles() {
|
||||||
@@ -209,6 +209,36 @@ async function refreshPublicFiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function callCloudApiGet(endpoint) {
|
||||||
|
const signinHeaders = await getCloudSigninHeaders();
|
||||||
|
if (!signinHeaders) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = await axios.default.get(`${DBGATE_CLOUD_URL}/${endpoint}`, {
|
||||||
|
headers: {
|
||||||
|
...getLicenseHttpHeaders(),
|
||||||
|
...signinHeaders,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return resp.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function callCloudApiPost(endpoint, body) {
|
||||||
|
const signinHeaders = await getCloudSigninHeaders();
|
||||||
|
if (!signinHeaders) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = await axios.default.post(`${DBGATE_CLOUD_URL}/${endpoint}`, body, {
|
||||||
|
headers: {
|
||||||
|
...getLicenseHttpHeaders(),
|
||||||
|
...signinHeaders,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return resp.data;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createDbGateIdentitySession,
|
createDbGateIdentitySession,
|
||||||
startCloudTokenChecking,
|
startCloudTokenChecking,
|
||||||
@@ -216,4 +246,6 @@ module.exports = {
|
|||||||
getPublicCloudFiles,
|
getPublicCloudFiles,
|
||||||
getPublicFileData,
|
getPublicFileData,
|
||||||
refreshPublicFiles,
|
refreshPublicFiles,
|
||||||
|
callCloudApiGet,
|
||||||
|
callCloudApiPost,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
export let groupFunc;
|
export let groupFunc;
|
||||||
export let items;
|
export let items;
|
||||||
export let groupIconFunc = plusExpandIcon;
|
export let groupIconFunc = plusExpandIcon;
|
||||||
|
export let mapGroupTitle = undefined;
|
||||||
export let module;
|
export let module;
|
||||||
export let checkedObjectsStore = null;
|
export let checkedObjectsStore = null;
|
||||||
export let disableContextMenu = false;
|
export let disableContextMenu = false;
|
||||||
@@ -63,7 +64,7 @@
|
|||||||
<FontIcon icon={groupIconFunc(isExpanded)} />
|
<FontIcon icon={groupIconFunc(isExpanded)} />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{group}
|
{mapGroupTitle ? mapGroupTitle(group) : group}
|
||||||
{items && `(${countText})`}
|
{items && `(${countText})`}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
export let groupIconFunc = plusExpandIcon;
|
export let groupIconFunc = plusExpandIcon;
|
||||||
export let groupFunc = undefined;
|
export let groupFunc = undefined;
|
||||||
|
export let mapGroupTitle = undefined;
|
||||||
export let onDropOnGroup = undefined;
|
export let onDropOnGroup = undefined;
|
||||||
export let emptyGroupNames = [];
|
export let emptyGroupNames = [];
|
||||||
export let isExpandedBySearch = false;
|
export let isExpandedBySearch = false;
|
||||||
@@ -127,6 +128,7 @@
|
|||||||
{subItemsComponent}
|
{subItemsComponent}
|
||||||
{checkedObjectsStore}
|
{checkedObjectsStore}
|
||||||
{groupFunc}
|
{groupFunc}
|
||||||
|
{mapGroupTitle}
|
||||||
{disableContextMenu}
|
{disableContextMenu}
|
||||||
{filter}
|
{filter}
|
||||||
{passProps}
|
{passProps}
|
||||||
|
|||||||
@@ -182,9 +182,12 @@ export const focusedConnectionOrDatabase = writable<{ conid: string; database?:
|
|||||||
|
|
||||||
export const focusedTreeDbKey = writable<{ key: string; root: string; type: string; text: string }>(null);
|
export const focusedTreeDbKey = writable<{ key: string; root: string; type: string; text: string }>(null);
|
||||||
|
|
||||||
export const cloudSigninToken = getElectron()
|
export const cloudSigninToken = writableSettingsValue(null, 'cloudSigninToken');
|
||||||
? writableSettingsValue(null, 'cloudSigninToken')
|
export const cloudEncryptKeysByFolder = writableSettingsValue({}, 'cloudEncryptKeysByFolder');
|
||||||
: writableWithStorage(null, 'cloudSigninToken');
|
|
||||||
|
// export const cloudSigninToken = getElectron()
|
||||||
|
// ? writableSettingsValue(null, 'cloudSigninToken')
|
||||||
|
// : writableWithStorage(null, 'cloudSigninToken');
|
||||||
|
|
||||||
export const DEFAULT_OBJECT_SEARCH_SETTINGS = {
|
export const DEFAULT_OBJECT_SEARCH_SETTINGS = {
|
||||||
pureName: true,
|
pureName: true,
|
||||||
|
|||||||
@@ -171,6 +171,11 @@ const publicCloudFilesLoader = () => ({
|
|||||||
params: {},
|
params: {},
|
||||||
reloadTrigger: { key: `public-cloud-changed` },
|
reloadTrigger: { key: `public-cloud-changed` },
|
||||||
});
|
});
|
||||||
|
const cloudContentListLoader = () => ({
|
||||||
|
url: 'cloud/content-list',
|
||||||
|
params: {},
|
||||||
|
reloadTrigger: { key: `cloud-content-changed` },
|
||||||
|
});
|
||||||
|
|
||||||
async function getCore(loader, args) {
|
async function getCore(loader, args) {
|
||||||
const { url, params, reloadTrigger, transform, onLoaded, errorValue } = loader(args);
|
const { url, params, reloadTrigger, transform, onLoaded, errorValue } = loader(args);
|
||||||
@@ -469,3 +474,10 @@ export function getPublicCloudFiles(args) {
|
|||||||
export function usePublicCloudFiles(args = {}) {
|
export function usePublicCloudFiles(args = {}) {
|
||||||
return useCore(publicCloudFilesLoader, args);
|
return useCore(publicCloudFilesLoader, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCloudContentList(args) {
|
||||||
|
return getCore(cloudContentListLoader, args);
|
||||||
|
}
|
||||||
|
export function useCloudContentList(args = {}) {
|
||||||
|
return useCore(cloudContentListLoader, args);
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
import AppObjectList from '../appobj/AppObjectList.svelte';
|
import AppObjectList from '../appobj/AppObjectList.svelte';
|
||||||
import * as cloudFileAppObject from '../appobj/CloudFileAppObject.svelte';
|
import * as cloudFileAppObject from '../appobj/CloudFileAppObject.svelte';
|
||||||
import { usePublicCloudFiles } from '../utility/metadataLoaders';
|
import { useCloudContentList, usePublicCloudFiles } from '../utility/metadataLoaders';
|
||||||
import { _t } from '../translations';
|
import { _t } from '../translations';
|
||||||
|
|
||||||
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
|
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
|
||||||
@@ -17,27 +17,69 @@
|
|||||||
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 { cloudSigninToken } from '../stores';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
let filter = '';
|
let publicFilter = '';
|
||||||
|
let cloudFilter = '';
|
||||||
|
|
||||||
$: publicFiles = usePublicCloudFiles();
|
$: publicFiles = usePublicCloudFiles();
|
||||||
|
$: cloudContentList = useCloudContentList();
|
||||||
|
|
||||||
|
$: emptyCloudContent = ($cloudContentList || []).filter(x => !x.items?.length).map(x => x.folid);
|
||||||
|
$: cloudContentFlat = ($cloudContentList || []).flatMap(fld => fld.items ?? []).map(x => x.folid);
|
||||||
|
$: contentGroupTitleMap = _.fromPairs(($cloudContentList || []).map(x => [x.folid, x.name]));
|
||||||
|
|
||||||
async function handleRefreshPublic() {
|
async function handleRefreshPublic() {
|
||||||
await apiCall('cloud/refresh-public-files');
|
await apiCall('cloud/refresh-public-files');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleRefreshContent() {
|
||||||
|
await apiCall('cloud/refresh-content');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WidgetColumnBar>
|
<WidgetColumnBar>
|
||||||
<WidgetColumnBarItem title="DbGate Cloud" name="privateCloud" height="50%" storageName="privateCloudItems" skip={!$cloudSigninToken}>
|
<WidgetColumnBarItem
|
||||||
XXX
|
title="DbGate Cloud"
|
||||||
</WidgetColumnBarItem>
|
name="privateCloud"
|
||||||
|
height="50%"
|
||||||
<WidgetColumnBarItem title="Public Knowledge Base" name="publicCloud" storageName="publicCloudItems">
|
storageName="privateCloudItems"
|
||||||
|
skip={!$cloudSigninToken}
|
||||||
|
>
|
||||||
<WidgetsInnerContainer>
|
<WidgetsInnerContainer>
|
||||||
<SearchBoxWrapper>
|
<SearchBoxWrapper>
|
||||||
<SearchInput placeholder="Search public files" bind:value={filter} />
|
<SearchInput placeholder="Search cloud items" bind:value={cloudFilter} />
|
||||||
<CloseSearchButton bind:filter />
|
<CloseSearchButton bind:filter={cloudFilter} />
|
||||||
<InlineButton on:click={handleRefreshPublic} title="Refresh files" data-testid="SavedFileList_buttonRefresh">
|
<InlineButton
|
||||||
|
on:click={handleRefreshContent}
|
||||||
|
title="Refresh files"
|
||||||
|
data-testid="CloudItemsWidget_buttonRefreshContent"
|
||||||
|
>
|
||||||
|
<FontIcon icon="icon refresh" />
|
||||||
|
</InlineButton>
|
||||||
|
</SearchBoxWrapper>
|
||||||
|
|
||||||
|
<AppObjectList
|
||||||
|
list={cloudContentFlat || []}
|
||||||
|
module={cloudFileAppObject}
|
||||||
|
emptyGroupNames={emptyCloudContent}
|
||||||
|
groupFunc={data => data.folid}
|
||||||
|
mapGroupTitle={folid => contentGroupTitleMap[folid]}
|
||||||
|
filter={publicFilter}
|
||||||
|
/>
|
||||||
|
</WidgetsInnerContainer>
|
||||||
|
</WidgetColumnBarItem>
|
||||||
|
|
||||||
|
<WidgetColumnBarItem title="Public Knowledge Base" name="publicCloud" storageName="publicCloudItems">
|
||||||
|
<WidgetsInnerContainer>
|
||||||
|
<SearchBoxWrapper>
|
||||||
|
<SearchInput placeholder="Search public files" bind:value={publicFilter} />
|
||||||
|
<CloseSearchButton bind:filter={publicFilter} />
|
||||||
|
<InlineButton
|
||||||
|
on:click={handleRefreshPublic}
|
||||||
|
title="Refresh files"
|
||||||
|
data-testid="CloudItemsWidget_buttonRefreshPublic"
|
||||||
|
>
|
||||||
<FontIcon icon="icon refresh" />
|
<FontIcon icon="icon refresh" />
|
||||||
</InlineButton>
|
</InlineButton>
|
||||||
</SearchBoxWrapper>
|
</SearchBoxWrapper>
|
||||||
@@ -46,7 +88,7 @@
|
|||||||
list={$publicFiles || []}
|
list={$publicFiles || []}
|
||||||
module={cloudFileAppObject}
|
module={cloudFileAppObject}
|
||||||
groupFunc={data => data.folder || undefined}
|
groupFunc={data => data.folder || undefined}
|
||||||
{filter}
|
filter={publicFilter}
|
||||||
/>
|
/>
|
||||||
</WidgetsInnerContainer>
|
</WidgetsInnerContainer>
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user