mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 08:07:30 +00:00
Automatically download test files when required
This commit is contained in:
parent
c3455ec183
commit
642e543fd6
@ -5,6 +5,7 @@ const {promisify} = require("util")
|
||||
const crypto = require("crypto")
|
||||
const stream = require("stream")
|
||||
|
||||
const constants = require("../../constants")
|
||||
const db = require("../../db")
|
||||
const Saved = require("../request_backends/saved")
|
||||
const NodeFetch = require("../request_backends/node-fetch")
|
||||
@ -56,9 +57,32 @@ class SavedRequestManager {
|
||||
request() {
|
||||
const row = db.prepare("SELECT * FROM SavedRequests WHERE url = ?").get(this.url)
|
||||
if (row) {
|
||||
console.log("Found, using saved request for "+row.path)
|
||||
const base = pj(folder, row.path)
|
||||
return new Saved(base)
|
||||
try {
|
||||
fs.accessSync(base)
|
||||
console.log("Found, using saved request for "+row.path)
|
||||
return new Saved(base)
|
||||
} catch (e) {
|
||||
console.log("Known, but not downloaded for "+row.path)
|
||||
|
||||
function download(name) {
|
||||
return new NodeFetch(constants.external.saved_requests_location+name).stream().then(readable => {
|
||||
return promisify(stream.pipeline)(
|
||||
readable,
|
||||
fs.createWriteStream(pj(folder, name))
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return new DelayedBackend(
|
||||
Promise.all([
|
||||
download(row.path),
|
||||
download(row.path + ".meta.json")
|
||||
]).then(() => {
|
||||
return this.clone().request()
|
||||
})
|
||||
)
|
||||
}
|
||||
} else {
|
||||
const name = generateName()
|
||||
console.log("Not found, saving now as "+name)
|
||||
|
@ -18,12 +18,13 @@ const cookies = {
|
||||
}
|
||||
}
|
||||
|
||||
function generateSetup(pageName, url, sizeName, cookiesName) {
|
||||
function generateSetup(pageName, url, sizeName, cookiesName, scrolls) {
|
||||
return {
|
||||
url: url,
|
||||
filename: `${pageName}-${sizeName}-${cookiesName}`,
|
||||
size: sizes[sizeName],
|
||||
cookies: cookies[cookiesName]
|
||||
cookies: cookies[cookiesName],
|
||||
scrolls: scrolls
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +32,8 @@ module.exports = [
|
||||
generateSetup("home", "/", "laptop", "default"),
|
||||
generateSetup("settings", "/settings", "laptop", "default"),
|
||||
generateSetup("home", "/", "phone", "default"),
|
||||
generateSetup("settings", "/settings", "phone", "default"),
|
||||
|
||||
generateSetup("home", "/", "laptop", "ptc"),
|
||||
generateSetup("settings", "/settings", "laptop", "ptc"),
|
||||
generateSetup("home", "/", "phone", "ptc"),
|
||||
|
Loading…
Reference in New Issue
Block a user