Skip to content
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

New feature: fork dat #47

Open
chrisekelley opened this issue Apr 18, 2018 · 3 comments
Open

New feature: fork dat #47

chrisekelley opened this issue Apr 18, 2018 · 3 comments
Assignees

Comments

@chrisekelley
Copy link
Contributor

chrisekelley commented Apr 18, 2018

I've noticed in node-dat-archive that fork is not yet implemented? What are the issues in making this work? Some background:

Following the code:

from dat-archive.js forkArchive: 
newArchiveUrl = await datLibrary.forkArchive(url, {title, description, type, author}, {networked})
from datLibrary.forkArchive - https://github.com/beakerbrowser/beaker/blob/master/app/background-process/networks/dat/library.js

import pda from 'pauls-dat-api'

https://github.com/beakerbrowser/pauls-dat-api

-- snip --

export async function forkArchive (srcArchiveUrl, manifest = {}, settings = false) {
  srcArchiveUrl = fromKeyToURL(srcArchiveUrl)

  // get the old archive
  var srcArchive = getArchive(srcArchiveUrl)
  if (!srcArchive) {
    throw new Error('Invalid archive key')
  }

  // fetch old archive meta
  var srcManifest = await pda.readManifest(srcArchive).catch(_ => {})
  srcManifest = srcManifest || {}

  // override any manifest data
  var dstManifest = {
    title: (manifest.title) ? manifest.title : srcManifest.title,
    description: (manifest.description) ? manifest.description : srcManifest.description,
    type: (manifest.type) ? manifest.type : srcManifest.type,
    author: manifest.author
  }
  DAT_PRESERVED_FIELDS_ON_FORK.forEach(field => {
    if (srcManifest[field]) {
      dstManifest[field] = srcManifest[field]
    }
  })

  // create the new archive
  var dstArchiveUrl = await createNewArchive(dstManifest, settings)
  var dstArchive = getArchive(dstArchiveUrl)

  // copy files
  var ignore = ['/.dat', '/.git', '/dat.json']
  await pda.exportArchiveToArchive({
    srcArchive,
    dstArchive,
    skipUndownloadedFiles: true,
    ignore
  })

  return dstArchiveUrl
}

more on pda.readManifest(srcArchive). from https://github.com/beakerbrowser/pauls-dat-api

// helper to read the manifest into an object
function readManifest (archive, cb) {
  return maybe(cb, async function () {
    var data = await readFile(archive, DAT_MANIFEST_FILENAME)
    return JSON.parse(data.toString())
  })
}
@rjcorwin
Copy link
Contributor

@chrisekelley From what I understand, DatArchive.fork creates a new Dat Archive and then copies the contents from the source Archive into the destination Archive. It's like git pull, a command that is a shortcut to a handful of other commands. When dat-archive-web is implemented in dat-gateway, DatArchive.fork could be an abstraction over DatArchive.create, DatArchive.readFile, and DatArchive.writeFile.

@chrisekelley
Copy link
Contributor Author

Re: our discussion on what stuff should happen in the gateway, vs what should happen in the client - want to note https://dat-multiwriter-web.glitch.me - amazing all the stuff that is happening in this client!

@chrisekelley
Copy link
Contributor Author

hey @rjsteinert , since dat-archive-web now supports fork can we now use it to fork dats in bunsen browser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants