Add resolver, server, PDF rendering and web app
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
6a7fcdc4b8
commit
bdfdf581f3
59 files changed
+4088
No files matched your search
@@ -0,0 +1,29 @@
|
||||
export class TemporaryError extends Error {}
|
||||
|
||||
export interface SourceCache { get(key: string): string | null; set(key: string, body: string): void }
|
||||
|
||||
export const USER_AGENT = 'booksorter/0.1 (personal library tool)';
|
||||
|
||||
export interface HttpResult { status: number; body: string }
|
||||
|
||||
/** One GET. Network errors and 5xx/429 become TemporaryError; other statuses are returned. */
|
||||
export async function getText(f: typeof fetch, url: string): Promise<HttpResult> {
|
||||
let res: Response;
|
||||
try {
|
||||
res = await f(url, { headers: { 'User-Agent': USER_AGENT } });
|
||||
} catch (e) {
|
||||
throw new TemporaryError(`Network error for ${url}: ${(e as Error).message}`);
|
||||
}
|
||||
if (res.status >= 500 || res.status === 429) throw new TemporaryError(`HTTP ${res.status} from ${url}`);
|
||||
let body: string;
|
||||
try {
|
||||
body = await res.text();
|
||||
} catch (e) {
|
||||
throw new TemporaryError(`Network error reading ${url}: ${(e as Error).message}`);
|
||||
}
|
||||
return { status: res.status, body };
|
||||
}
|
||||
|
||||
export function trimPunct(s: string): string {
|
||||
return s.replace(/[\s\/,:;.]+$/, '').trim();
|
||||
}
|
||||
Reference in new issue
Block a user