cloud content fixes

This commit is contained in:
SPRINX0\prochazka
2025-05-22 13:07:45 +02:00
parent f8081ff09e
commit 5c33579544
6 changed files with 31 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ const {
callCloudApiGet,
callCloudApiPost,
getCloudFolderEncryptor,
getCloudContent,
} = require('../utility/cloudIntf');
const connections = require('./connections');
const socket = require('../utility/socket');
@@ -48,8 +49,8 @@ module.exports = {
getContent_meta: true,
async getContent({ folid, cntid }) {
const { content, name, type } = await callCloudApiGet(`content/${folid}/${cntid}`);
return { content, name, type };
const resp = await getCloudContent(folid, cntid);
return resp;
},
putContent_meta: true,

View File

@@ -425,12 +425,9 @@ module.exports = {
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 { loadCachedCloudConnection } = require('../utility/cloudIntf');
const conn = await loadCachedCloudConnection(cloudMatch[1], cloudMatch[2]);
return conn;
}
const storage = require('./storage');

View File

@@ -248,6 +248,24 @@ async function getCloudFolderEncryptor(folid) {
return simpleEncryptor.createEncryptor(encryptionKey);
}
async function getCloudContent(folid, cntid) {
const { content, name, type } = await callCloudApiGet(`content/${folid}/${cntid}`);
return { content, name, type };
}
const cloudConnectionCache = {};
async function loadCachedCloudConnection(folid, cntid) {
const cacheKey = `${folid}|${cntid}`;
if (!cloudConnectionCache[cacheKey]) {
const { content } = await getCloudContent(folid, cntid);
cloudConnectionCache[cacheKey] = {
...JSON.parse(content),
_id: `cloud://${folid}/${cntid}`,
};
}
return cloudConnectionCache[cacheKey];
}
module.exports = {
createDbGateIdentitySession,
startCloudTokenChecking,
@@ -258,4 +276,6 @@ module.exports = {
callCloudApiGet,
callCloudApiPost,
getCloudFolderEncryptor,
getCloudContent,
loadCachedCloudConnection,
};