rss.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { supabase } from '@/integrations/supabase/client';
  2. interface RSSFeed {
  3. url: string;
  4. title: string;
  5. type: string;
  6. }
  7. interface FetchRSSResult {
  8. rssUrl: string;
  9. siteName: string;
  10. feeds?: RSSFeed[];
  11. }
  12. export async function fetchWebsiteRSS(url: string): Promise<FetchRSSResult | null> {
  13. try {
  14. console.log('Fetching RSS for website:', url);
  15. const { data, error } = await supabase.functions.invoke('fetch-website-rss', {
  16. body: { url }
  17. });
  18. if (error) {
  19. console.error('Error calling fetch-website-rss:', error);
  20. return null;
  21. }
  22. if (!data.success) {
  23. console.error('RSS detection failed:', data.error);
  24. return null;
  25. }
  26. return {
  27. rssUrl: data.rssUrl,
  28. siteName: data.siteName,
  29. feeds: data.feeds,
  30. };
  31. } catch (error) {
  32. console.error('Error fetching website RSS:', error);
  33. return null;
  34. }
  35. }
  36. export function isValidWebsiteUrl(url: string): boolean {
  37. try {
  38. const urlObj = new URL(url);
  39. return urlObj.protocol === 'http:' || urlObj.protocol === 'https:';
  40. } catch {
  41. return false;
  42. }
  43. }
  44. export function isDirectRSSFeed(url: string): boolean {
  45. return url.includes('.xml') || url.includes('/feed') || url.includes('/rss') || url.includes('/atom');
  46. }