move fetch options to [hostname].json
This commit is contained in:
parent
b3aafd4cc4
commit
506e2f0e2f
3 changed files with 6 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/node_modules/
|
||||
/fetch-options.*.json
|
||||
/*.json
|
||||
!/package.json
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# dl-fur
|
||||
|
||||
## `fetch-options.*.json`
|
||||
## `[hostname].json` fetch options
|
||||
|
||||
Each request will look for a corresponding `fetch-options.[hostname].json` and, if present, will use it as the second argument in all `fetch` calls.
|
||||
Each request will look for a corresponding `[hostname].json` and, if present, will use it as the second argument in all `fetch` calls.
|
||||
|
||||
For example, if you have a `cf_clearance` cookie for the Cloudflare protection in front of FurryBooru, you can create
|
||||
|
||||
```json
|
||||
// fetch-options.furry.booru.org.json
|
||||
// furry.booru.org.json
|
||||
{
|
||||
"headers": {
|
||||
"cookie": "cf_clearance=whatever",
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as stream from 'node:stream';
|
|||
const fetch_options_lookup = {};
|
||||
const fetch_200 = async url => {
|
||||
const { hostname } = new URL(url);
|
||||
const fetch_options = await (fetch_options_lookup[hostname] ??= fs.promises.readFile(new URL(`./fetch-options.${hostname}.json`, import.meta.url), 'utf8').then(JSON.parse, () => {}));
|
||||
const fetch_options = await (fetch_options_lookup[hostname] ??= fs.promises.readFile(new URL(`./${hostname}.json`, import.meta.url), 'utf8').then(JSON.parse, () => {}));
|
||||
const resp = await fetch(url, fetch_options);
|
||||
if (resp.status !== 200) {
|
||||
console.log(url, fetch_options);
|
||||
|
|
Loading…
Reference in a new issue