diff --git a/src/lib/constants.js b/src/lib/constants.js index a973284..9b5eded 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -277,7 +277,7 @@ let constants = { additional_routes: [], - database_version: 8 + database_version: 9 } // Override values from config and export the result diff --git a/src/lib/utils/request.js b/src/lib/utils/request.js index 0d4dcac..2890ece 100644 --- a/src/lib/utils/request.js +++ b/src/lib/utils/request.js @@ -1,5 +1,6 @@ const NodeFetch = require("./request_backends/node-fetch") const Got = require("./request_backends/got") +const SavedRequestManager = require("./saved_requests/manager") const constants = require("../constants") @@ -7,7 +8,8 @@ const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 const backendStatusLineMap = new Map([ ["node-fetch", "NF "], - ["got", "GOT"] + ["got", "GOT"], + ["saved", "SAV"] ]) /** @@ -17,6 +19,8 @@ function request(url, options = {}, settings = {}) { if (settings.statusLine === undefined) settings.statusLine = "OUT" if (settings.log === undefined) settings.log = true if (settings.log) console.log(` -> [${settings.statusLine}-${backendStatusLineMap.get(constants.request_backend)}] ${url}`) // todo: make more like pinski? + const save = !!settings.save + if (constants.request_backend === "node-fetch") { return new NodeFetch(url, Object.assign({ headers: { @@ -32,6 +36,8 @@ function request(url, options = {}, settings = {}) { followRedirect: false, throwHttpErrors: false }, options)) + } else if (constants.request_backend === "saved") { + return new SavedRequestManager(url).request() } else { throw new Error("Invalid value for setting `request_backend`.") } diff --git a/src/lib/utils/request_backends/node-fetch.js b/src/lib/utils/request_backends/node-fetch.js index bc9287d..09881b8 100644 --- a/src/lib/utils/request_backends/node-fetch.js +++ b/src/lib/utils/request_backends/node-fetch.js @@ -10,7 +10,10 @@ class NodeFetch { } response() { - return this.instance + return this.instance.then(res => ({ + status: res.status, + headers: new Map(Object.entries(res.headers)) + })) } json() { diff --git a/src/lib/utils/upgradedb.js b/src/lib/utils/upgradedb.js index c3a85a3..9ce1f74 100644 --- a/src/lib/utils/upgradedb.js +++ b/src/lib/utils/upgradedb.js @@ -103,6 +103,15 @@ const deltas = new Map([ db.prepare("ALTER TABLE UserSettings ADD COLUMN infinite_scroll TEXT NOT NULL DEFAULT 'normal'") .run() })() + }], + // version 8 to version 9 + [9, function() { + db.transaction(() => { + db.prepare("DROP TABLE IF EXISTS SavedRequests") + .run() + db.prepare("CREATE TABLE SavedRequests (url TEXT NOT NULL, path TEXT NOT NULL, PRIMARY KEY (url))") + .run() + })() }] ])