move fetch options to own directory; only send special user-agent to e621 API
This commit is contained in:
parent
b8f5929b07
commit
ed3c8bcc00
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1 @@
|
||||
/node_modules/
|
||||
/*.json
|
||||
!/package.json
|
||||
!/package-lock.json
|
||||
|
18
README.md
18
README.md
@ -1,23 +1,5 @@
|
||||
# fetch-booru
|
||||
|
||||
## `[hostname].json` fetch options
|
||||
|
||||
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 a given site, you can create
|
||||
|
||||
```json
|
||||
// example.com.json
|
||||
{
|
||||
"headers": {
|
||||
"cookie": "cf_clearance=whatever",
|
||||
"user-agent": "whatever"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
and this cookie and user-agent will be used for API calls and for downloading the images.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
11
fetch_options/README.md
Normal file
11
fetch_options/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# `fetch_options/[hostname].json`
|
||||
|
||||
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.
|
||||
|
||||
For example, if you have a `cf_clearance` cookie for the Cloudflare protection in front of a given site, you can create `fetch_options/example.com.json`
|
||||
|
||||
```json
|
||||
{ "headers": { "cookie": "cf_clearance=whatever", "user-agent": "whatever" } }
|
||||
```
|
||||
|
||||
and this cookie and user-agent will be used for network calls to `example.com`. Note that these will not automatically apply to subdomains.
|
1
fetch_options/e621.net.json
Normal file
1
fetch_options/e621.net.json
Normal file
@ -0,0 +1 @@
|
||||
{ "headers": { "user-agent": "fetch-booru (+https://git.chor.date/Conduitry/fetch-booru)" } }
|
@ -4,7 +4,7 @@ import { log } from './log.js';
|
||||
const fetch_options_lookup = {};
|
||||
export async function fetch_retry(url) {
|
||||
const { hostname } = new URL(url);
|
||||
const fetch_options = await (fetch_options_lookup[hostname] ??= fs.promises.readFile(new URL(`../${hostname}.json`, import.meta.url), 'utf8').then(JSON.parse).catch(() => ({ headers: { 'user-agent': 'fetch-booru (+https://git.chor.date/Conduitry/fetch-booru)' } })));
|
||||
const fetch_options = await (fetch_options_lookup[hostname] ??= fs.promises.readFile(new URL(`../fetch_options/${hostname}.json`, import.meta.url), 'utf8').then(JSON.parse).catch(() => {}));
|
||||
for (;;) {
|
||||
let resp;
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user