vibe coded v1
This commit is contained in:
31
api/services/providers/generic.ts
Normal file
31
api/services/providers/generic.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { RichContent } from "../../model/interfaces.ts";
|
||||
import type { RichContentProvider } from "../rich-content-service.ts";
|
||||
import { extractOgTag, fetchWithTimeout } from "../rich-content-service.ts";
|
||||
|
||||
export const genericProvider: RichContentProvider = {
|
||||
name: "generic",
|
||||
|
||||
matches(_url: string): boolean {
|
||||
return true; // fallback — always matches
|
||||
},
|
||||
|
||||
async fetch(url: string): Promise<RichContent> {
|
||||
const res = await fetchWithTimeout(url);
|
||||
const contentType = res.headers.get("content-type") ?? "";
|
||||
|
||||
if (!contentType.startsWith("text/html")) {
|
||||
return { type: "generic", url };
|
||||
}
|
||||
|
||||
const html = await res.text();
|
||||
|
||||
return {
|
||||
type: "generic",
|
||||
url,
|
||||
title: extractOgTag(html, "title"),
|
||||
description: extractOgTag(html, "description"),
|
||||
thumbnailUrl: extractOgTag(html, "image"),
|
||||
siteName: extractOgTag(html, "site_name"),
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user