From 8c29ee148336d1c32d991367002b803dbb7daf20 Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 01:03:47 +0530 Subject: [PATCH 1/8] Check if hyperlink is causing the problem - Perhaps the reactivity of vue is the problem and the hyperlink is not being updated --- src/components/NavColab.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/NavColab.vue b/src/components/NavColab.vue index a9e21fc7..4a324e5e 100644 --- a/src/components/NavColab.vue +++ b/src/components/NavColab.vue @@ -69,6 +69,7 @@ export default { setup() { const showDownloadMsg = ref(false) const colabText = ref('Open in Colab') + const new_colab_link = ref('') const downloadProject = async () => { if (store.code && Object.keys(store.code).length) { @@ -97,10 +98,11 @@ export default { }) // response body is plain text const colabLink = await res.text() + new_colab_link.value = colabLink // create a hyperlink element const el = document.createElement('a') - el.setAttribute('href', colabLink) + el.setAttribute('href', new_colab_link.value) el.setAttribute('target', '_blank') el.setAttribute('rel', 'noopener noreferrer') el.click() From b8dccd36115985b658c64e17d901240c2412d6f8 Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 01:16:29 +0530 Subject: [PATCH 2/8] Change unique identifier each time the function is called --- functions/colab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/colab.js b/functions/colab.js index 07f1024d..4b60e954 100644 --- a/functions/colab.js +++ b/functions/colab.js @@ -6,7 +6,6 @@ import { v4 as uuidv4 } from 'uuid' import JSZip from 'jszip' import { pushToGitHub } from './utils' -const nbUid = uuidv4() const repoOwner = process.env.VUE_APP_GH_USER const repo = process.env.VUE_APP_GH_REPO @@ -14,6 +13,7 @@ const repo = process.env.VUE_APP_GH_REPO // https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format exports.handler = async function (event, _) { // event is a JSON object + const nbUid = uuidv4() const data = JSON.parse(event.body) const zip = new JSZip() const code = data.code From b47e3ec00b40f5e15431bcbe51c8c6206499c35e Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 19:24:23 +0530 Subject: [PATCH 3/8] Revert back changes in NavColab.vue --- src/components/NavColab.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/NavColab.vue b/src/components/NavColab.vue index 4a324e5e..8a60782d 100644 --- a/src/components/NavColab.vue +++ b/src/components/NavColab.vue @@ -69,7 +69,6 @@ export default { setup() { const showDownloadMsg = ref(false) const colabText = ref('Open in Colab') - const new_colab_link = ref('') const downloadProject = async () => { if (store.code && Object.keys(store.code).length) { @@ -98,11 +97,10 @@ export default { }) // response body is plain text const colabLink = await res.text() - new_colab_link.value = colabLink // create a hyperlink element const el = document.createElement('a') - el.setAttribute('href', new_colab_link.value) + el.setAttribute('href', colabLink) el.setAttribute('target', '_blank') el.setAttribute('rel', 'noopener noreferrer') el.click() @@ -113,6 +111,7 @@ export default { } colabText.value = 'Open in Colab' } + // watch(store.config, () => downloadProject) return { downloadProject, showDownloadMsg, colabText } } } From 5849c0e8ab976ffddfb7d6d32eb623e55a134aca Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 19:25:27 +0530 Subject: [PATCH 4/8] Added combined hash of the code for formation of uuid --- functions/colab.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions/colab.js b/functions/colab.js index 4b60e954..a7530647 100644 --- a/functions/colab.js +++ b/functions/colab.js @@ -2,21 +2,23 @@ // `external_node_modules` of [functions] in netlify.toml // They are required for this function to run -import { v4 as uuidv4 } from 'uuid' +import { v5 as uuidv5 } from 'uuid'; import JSZip from 'jszip' import { pushToGitHub } from './utils' const repoOwner = process.env.VUE_APP_GH_USER const repo = process.env.VUE_APP_GH_REPO +const NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341' + // This function is the one Netlify function runs on // https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format exports.handler = async function (event, _) { // event is a JSON object - const nbUid = uuidv4() const data = JSON.parse(event.body) const zip = new JSZip() const code = data.code + let hash = '' const template = `ignite-${data.template}` const nbName = `${template}.ipynb` @@ -25,8 +27,10 @@ exports.handler = async function (event, _) { // generate a base64 format for pushing to GitHub // with Octokit. for (const filename in code) { + hash += code[filename] zip.file(filename, code[filename]) } + const nbUid = uuidv5(hash, NAMESPACE) const content = await zip.generateAsync({ type: 'base64' }) const zipRes = await pushToGitHub( content, From 47e70e52e8c09ce8ba5e2f75d1c93cef4124dcf1 Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 19:38:34 +0530 Subject: [PATCH 5/8] Fix lint --- functions/colab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/colab.js b/functions/colab.js index a7530647..b1bb62ba 100644 --- a/functions/colab.js +++ b/functions/colab.js @@ -2,7 +2,7 @@ // `external_node_modules` of [functions] in netlify.toml // They are required for this function to run -import { v5 as uuidv5 } from 'uuid'; +import { v5 as uuidv5 } from 'uuid' import JSZip from 'jszip' import { pushToGitHub } from './utils' From 182185df666dc7616cc5905860c96d8d8a2c8b4c Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 20:12:21 +0530 Subject: [PATCH 6/8] Using the uuidv5 URL namespace --- functions/colab.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/functions/colab.js b/functions/colab.js index b1bb62ba..c7e2431e 100644 --- a/functions/colab.js +++ b/functions/colab.js @@ -9,8 +9,6 @@ import { pushToGitHub } from './utils' const repoOwner = process.env.VUE_APP_GH_USER const repo = process.env.VUE_APP_GH_REPO -const NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341' - // This function is the one Netlify function runs on // https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format exports.handler = async function (event, _) { @@ -30,7 +28,7 @@ exports.handler = async function (event, _) { hash += code[filename] zip.file(filename, code[filename]) } - const nbUid = uuidv5(hash, NAMESPACE) + const nbUid = uuidv5(hash, uuidv5.URL) const content = await zip.generateAsync({ type: 'base64' }) const zipRes = await pushToGitHub( content, From 7f5dc5c321aea7070dad303b7f452b661fabdd2d Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 20:23:58 +0530 Subject: [PATCH 7/8] Remove unwanted comments --- src/components/NavColab.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/NavColab.vue b/src/components/NavColab.vue index 8a60782d..80fb4ed8 100644 --- a/src/components/NavColab.vue +++ b/src/components/NavColab.vue @@ -111,7 +111,7 @@ export default { } colabText.value = 'Open in Colab' } - // watch(store.config, () => downloadProject) + return { downloadProject, showDownloadMsg, colabText } } } From e0609539447f949e5ad78f3f90f98f1eccc34e98 Mon Sep 17 00:00:00 2001 From: Jyotirmay Khavasi Date: Sun, 20 Aug 2023 20:25:38 +0530 Subject: [PATCH 8/8] Remove rogue extra line --- src/components/NavColab.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/NavColab.vue b/src/components/NavColab.vue index 80fb4ed8..a9e21fc7 100644 --- a/src/components/NavColab.vue +++ b/src/components/NavColab.vue @@ -111,7 +111,6 @@ export default { } colabText.value = 'Open in Colab' } - return { downloadProject, showDownloadMsg, colabText } } }