Fix some errors I've seen responding to blobs.get. Especially: handle sending large blobs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3715 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-12-28 21:48:03 +00:00
parent 0f7472fa22
commit 5e205ac897
2 changed files with 74 additions and 3 deletions

View File

@ -168,10 +168,25 @@ ssb.addRpc(['blobs', 'has'], function(request) {
});
ssb.addRpc(['blobs', 'get'], function(request) {
for (let id of request.args) {
var blob = ssb.blobGet(id);
request.send_binary(blob);
for (let arg of request.args) {
var blob;
if (arg.key) {
blob = ssb.blobGet(arg.key);
} else {
blob = ssb.blobGet(arg);
}
const k_send_max = 8192;
if (blob.byteLength > k_send_max) {
for (var i = 0; i < blob.byteLength; i += k_send_max) {
var buffer = new Uint8Array(blob, i, Math.min(blob.byteLength - i, k_send_max));
request.send_binary(buffer);
}
} else {
request.send_binary(blob);
}
request.send_json_end(true);
}
request.more(function(request) {});
});
ssb.addRpc(['gossip', 'ping'], function(request) {