Explorar el Código

fix failstates not triggering properly

lolcat hace 18 horas
padre
commit
e830a8f372
Se han modificado 1 ficheros con 39 adiciones y 43 borrados
  1. 39 43
      extra/4play/page-render.js

+ 39 - 43
extra/4play/page-render.js

@@ -239,78 +239,74 @@ fplay.event.on("web_response", async function(page){
 	var fail_url_match = page.url.match(new RegExp(callback_data.fail_url_match, "i"));
 	var fail_content_match = body.match(new RegExp(callback_data.fail_content_match, "i"));
 	
-	// handle positive response
+	// handle negative response
 	if(
 		(
-			callback_data.url_match === null &&
-			callback_data.content_match === null
-		) ||
-		(
-			url_match &&
-			content_match
-		) ||
-		(
-			url_match &&
-			callback_data.content_match === null
-		) ||
+			callback_data.fail_url_match !== null ||
+			callback_data.fail_content_match !== null
+		) &&
 		(
-			callback_data.url_match === null &&
-			content_match
+			fail_url_match !== null ||
+			fail_content_match !== null
 		)
 	){
 		
 		callback_data.http_res.writeHead(
-			200,
+			400,
 			{
-				"Content-Type": "text/plain;charset=UTF-8",
+				"Content-Type": "text/plain",
 				"X-Proxy": callback_data.proxy.raw,
-				"X-Container-ID": typeof callback_data.container.id == "undefined" ? callback_data.container : callback_data.container.id
+				"X-Container-ID": callback_data.container.id
 			}
 		);
 		
-		callback_data.http_res.end(body);
+		callback_data.http_res.end("Reached fail state (matched fail_url_match or fail_content_match)");
+		
+		// cleanup browser + callback
+		await fplay.tab_close(global_ws, page.id);
+		await fplay.container_delete(global_ws, callback_data.container);
+		callback_q.delete(page.id);
 		
-		callback_q.delete(page.id); // cleanup callback only
 		return;
 	}
 	
-	// handle negative response
+	// handle positive response
 	if(
 		(
-			callback_data.fail_url_match !== null &&
-			callback_data.fail_content_match !== null
-		) &&
+			callback_data.url_match === null &&
+			callback_data.content_match === null
+		) ||
+		(
+			callback_data.url_match !== null &&
+			callback_data.content_match !== null &&
+			url_match &&
+			content_match
+		) ||
+		(
+			callback_data.url_match === null &&
+			callback_data.content_match !== null &&
+			content_match
+		) ||
 		(
-			(
-				fail_url_match &&
-				fail_content_match
-			) ||
-			(
-				fail_url_match &&
-				callback_data.fail_content_match === null
-			) ||
-			(
-				callback_data.fail_url_match === null &&
-				fail_content_match
-			)
+			callback_data.url_match !== null &&
+			callback_data.content_match === null &&
+			url_match
 		)
 	){
 		
 		callback_data.http_res.writeHead(
-			400,
+			200,
 			{
-				"Content-Type": "text/plain",
+				"Content-Type": "text/plain;charset=UTF-8",
 				"X-Proxy": callback_data.proxy.raw,
-				"X-Container-ID": callback_data.container.id
+				"X-Container-ID": typeof callback_data.container.id == "undefined" ? callback_data.container : callback_data.container.id
 			}
 		);
 		
-		callback_data.http_res.end("Reached fail state (matched fail_url_match or fail_content_match)");
+		callback_data.http_res.end(body);
 		
-		// cleanup browser + callback
-		await fplay.tab_close(global_ws, page.id);
-		await fplay.container_delete(global_ws, callback_data.container);
-		callback_q.delete(page.id);
+		callback_q.delete(page.id); // cleanup callback only
+		return;
 	}
 });