forked from cory/tildefriends
		
	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:
		
							
								
								
									
										21
									
								
								core/ssb.js
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								core/ssb.js
									
									
									
									
									
								
							| @@ -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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user