show cloud content

This commit is contained in:
SPRINX0\prochazka
2025-05-21 17:09:16 +02:00
parent b553a81d47
commit 590a4ae476
9 changed files with 96 additions and 10 deletions

View File

@@ -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',
};
},
};

View File

@@ -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,
};