Files
RSSHub/lib/routes/winstall/update.tsx
T
DIYgod cf4e772de8 refactor: replace art template with jsx (#20777)
* refactor: replace art template with jsx

* fix: tsx files

* fix: renderToString import

* fix: hono html raw import

* feat: remove art
2025-12-29 12:27:32 +08:00

79 lines
2.1 KiB
TypeScript

import { load } from 'cheerio';
import { renderToString } from 'hono/jsx/dom/server';
import { config } from '@/config';
import type { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
const renderDesc = (installers?: string[]) =>
renderToString(
<>
{installers?.map((installer) => (
<>
<a href={installer}>{installer}</a>
<br />
</>
))}
</>
);
export const route: Route = {
path: '/:appId',
categories: ['program-update'],
example: '/winstall/Mozilla.Firefox',
parameters: { appId: 'Application ID' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['winstall.app/apps/:appId'],
},
],
name: 'Apps Update',
maintainers: ['TonyRL'],
handler,
};
async function handler(ctx) {
const baseUrl = 'https://winstall.app';
const appId = ctx.req.param('appId');
const buildId = await cache.tryGet(
'winget:buildId',
async () => {
const { data } = await got(baseUrl);
const $ = load(data);
return JSON.parse($('#__NEXT_DATA__').text()).buildId;
},
config.cache.routeExpire,
false
);
const { data: response } = await got(`${baseUrl}/_next/data/${buildId}/apps/${appId}.json`);
const { app } = response.pageProps;
const items = app.versions.map((item) => ({
title: `${app.name} ${item.version}`,
description: renderDesc(item.installers),
author: app.publisher,
category: app.tags,
guid: `winstall:${appId}:${item.version}`,
}));
return {
title: `${app.name} - winstall`,
description: app.desc,
link: `${baseUrl}/apps/${appId}`,
image: `https://api.winstall.app/icons/next/${appId}.webp`,
language: 'en',
item: items,
};
}