Skip to content

Fix for "open in colab" opens the same zip after updates #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 20, 2023
6 changes: 4 additions & 2 deletions functions/colab.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// `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 nbUid = uuidv4()
const repoOwner = process.env.VUE_APP_GH_USER
const repo = process.env.VUE_APP_GH_REPO

Expand All @@ -17,6 +16,7 @@ exports.handler = async function (event, _) {
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`

Expand All @@ -25,8 +25,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, uuidv5.URL)
const content = await zip.generateAsync({ type: 'base64' })
const zipRes = await pushToGitHub(
content,
Expand Down