"Improving stability of build and packaging."
This commit is contained in:
parent
fa8acff742
commit
56dcdcec16
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
67
archivist.js
67
archivist.js
|
@ -6,6 +6,7 @@ import args from './args.js';
|
|||
import {APP_ROOT, context, sleep, DEBUG} from './common.js';
|
||||
import {connect} from './protocol.js';
|
||||
import {getInjection} from './public/injection.js';
|
||||
import {BLOCKED_BODY, BLOCKED_CODE, BLOCKED_HEADERS} from './blockedResponse.js';
|
||||
|
||||
//import xapian from 'xapian';
|
||||
|
||||
|
@ -74,7 +75,7 @@ async function collect({chrome_port:port, mode} = {}) {
|
|||
const Sessions = new Map();
|
||||
const Installations = new Set();
|
||||
const ConfirmedInstalls = new Set();
|
||||
const DELAY = 500;
|
||||
const DELAY = 100; // 500 ?
|
||||
Close = close;
|
||||
Mode = mode;
|
||||
|
||||
|
@ -263,7 +264,15 @@ async function collect({chrome_port:port, mode} = {}) {
|
|||
}
|
||||
|
||||
async function cacheRequest(pausedRequest) {
|
||||
const {requestId, request, resourceType, responseStatusCode, responseHeaders} = pausedRequest;
|
||||
const {
|
||||
requestId, request, resourceType,
|
||||
responseStatusCode, responseHeaders, responseErrorReason
|
||||
} = pausedRequest;
|
||||
const {url} = request;
|
||||
const isNavigationRequest = resourceType == "Document";
|
||||
const isFont = resourceType == "Font";
|
||||
|
||||
|
||||
if ( dontCache(request) ) {
|
||||
DEBUG && console.log("Not caching", request.url);
|
||||
return send("Fetch.continueRequest", {requestId});
|
||||
|
@ -286,32 +295,58 @@ async function collect({chrome_port:port, mode} = {}) {
|
|||
}
|
||||
} else if ( Mode == 'save' ) {
|
||||
const response = {key, responseCode: responseStatusCode, responseHeaders};
|
||||
let resp;
|
||||
if ( ! BODYLESS.has(responseStatusCode) ) {
|
||||
resp = await send("Fetch.getResponseBody", {requestId});
|
||||
} else {
|
||||
resp = {body:'', base64Encoded:true};
|
||||
}
|
||||
if ( ! resp ) {
|
||||
DEBUG && console.warn("get response body error", key, responseStatusCode, responseHeaders, pausedRequest.responseErrorReason);
|
||||
await sleep(DELAY);
|
||||
return send("Fetch.continueRequest", {requestId});
|
||||
}
|
||||
const resp = await getBody({requestId, responseStatusCode});
|
||||
if ( !! resp ) {
|
||||
let {body, base64Encoded} = resp;
|
||||
if ( ! base64Encoded ) {
|
||||
body = b64(body);
|
||||
}
|
||||
response.body = body;
|
||||
const responsePath = await saveResponseData(key, request.url, response);
|
||||
State.Cache.set(key, responsePath);
|
||||
} else {
|
||||
DEBUG && console.warn("get response body error", key, responseStatusCode, responseHeaders, pausedRequest.responseErrorReason);
|
||||
response.body = '';
|
||||
}
|
||||
const responsePath = await saveResponseData(key, request.url, response);
|
||||
State.Cache.set(key, responsePath);
|
||||
await sleep(DELAY);
|
||||
await send("Fetch.continueRequest", {requestId});
|
||||
if ( !isFont && responseErrorReason ) {
|
||||
if ( isNavigationRequest ) {
|
||||
await send("Fetch.fulfillRequest", {
|
||||
requestId,
|
||||
responseHeaders: BLOCKED_HEADERS,
|
||||
responseCode: BLOCKED_CODE,
|
||||
body: Buffer.from(responseErrorReason).toString("base64"),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await send("Fetch.failRequest", {
|
||||
requestId,
|
||||
errorReason: responseErrorReason
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await send("Fetch.continueRequest", {
|
||||
requestId,
|
||||
},
|
||||
);
|
||||
} catch(e) {
|
||||
console.warn("Issue with continuing request", e, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getBody({requestId, responseStatusCode}) {
|
||||
let resp;
|
||||
if ( ! BODYLESS.has(responseStatusCode) ) {
|
||||
resp = await send("Fetch.getResponseBody", {requestId});
|
||||
} else {
|
||||
resp = {body:'', base64Encoded:true};
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
function dontCache(request) {
|
||||
if ( ! request.url ) return false;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
export const BLOCKED_CODE = 200;
|
||||
export const BLOCKED_BODY = Buffer.from(`
|
||||
<style>:root { font-family: system-ui, monospace; }</style>
|
||||
<h1>Request blocked</h1>
|
||||
<p>This navigation was prevented by 22120 as a Chrome bug fix for some requests causing issues.</p>
|
||||
`).toString("base64");
|
||||
export const BLOCKED_HEADERS = [
|
||||
{name: "X-Powered-By", value: "Dosyago-Corporation"},
|
||||
{name: "X-Blocked-Internally", value: "Custom 22120 Chrome bug fix"},
|
||||
{name: "Accept-Ranges", value: "bytes"},
|
||||
{name: "Cache-Control", value: "public, max-age=0"},
|
||||
{name: "Content-Type", value: "text/html; charset=UTF-8"},
|
||||
{name: "Content-Length", value: `${BLOCKED_BODY.length}`}
|
||||
];
|
||||
|
||||
const BLOCKED_RESPONSE = `
|
||||
HTTP/1.1 ${BLOCKED_CODE} OK
|
||||
X-Powered-By: Zanj-Dosyago-Corporation
|
||||
X-Blocked-Internally: Custom ad blocking
|
||||
Accept-Ranges: bytes
|
||||
Cache-Control: public, max-age=0
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: ${BLOCKED_BODY.length}
|
||||
|
||||
${BLOCKED_BODY}
|
||||
`;
|
||||
|
||||
export default BLOCKED_RESPONSE;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
|
||||
// determine where this code is running
|
||||
let Context = 'unknown';
|
||||
|
||||
|
@ -24,7 +25,8 @@ export const DEBUG = process.env.DEBUG_22120 || false;
|
|||
|
||||
export const NO_SANDBOX = process.env.DEBUG_22120 || false;
|
||||
|
||||
export const APP_ROOT = __dirname;
|
||||
//export const APP_ROOT = __dirname;
|
||||
export const APP_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export const sleep = ms => new Promise(res => setTimeout(res, ms));
|
||||
|
||||
|
|
|
@ -7,4 +7,5 @@ nvm install v14.15.3
|
|||
nvm use v14.15.3
|
||||
|
||||
npx webpack
|
||||
chmod +x 22120.js
|
||||
npx nexe -t windows -i 22120.js -r \"./?.22120.js\" -r \"./public/*\" && npx nexe -t linux-x64 -o 22120.nix -i 22120.js -r \"./?.22120.js\" -r \"./public/*\" && npx nexe -t macos-x64 -o 22120.mac -i 22120.js -r \"./?.22120.js\" -r \"./public/*\" && npx nexe -t windows-x32 -o 22120.win32.exe -i 22120.js -r \"./?.22120.js\" -r \"./public/*\" && npx nexe -t linux-x32 -o 22120.nix32 -i 22120.js -r \"./?.22120.js\" -r \"./public/*\"
|
||||
|
|
|
@ -3,10 +3,10 @@ import path from 'path';
|
|||
import express from 'express';
|
||||
|
||||
import args from './args.js';
|
||||
import {say, sleep} from './common.js';
|
||||
import {say, sleep, APP_ROOT} from './common.js';
|
||||
import Archivist from './archivist.js';
|
||||
|
||||
const SITE_PATH = path.resolve(__dirname, 'public');
|
||||
const SITE_PATH = path.resolve(APP_ROOT, 'public');
|
||||
|
||||
const app = express();
|
||||
const INDEX_FILE = args.index_file;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"chrome-launcher": "latest",
|
||||
"esm": "latest",
|
||||
"esm": "^3.2.25",
|
||||
"express": "latest",
|
||||
"hasha": "latest",
|
||||
"node-fetch": "latest",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"version": "1.3.15",
|
||||
"description": "Library server and an archivist browser controller.",
|
||||
"main": "index.js",
|
||||
"module": "app.js",
|
||||
"bin": {
|
||||
"archivist1": "22120.js"
|
||||
},
|
||||
|
@ -32,7 +33,7 @@
|
|||
"homepage": "https://github.com/dosyago/22120#readme",
|
||||
"dependencies": {
|
||||
"chrome-launcher": "latest",
|
||||
"esm": "latest",
|
||||
"esm": "^3.2.25",
|
||||
"express": "latest",
|
||||
"hasha": "latest",
|
||||
"node-fetch": "latest",
|
||||
|
|
Loading…
Reference in New Issue