mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-20 09:19:47 +08:00
feat(baoyu-fetch): add URL reader CLI with Chrome CDP and site adapters
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
export interface Logger {
|
||||
info(message: string): void;
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
|
||||
export function createLogger(debugEnabled = false): Logger {
|
||||
const print = (level: string, message: string): void => {
|
||||
console.error(`[${level}] ${message}`);
|
||||
};
|
||||
|
||||
return {
|
||||
info(message: string) {
|
||||
print("info", message);
|
||||
},
|
||||
warn(message: string) {
|
||||
print("warn", message);
|
||||
},
|
||||
error(message: string) {
|
||||
print("error", message);
|
||||
},
|
||||
debug(message: string) {
|
||||
if (debugEnabled) {
|
||||
print("debug", message);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
export function normalizeUrl(input: string): URL {
|
||||
try {
|
||||
return new URL(input);
|
||||
} catch {
|
||||
throw new Error(`Invalid URL: ${input}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function sanitizeFilename(input: string): string {
|
||||
return input.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "document";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user