mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 13:06:01 +00:00
load cloud folders
This commit is contained in:
@@ -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 = {
|
||||
publicFiles_meta: true,
|
||||
@@ -20,4 +27,56 @@ module.exports = {
|
||||
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';
|
||||
|
||||
const DBGATE_CLOUD_URL = process.env.LOCAL_DBGATE_CLOUD
|
||||
? 'http://localhost:3109'
|
||||
? 'http://localhost:3110'
|
||||
: process.env.DEVWEB || process.env.DEVMODE
|
||||
? 'https://cloud.dbgate.udolni.net'
|
||||
: 'https://cloud.dbgate.io';
|
||||
@@ -130,7 +130,7 @@ async function getCloudSigninHeaders() {
|
||||
'x-cloud-login': value,
|
||||
};
|
||||
}
|
||||
return {};
|
||||
return null;
|
||||
}
|
||||
|
||||
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 = {
|
||||
createDbGateIdentitySession,
|
||||
startCloudTokenChecking,
|
||||
@@ -216,4 +246,6 @@ module.exports = {
|
||||
getPublicCloudFiles,
|
||||
getPublicFileData,
|
||||
refreshPublicFiles,
|
||||
callCloudApiGet,
|
||||
callCloudApiPost,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user