pg
/
sbot
1
0
Fork 0

blob: protocol now supports ?fallback=img on notfound

Dieser Commit ist enthalten in:
Paul Frazee 2015-06-26 13:53:37 -05:00
Ursprung 753b9058ec
Commit f988d7fbe8
1 geänderte Dateien mit 20 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,15 @@
var path = require('path')
var multicb = require('multicb')
var toPath = require('multiblob/util').toPath
var createHash = require('multiblob/util').createHash
var pull = require('pull-stream')
var toPull = require('stream-to-pull-stream')
var path = require('path')
var multicb = require('multicb')
var toPath = require('multiblob/util').toPath
var createHash = require('multiblob/util').createHash
var pull = require('pull-stream')
var toPull = require('stream-to-pull-stream')
var querystring = require('querystring')
var fs = require('fs')
var fs = require('fs')
module.exports = function (blobs_dir, checkout_dir) {
var fallback_img_path = path.join(__dirname, '../../node_modules/ssbplug-phoenix/img/default-prof-pic.png')
return {
// behavior for the blob: protocol
protocol: function (request) {
@ -15,7 +17,17 @@ module.exports = function (blobs_dir, checkout_dir) {
// simple fetch
var parsed = url_parse(request.url)
if (request.method == 'GET' && parsed) {
return new protocol.RequestFileJob(toPath(blobs_dir, parsed.hash))
var filepath = toPath(blobs_dir, parsed.hash)
try {
// check if the file exists
fs.statSync(filepath) // :HACK: make async when we figure out how to make a protocol-handler support that
return new protocol.RequestFileJob(filepath)
} catch (e) {
// notfound
if (parsed.qs.fallback == 'img')
return new protocol.RequestFileJob(fallback_img_path)
return new protocol.RequestErrorJob(-6)
}
}
},