mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 06:47:28 +00:00
Add feed discovery plugin
This commit is contained in:
parent
e47616bf9d
commit
5cfeea6b57
37 changed files with 2432 additions and 5 deletions
27
plugins/feed-discovery/src/validate-feed.ts
Normal file
27
plugins/feed-discovery/src/validate-feed.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { readFeedDiscoveryConfig } from "./config.js";
|
||||
import { parseFeedDocument } from "./feed-parsing.js";
|
||||
import { fetchTextWithGuards } from "./http.js";
|
||||
import type { FeedDiscoveryConfig, ValidationResult } from "./types.js";
|
||||
import { canonicalizeUrl } from "./url-safety.js";
|
||||
|
||||
export async function validateFeed(feedUrl: string, config: Partial<FeedDiscoveryConfig> = {}): Promise<ValidationResult> {
|
||||
const resolvedConfig = { ...readFeedDiscoveryConfig(), ...config };
|
||||
try {
|
||||
const response = await fetchTextWithGuards(feedUrl, resolvedConfig);
|
||||
const canonicalFeedUrl = canonicalizeUrl(response.url || feedUrl);
|
||||
const parsed = parseFeedDocument(canonicalFeedUrl, response.body, response.contentType);
|
||||
return {
|
||||
...parsed,
|
||||
feedUrl,
|
||||
canonicalFeedUrl
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
ok: false,
|
||||
feedUrl,
|
||||
kind: "unknown",
|
||||
sampleItems: [],
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue