Fixed lots of things about storing blobs.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3680 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-10-31 21:15:18 +00:00
parent 08cd0ec878
commit 03a2367532
3 changed files with 49 additions and 6 deletions

View File

@ -92,13 +92,27 @@ ssb.registerConnectionsChanged(function(change, connection) {
}
} else {
debug_print("blobs.get", id);
var received_bytes = 0;
var expected_bytes = message.message[id];
var buffer = new Uint8Array(expected_bytes);
connection.send_json({'name': ['blobs', 'get'], 'type': 'source', 'args': [id]}, function(message) {
debug_print(id, '=>', debug_utf8Decode(message.message));
ssb.blobStore(message.message);
buffer.set(new Uint8Array(message.message, 0, message.message.byteLength), received_bytes);
received_bytes += message.message.byteLength;
if (received_bytes == expected_bytes) {
ssb.blobStore(buffer);
}
});
}
});
});
followingDeep(g_database, [ssb.whoami()], 2).then(function(ids) {
for (let id of ids) {
var sequence = get_latest_sequence_for_author(id);
connection.send_json({'name': ['createHistoryStream'], 'type': 'source', 'args': [{'id': id, 'seq': sequence}]}, function(message) {
ssb.storeMessage(message.message.value);
});
}
});
} else if (change == 'remove') {
debug_print('REMOVE', connection.id);
delete g_wants_requests[connection.id];
@ -110,7 +124,6 @@ ssb.registerConnectionsChanged(function(change, connection) {
ssb.registerRpc(['blobs', 'createWants'], function(request) {
g_wants_requests[request.connection.id] = request;
function blob_want_discovered(id) {
debug_print('discovered', id);
var message = {};
message[id] = -1;
request.send_json(message);