remove the custom blob protocol
This commit is contained in:
parent
f0b39ad9b4
commit
b232250221
@ -30,7 +30,6 @@ app.on('ready', function () {
|
|||||||
|
|
||||||
// setup blob and file serving
|
// setup blob and file serving
|
||||||
var blobs = require('./lib/blobs')(sbot, { blobs_dir: path.join(config.path, 'blobs'), checkout_dir: app.getPath('userDesktop') })
|
var blobs = require('./lib/blobs')(sbot, { blobs_dir: path.join(config.path, 'blobs'), checkout_dir: app.getPath('userDesktop') })
|
||||||
require('protocol').registerProtocol('pwblob', blobs.protocol)
|
|
||||||
http.createServer(blobs.server({ serveFiles: false })).listen(7777)
|
http.createServer(blobs.server({ serveFiles: false })).listen(7777)
|
||||||
http.createServer(blobs.server({ serveFiles: true })).listen(7778)
|
http.createServer(blobs.server({ serveFiles: true })).listen(7778)
|
||||||
|
|
||||||
|
@ -12,27 +12,6 @@ module.exports = function (sbot, config) {
|
|||||||
var nowaitOpts = { nowait: true }, id = function(){}
|
var nowaitOpts = { nowait: true }, id = function(){}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// behavior for the blob: protocol
|
|
||||||
protocol: function (request) {
|
|
||||||
var protocol = require('protocol') // have to require here, doing so before app:ready causes errors
|
|
||||||
// simple fetch
|
|
||||||
var parsed = url_parse(request.url)
|
|
||||||
if (request.method == 'GET' && parsed) {
|
|
||||||
var filepath = toPath(config.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
|
|
||||||
sbot.blobs.want(parsed.hash, nowaitOpts, id)
|
|
||||||
if (parsed.qs.fallback == 'img')
|
|
||||||
return new protocol.RequestFileJob(fallback_img_path)
|
|
||||||
return new protocol.RequestErrorJob(-6)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// copy file from blobs into given dir with nice name
|
// copy file from blobs into given dir with nice name
|
||||||
checkout: function (url, cb) {
|
checkout: function (url, cb) {
|
||||||
var parsed = url_parse(url)
|
var parsed = url_parse(url)
|
||||||
@ -102,15 +81,24 @@ module.exports = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serve blob
|
// serve blob
|
||||||
var hash = req.url.slice(-51) // hash ids are 51 chars long
|
var parsed = url_parse(req.url)
|
||||||
sbot.blobs.has(hash, function(err, has) {
|
sbot.blobs.has(parsed.hash, function(err, has) {
|
||||||
if (!has) {
|
if (!has) {
|
||||||
|
sbot.blobs.want(parsed.hash, nowaitOpts, id)
|
||||||
|
if (parsed.qs.fallback == 'img') {
|
||||||
|
return fs.createReadStream(fallback_img_path)
|
||||||
|
.on('error', function () {
|
||||||
|
res.writeHead(404)
|
||||||
|
res.end('File not found')
|
||||||
|
})
|
||||||
|
.pipe(res)
|
||||||
|
}
|
||||||
res.writeHead(404)
|
res.writeHead(404)
|
||||||
res.end('File not found')
|
res.end('File not found')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pull(
|
pull(
|
||||||
sbot.blobs.get(hash),
|
sbot.blobs.get(parsed.hash),
|
||||||
toPull(res)
|
toPull(res)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -159,7 +147,14 @@ module.exports = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// blob url parser
|
// blob url parser
|
||||||
var re = /^pwblob:&([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
|
// var re = /^pwblob:&([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
|
||||||
|
// var url_parse =
|
||||||
|
// module.exports.url_parse = function (str) {
|
||||||
|
// var parts = re.exec(str)
|
||||||
|
// if (parts)
|
||||||
|
// return { hash: parts[1], qs: querystring.parse(parts[2]) }
|
||||||
|
// }
|
||||||
|
var re = /^(?:http:\/\/localhost:7777)?\/&([a-z0-9\+\/=]+\.(?:sha256|blake2s))\??(.*)$/i
|
||||||
var url_parse =
|
var url_parse =
|
||||||
module.exports.url_parse = function (str) {
|
module.exports.url_parse = function (str) {
|
||||||
var parts = re.exec(str)
|
var parts = re.exec(str)
|
||||||
|
@ -34,7 +34,7 @@ module.exports.open = function (url, sbot, blobs, opts, params) {
|
|||||||
|
|
||||||
win.webContents.on('new-window', function (e, url) {
|
win.webContents.on('new-window', function (e, url) {
|
||||||
e.preventDefault() // hell naw
|
e.preventDefault() // hell naw
|
||||||
if (url.indexOf('blob:') === 0) {
|
if (url.indexOf('http://localhost:7777/') === 0) {
|
||||||
// open the file
|
// open the file
|
||||||
blobs.checkout(url, function (err, filepath) {
|
blobs.checkout(url, function (err, filepath) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
"muxrpc": "^5.0.1",
|
"muxrpc": "^5.0.1",
|
||||||
"pull-pushable": "^1.1.4",
|
"pull-pushable": "^1.1.4",
|
||||||
"pull-stream": "^2.27.0",
|
"pull-stream": "^2.27.0",
|
||||||
"scuttlebot": "^6.0.0",
|
"scuttlebot": "^6.1.5",
|
||||||
"ssb-config": "^1.0.3",
|
"ssb-config": "^1.0.3",
|
||||||
"ssb-keys": "^4.0.3",
|
"ssb-keys": "^4.0.3",
|
||||||
"ssb-patchwork-api": "~0.0.1",
|
"ssb-patchwork-api": "~0.0.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user