From 6234a19e7a96a51c7571bab7ad0f93666670ba42 Mon Sep 17 00:00:00 2001 From: Yanhui Li Date: Thu, 9 Nov 2023 21:17:08 +1100 Subject: [PATCH] Use https://zenuml.com/sequence-diagram in share link --- .../paddle-webhook/functions/index.js | 18 +++++++++++++++--- src/services/syncService.js | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/firebase-functions/paddle-webhook/functions/index.js b/firebase-functions/paddle-webhook/functions/index.js index d57482c0..c89befa5 100644 --- a/firebase-functions/paddle-webhook/functions/index.js +++ b/firebase-functions/paddle-webhook/functions/index.js @@ -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: { @@ -49,7 +61,7 @@ exports.sync_diagram = functions.https.onRequest(async (req, res) => { }); response.on('end', () => { - res.send(responseData); + res.send(replaceBaseUrlInShareLink(responseData)); }); }); diff --git a/src/services/syncService.js b/src/services/syncService.js index 36202882..6b888693 100644 --- a/src/services/syncService.js +++ b/src/services/syncService.js @@ -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()