Bläddra i källkod

Long HTML output is now replaced with an overlay in the same way as long string output.

n1474335 6 år sedan
förälder
incheckning
b98cf9538d

+ 12 - 9
src/core/Chef.mjs

@@ -89,23 +89,26 @@ class Chef {
             progress = err.progress;
         }
 
-        // Depending on the size of the output, we may send it back as a string or an ArrayBuffer.
-        // This can prevent unnecessary casting as an ArrayBuffer can be easily downloaded as a file.
-        // The threshold is specified in KiB.
-        const threshold = (options.ioDisplayThreshold || 1024) * 1024;
-        const returnType = this.dish.size > threshold ? Dish.ARRAY_BUFFER : Dish.STRING;
-
         // Create a raw version of the dish, unpresented
         const rawDish = this.dish.clone();
 
         // Present the raw result
         await recipe.present(this.dish);
 
+        // Depending on the size of the output, we may send it back as a string or an ArrayBuffer.
+        // This can prevent unnecessary casting as an ArrayBuffer can be easily downloaded as a file.
+        // The threshold is specified in KiB.
+        const threshold = (options.ioDisplayThreshold || 1024) * 1024;
+        const returnType =
+            this.dish.size > threshold ?
+                Dish.ARRAY_BUFFER :
+                this.dish.type === Dish.HTML ?
+                    Dish.HTML :
+                    Dish.STRING;
+
         return {
             dish: rawDish,
-            result: this.dish.type === Dish.HTML ?
-                await this.dish.get(Dish.HTML, notUTF8) :
-                await this.dish.get(returnType, notUTF8),
+            result: await this.dish.get(returnType, notUTF8),
             type: Dish.enumLookup(this.dish.type),
             progress: progress,
             duration: new Date().getTime() - startTime,

+ 2 - 2
src/core/operations/Bombe.mjs

@@ -163,9 +163,9 @@ class Bombe extends Operation {
      */
     present(output) {
         let html = `Bombe run on menu with ${output.nLoops} loop${output.nLoops === 1 ? "" : "s"} (2+ desirable). Note: Rotor positions are listed left to right and start at the beginning of the crib, and ignore stepping and the ring setting. Some plugboard settings are determined. A decryption preview starting at the beginning of the crib and ignoring stepping is also provided.\n\n`;
-        html += "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Rotor stops</th><th>Partial plugboard</th><th>Decryption preview</th></tr>";
+        html += "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Rotor stops</th>  <th>Partial plugboard</th>  <th>Decryption preview</th></tr>\n";
         for (const [setting, stecker, decrypt] of output.result) {
-            html += `<tr><td>${setting}</td><td>${stecker}</td><td>${decrypt}</td></tr>\n`;
+            html += `<tr><td>${setting}</td>  <td>${stecker}</td>  <td>${decrypt}</td></tr>\n`;
         }
         html += "</table>";
         return html;

+ 2 - 2
src/core/operations/MultipleBombe.mjs

@@ -292,9 +292,9 @@ class MultipleBombe extends Operation {
 
         for (const run of output.bombeRuns) {
             html += `\nRotors: ${run.rotors.slice().reverse().join(", ")}\nReflector: ${run.reflector}\n`;
-            html += "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Rotor stops</th><th>Partial plugboard</th><th>Decryption preview</th></tr>";
+            html += "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Rotor stops</th>  <th>Partial plugboard</th>  <th>Decryption preview</th></tr>\n";
             for (const [setting, stecker, decrypt] of run.result) {
-                html += `<tr><td>${setting}</td><td>${stecker}</td><td>${decrypt}</td></tr>\n`;
+                html += `<tr><td>${setting}</td>  <td>${stecker}</td>  <td>${decrypt}</td></tr>\n`;
             }
             html += "</table>\n";
         }

+ 6 - 6
tests/operations/tests/Bombe.mjs

@@ -11,7 +11,7 @@ TestRegister.addTests([
         // Plugboard for this test is BO LC KE GA
         name: "Bombe: 3 rotor (self-stecker)",
         input: "BBYFLTHHYIJQAYBBYS",
-        expectedMatch: /<td>LGA<\/td><td>SS<\/td><td>VFISUSGTKSTMPSUNAK<\/td>/,
+        expectedMatch: /<td>LGA<\/td> {2}<td>SS<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
         recipeConfig: [
             {
                 "op": "Bombe",
@@ -31,7 +31,7 @@ TestRegister.addTests([
         // This test produces a menu that doesn't use the first letter, which is also a good test
         name: "Bombe: 3 rotor (other stecker)",
         input: "JBYALIHDYNUAAVKBYM",
-        expectedMatch: /<td>LGA<\/td><td>AG<\/td><td>QFIMUMAFKMQSKMYNGW<\/td>/,
+        expectedMatch: /<td>LGA<\/td> {2}<td>AG<\/td> {2}<td>QFIMUMAFKMQSKMYNGW<\/td>/,
         recipeConfig: [
             {
                 "op": "Bombe",
@@ -50,7 +50,7 @@ TestRegister.addTests([
     {
         name: "Bombe: crib offset",
         input: "AAABBYFLTHHYIJQAYBBYS", // first three chars here are faked
-        expectedMatch: /<td>LGA<\/td><td>SS<\/td><td>VFISUSGTKSTMPSUNAK<\/td>/,
+        expectedMatch: /<td>LGA<\/td> {2}<td>SS<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
         recipeConfig: [
             {
                 "op": "Bombe",
@@ -69,7 +69,7 @@ TestRegister.addTests([
     {
         name: "Bombe: multiple stops",
         input: "BBYFLTHHYIJQAYBBYS",
-        expectedMatch: /<td>LGA<\/td><td>TT<\/td><td>VFISUSGTKSTMPSUNAK<\/td>/,
+        expectedMatch: /<td>LGA<\/td> {2}<td>TT<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
         recipeConfig: [
             {
                 "op": "Bombe",
@@ -88,7 +88,7 @@ TestRegister.addTests([
     {
         name: "Bombe: checking machine",
         input: "BBYFLTHHYIJQAYBBYS",
-        expectedMatch: /<td>LGA<\/td><td>TT AG BO CL EK FF HH II JJ SS YY<\/td><td>THISISATESTMESSAGE<\/td>/,
+        expectedMatch: /<td>LGA<\/td> {2}<td>TT AG BO CL EK FF HH II JJ SS YY<\/td> {2}<td>THISISATESTMESSAGE<\/td>/,
         recipeConfig: [
             {
                 "op": "Bombe",
@@ -108,7 +108,7 @@ TestRegister.addTests([
     {
         name: "Bombe: 4 rotor",
         input: "LUOXGJSHGEDSRDOQQX",
-        expectedMatch: /<td>LHSC<\/td><td>SS<\/td><td>HHHSSSGQUUQPKSEKWK<\/td>/,
+        expectedMatch: /<td>LHSC<\/td> {2}<td>SS<\/td> {2}<td>HHHSSSGQUUQPKSEKWK<\/td>/,
         recipeConfig: [
             {
                 "op": "Bombe",

+ 1 - 1
tests/operations/tests/MultipleBombe.mjs

@@ -10,7 +10,7 @@ TestRegister.addTests([
     {
         name: "Multi-Bombe: 3 rotor",
         input: "BBYFLTHHYIJQAYBBYS",
-        expectedMatch: /<td>LGA<\/td><td>SS<\/td><td>VFISUSGTKSTMPSUNAK<\/td>/,
+        expectedMatch: /<td>LGA<\/td> {2}<td>SS<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
         recipeConfig: [
             {
                 "op": "Multiple Bombe",