X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fhash-lookup.js;h=ac896164d1e338c86038a45b82e97fb263dc93cf;hb=bdfe5da9a23157deec0aea582f83143dad1a4558;hp=d9499d00d2c55beaf235ff55cf505a7dce01e059;hpb=61e966c98cd7649a60bbf30efb40eebc1702f14a;p=remoteglot diff --git a/www/js/hash-lookup.js b/www/js/hash-lookup.js index d9499d0..ac89616 100644 --- a/www/js/hash-lookup.js +++ b/www/js/hash-lookup.js @@ -7,7 +7,14 @@ var hashprobe_proto = grpc.load(PROTO_PATH).hashprobe; // TODO: Make destination configurable. var client = new hashprobe_proto.HashProbe('localhost:50051', grpc.credentials.createInsecure()); +var board = new Chess(); + var handle_request = function(fen, response) { + if (!board.validate_fen(fen).valid) { + response.writeHead(400, {}); + response.end(); + return; + } client.probe({fen: fen}, function(err, probe_response) { if (err) { response.writeHead(500, {}); @@ -20,8 +27,6 @@ var handle_request = function(fen, response) { exports.handle_request = handle_request; var handle_response = function(fen, response, probe_response) { - var board = new Chess(); - var lines = {}; var root = translate_line(board, fen, probe_response['root'], true); @@ -50,7 +55,12 @@ var translate_line = function(board, fen, line, pretty_score) { var toplay = board.turn(); if (line['move'] && line['move']['from_sq']) { - r['pretty_move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'], promotion: line['move']['promotion'] }).san; + var promo = line['move']['promotion']; + if (promo) { + r['pretty_move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'], promotion: promo.toLowerCase() }).san; + } else { + r['pretty_move'] = board.move({ from: line['move']['from_sq'], to: line['move']['to_sq'] }).san; + } } else { r['pretty_move'] = ''; }