save new connection on cloud

This commit is contained in:
SPRINX0\prochazka
2025-05-26 14:41:41 +02:00
parent b3497c7306
commit 88f937f73e
10 changed files with 173 additions and 36 deletions

View File

@@ -10,7 +10,7 @@ const {
} = require('../utility/cloudIntf');
const connections = require('./connections');
const socket = require('../utility/socket');
const { recryptConnection, getInternalEncryptor } = require('../utility/crypting');
const { recryptConnection, getInternalEncryptor, encryptConnection } = require('../utility/crypting');
const { getConnectionLabel, getLogger, extractErrorLogData } = require('dbgate-tools');
const logger = getLogger('cloud');
const _ = require('lodash');
@@ -113,7 +113,7 @@ module.exports = {
moveConnectionCloud_meta: true,
async moveConnectionCloud({ conid, folid }) {
const conn = await connections.getCore({ conid });
const folderEncryptor = getCloudFolderEncryptor(folid);
const folderEncryptor = await getCloudFolderEncryptor(folid);
const recryptedConn = recryptConnection(conn, getInternalEncryptor(), folderEncryptor);
const connToSend = _.omit(recryptedConn, ['_id']);
const resp = await putCloudContent(
@@ -125,4 +125,24 @@ module.exports = {
);
return resp;
},
saveConnection_meta: true,
async saveConnection({ folid, connection }) {
const folderEncryptor = await getCloudFolderEncryptor(folid);
const recryptedConn = encryptConnection(connection, folderEncryptor);
const resp = await putCloudContent(
folid,
undefined,
JSON.stringify(recryptedConn),
getConnectionLabel(recryptedConn),
'connection'
);
const { cntid } = resp;
socket.emitChanged('cloud-content-changed');
return {
...recryptedConn,
_id: `cloud://${folid}/${cntid}`,
};
},
};