Skip to content

Commit

Permalink
Merge pull request #606 from ZenUml/update-share-link
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCoder committed Nov 9, 2023
2 parents 6373654 + 6234a19 commit e18e363
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions firebase-functions/paddle-webhook/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ exports.sync_diagram = functions.https.onRequest(async (req, res) => {
console.log('decoded token:', decoded);
const user = {name: decoded.name, id: decoded.user_id, email: decoded.email, email_verified: decoded.email_verified, picture: decoded.picture};

const hostname = process.env.LARASITE_HOST || 'sequence-diagram.zenuml.com';
const baseUrlHttps = `https://${hostname}`;
const baseUrlHttp = `http://${hostname}`;
const publicBaseUrl = process.env.PUBLIC_LARASITE_BASE_URL || 'https://zenuml.com/sequence-diagram';
console.log('using publicBaseUrl:', publicBaseUrl);

const replaceBaseUrlInShareLink = (responseData) => {
const data = JSON.parse(responseData);
data.page_share = data.page_share.replace(baseUrlHttp, publicBaseUrl).replace(baseUrlHttps, publicBaseUrl);
return JSON.stringify(data);
}

const options = {
hostname: process.env.LARASITE_HOST || 'sequence-diagram.zenuml.com',
port: process.env.LARASITE_PORT || 443,
hostname,
port: 443,
path: '/diagrams',
method: 'POST',
headers: {
Expand All @@ -49,7 +61,7 @@ exports.sync_diagram = functions.https.onRequest(async (req, res) => {
});

response.on('end', () => {
res.send(responseData);
res.send(replaceBaseUrlInShareLink(responseData));
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/services/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import firebase from 'firebase/app';
async function syncDiagram(currentItem) {
const token = await firebase.auth().currentUser.getIdToken(true);

const data = { token, id: currentItem.id, name: currentItem.title, content: currentItem.js, description: JSON.stringify({ source: 'app.zenuml.com' }), imageBase64: currentItem.imageBase64 };
const data = { token, id: currentItem.id, name: currentItem.title, content: currentItem.js, description: 'Shared diagram from https://app.zenuml.com', imageBase64: currentItem.imageBase64 };
console.log('calling /sync-diagram with data:', data)

const result = await (await fetch('/sync-diagram', { method: 'POST', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } })).json()
Expand Down

0 comments on commit e18e363

Please sign in to comment.