mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
Centralize and standardize User-Agent string
Introduce a centralized RMAB_USER_AGENT constant (ReadMeABook/<version>) and update audible service calls to use it instead of hardcoded values. This avoids the default axios UA (which some indexers reject) and replaces the previous `rmab/` identifier. Adds unit tests to verify the User-Agent format and ensure it doesn't resemble generic bot signatures.
This commit is contained in:
@@ -677,7 +677,7 @@ export class AudibleService {
|
|||||||
{
|
{
|
||||||
params: { region: audnexusRegion },
|
params: { region: audnexusRegion },
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
headers: { 'User-Agent': 'ReadMeABook/1.0' },
|
headers: { 'User-Agent': RMAB_USER_AGENT },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -768,7 +768,7 @@ export class AudibleService {
|
|||||||
{
|
{
|
||||||
params: { region: audnexusRegion },
|
params: { region: audnexusRegion },
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
headers: { 'User-Agent': 'ReadMeABook/1.0' },
|
headers: { 'User-Agent': RMAB_USER_AGENT },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* Component: User-Agent Constant
|
||||||
|
*
|
||||||
|
* Centralized User-Agent string used for all outbound HTTP requests.
|
||||||
|
* Replaces the default `axios/x.y.z` UA, which is rejected by some
|
||||||
|
* indexers (e.g., NZBFinder) as a generic-bot signature.
|
||||||
|
*/
|
||||||
|
|
||||||
import { version } from '../../../package.json';
|
import { version } from '../../../package.json';
|
||||||
|
|
||||||
export const RMAB_USER_AGENT = `rmab/${version}`;
|
export const RMAB_USER_AGENT = `ReadMeABook/${version}`;
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { RMAB_USER_AGENT } from '@/lib/utils/user-agent';
|
||||||
|
|
||||||
|
describe('RMAB_USER_AGENT', () => {
|
||||||
|
it('uses the ReadMeABook/<semver> format', () => {
|
||||||
|
expect(RMAB_USER_AGENT).toMatch(/^ReadMeABook\/\d+\.\d+\.\d+/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not look like a generic bot signature', () => {
|
||||||
|
expect(RMAB_USER_AGENT).not.toMatch(/^axios\//);
|
||||||
|
expect(RMAB_USER_AGENT).not.toMatch(/^rmab\//);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user