mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 07:16:01 +00:00
show cloud content
This commit is contained in:
@@ -4,8 +4,13 @@ const {
|
||||
refreshPublicFiles,
|
||||
callCloudApiGet,
|
||||
callCloudApiPost,
|
||||
getCloudFolderEncryptor,
|
||||
} = require('../utility/cloudIntf');
|
||||
const connections = require('./connections');
|
||||
const socket = require('../utility/socket');
|
||||
const { decryptConnection, recryptConnection, getInternalEncryptor } = require('../utility/crypting');
|
||||
const { getConnectionLabel, getLogger, extractErrorLogData } = require('dbgate-tools');
|
||||
const logger = getLogger('cloud');
|
||||
|
||||
module.exports = {
|
||||
publicFiles_meta: true,
|
||||
@@ -30,9 +35,14 @@ module.exports = {
|
||||
|
||||
contentList_meta: true,
|
||||
async contentList() {
|
||||
const resp = callCloudApiGet('content-list');
|
||||
console.log('contentList', resp);
|
||||
return resp;
|
||||
try {
|
||||
const resp = await callCloudApiGet('content-list');
|
||||
return resp;
|
||||
} catch (err) {
|
||||
logger.error(extractErrorLogData(err), 'Error getting cloud content list');
|
||||
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
getContent_meta: true,
|
||||
@@ -79,4 +89,21 @@ module.exports = {
|
||||
status: 'ok',
|
||||
};
|
||||
},
|
||||
|
||||
moveConnectionCloud_meta: true,
|
||||
async moveConnectionCloud({ conid, folid }) {
|
||||
const conn = await connections.getCore({ conid });
|
||||
const folderEncryptor = getCloudFolderEncryptor(folid);
|
||||
const recryptedConn = recryptConnection(conn, getInternalEncryptor(), folderEncryptor);
|
||||
await this.putContent({
|
||||
folid,
|
||||
cntid: conid,
|
||||
content: JSON.stringify(recryptedConn),
|
||||
name: getConnectionLabel(conn),
|
||||
type: 'connection',
|
||||
});
|
||||
return {
|
||||
status: 'ok',
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ const connections = require('../controllers/connections');
|
||||
const { isProApp } = require('./checkLicense');
|
||||
const socket = require('./socket');
|
||||
const config = require('../controllers/config');
|
||||
const simpleEncryptor = require('simple-encryptor');
|
||||
|
||||
const logger = getLogger('cloudIntf');
|
||||
|
||||
@@ -239,6 +240,14 @@ async function callCloudApiPost(endpoint, body) {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
async function getCloudFolderEncryptor(folid) {
|
||||
const { encryptionKey } = await callCloudApiGet(`folder-key/${folid}`);
|
||||
if (!encryptionKey) {
|
||||
throw new Error('No encryption key');
|
||||
}
|
||||
return simpleEncryptor.createEncryptor(encryptionKey);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createDbGateIdentitySession,
|
||||
startCloudTokenChecking,
|
||||
@@ -248,4 +257,5 @@ module.exports = {
|
||||
refreshPublicFiles,
|
||||
callCloudApiGet,
|
||||
callCloudApiPost,
|
||||
getCloudFolderEncryptor,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user