notfounds in blob: protocol now register blob-want

This commit is contained in:
Paul Frazee 2015-07-04 13:51:33 -05:00
parent fadfda353d
commit 4d9510336a

View File

@ -7,8 +7,10 @@ var toPull = require('stream-to-pull-stream')
var querystring = require('querystring') var querystring = require('querystring')
var fs = require('fs') var fs = require('fs')
module.exports = function (blobs_dir, checkout_dir) { module.exports = function (sbot, checkout_dir) {
var blobs_dir = path.join(sbot.config.path, 'blobs')
var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png') var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png')
var nowaitOpts = { nowait: true }, id = function(){}
return { return {
// behavior for the blob: protocol // behavior for the blob: protocol
@ -24,6 +26,7 @@ module.exports = function (blobs_dir, checkout_dir) {
return new protocol.RequestFileJob(filepath) return new protocol.RequestFileJob(filepath)
} catch (e) { } catch (e) {
// notfound // notfound
sbot.blobs.want(parsed.hash, nowaitOpts, id)
if (parsed.qs.fallback == 'img') if (parsed.qs.fallback == 'img')
return new protocol.RequestFileJob(fallback_img_path) return new protocol.RequestFileJob(fallback_img_path)
return new protocol.RequestErrorJob(-6) return new protocol.RequestErrorJob(-6)