]> git.sesse.net Git - remoteglot/commitdiff
Make the JavaScript validate the FENs before sending them off to the server, which...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 20 Mar 2016 23:01:43 +0000 (00:01 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 20 Mar 2016 23:01:43 +0000 (00:01 +0100)
www/js/hash-lookup.js

index d9499d00d2c55beaf235ff55cf505a7dce01e059..9ecca5389009227a14bef7d785af39f52a989ba3 100644 (file)
@@ -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());
 
 // 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) {
 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, {});
        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) {
 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);
        var lines = {};
 
        var root = translate_line(board, fen, probe_response['root'], true);