move fetch options to [hostname].json
This commit is contained in:
parent
b3aafd4cc4
commit
506e2f0e2f
|
@ -1,2 +1,3 @@
|
||||||
/node_modules/
|
/node_modules/
|
||||||
/fetch-options.*.json
|
/*.json
|
||||||
|
!/package.json
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# dl-fur
|
# 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
|
For example, if you have a `cf_clearance` cookie for the Cloudflare protection in front of FurryBooru, you can create
|
||||||
|
|
||||||
```json
|
```json
|
||||||
// fetch-options.furry.booru.org.json
|
// furry.booru.org.json
|
||||||
{
|
{
|
||||||
"headers": {
|
"headers": {
|
||||||
"cookie": "cf_clearance=whatever",
|
"cookie": "cf_clearance=whatever",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import * as stream from 'node:stream';
|
||||||
const fetch_options_lookup = {};
|
const fetch_options_lookup = {};
|
||||||
const fetch_200 = async url => {
|
const fetch_200 = async url => {
|
||||||
const { hostname } = new URL(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);
|
const resp = await fetch(url, fetch_options);
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
console.log(url, fetch_options);
|
console.log(url, fetch_options);
|
||||||
|
|
Loading…
Reference in New Issue