From db9d5cee3c93a40a8b13624a6d009218653d8e0d Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 23 Dec 2024 17:51:45 +0800 Subject: [PATCH] feat: add home-assistant route --- lib/routes/home-assistant/hacs.ts | 50 ++++++++++++++++++++++++++ lib/routes/home-assistant/namespace.ts | 7 ++++ 2 files changed, 57 insertions(+) create mode 100644 lib/routes/home-assistant/hacs.ts create mode 100644 lib/routes/home-assistant/namespace.ts diff --git a/lib/routes/home-assistant/hacs.ts b/lib/routes/home-assistant/hacs.ts new file mode 100644 index 00000000000000..14580fbbbee251 --- /dev/null +++ b/lib/routes/home-assistant/hacs.ts @@ -0,0 +1,50 @@ +import { Route } from '@/types'; + +import ofetch from '@/utils/ofetch'; + +export const route: Route = { + path: '/hacs/repositories', + name: 'HACS Repositories', + maintainers: ['DIYgod'], + categories: ['program-update'], + example: '/home-assistant/hacs/repositories', + handler, +}; + +async function handler() { + const sections = ['appdaemon', 'critical', 'integration', 'theme', 'python_script', 'plugin']; + const dataList = ( + await Promise.all( + sections.map(async (section) => { + const url = `https://data-v2.hacs.xyz/${section}/data.json`; + const response = await ofetch(url); + return Object.values(response); + }) + ) + ).flat() as { + manifest: { + name: string; + }; + manifest_name: string; + description: string; + full_name: string; + domain: string; + stargazers_count: number; + topics?: string[]; + last_updated: string; + last_fetched: number; + }[]; + + return { + title: 'HACS Repositories', + link: `https://www.hacs.xyz/`, + item: dataList.map((item) => ({ + title: item.manifest_name || item.manifest?.name || item.full_name, + description: `${item.domain ? `` : ''}
${item.description}

Last updated: ${item.last_updated}
Stars: ${item.stargazers_count}
Topics: ${item.topics?.join(', ')}`, + link: `https://github.com/${item.full_name}`, + guid: item.domain || item.full_name, + tags: item.topics, + pubDate: new Date(item.last_fetched * 1000), + })), + }; +} diff --git a/lib/routes/home-assistant/namespace.ts b/lib/routes/home-assistant/namespace.ts new file mode 100644 index 00000000000000..6764c4fb2fee8d --- /dev/null +++ b/lib/routes/home-assistant/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Home Assistant', + url: 'www.home-assistant.io', + lang: 'en', +};