From d10fc1c7fbc410ec0c4773902251255582e33adc Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 23 May 2017 23:24:25 -1000 Subject: wip: more git --- lib/app.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index 4219151..1daf064 100644 --- a/lib/app.js +++ b/lib/app.js @@ -11,6 +11,7 @@ var Contacts = require('ssb-contact') var About = require('./about') var Serve = require('./serve') var Render = require('./render') +var Git = require('./git') module.exports = App @@ -41,6 +42,7 @@ function App(sbot, config) { this.unboxMsg = this.unboxMsg.bind(this) this.render = new Render(this, this.opts) + this.git = new Git(this) } App.prototype.go = function () { @@ -186,6 +188,36 @@ App.prototype.pushBlob = function (id, cb) { this.sbot.blobs.push(id, cb) } +App.prototype.readBlob = function (link, opts) { + link = u.toLink(link) + opts = opts || {} + return this.sbot.blobs.get({ + hash: link.link, + size: link.size, + start: opts.start, + end: opts.end, + }) +} + +App.prototype.ensureHasBlobs = function (links, cb) { + var self = this + var done = multicb({pluck: 1}) + links.forEach(function (link) { + var cb = done() + self.sbot.blobs.size(link.link, function (err, size) { + if (err) cb(err) + else if (size == null) cb(null, link) + else cb() + }) + }) + done(function (err, missingLinks) { + if (err) console.trace(err) + missingLinks = missingLinks.filter(Boolean) + if (missingLinks.length == 0) return cb() + return cb({name: 'BlobNotFoundError', links: missingLinks}) + }) +} + App.prototype.getReverseNameSync = function (name) { var id = this.reverseNameCache.get(name) return id -- cgit v1.2.3