Skip to content

Commit

Permalink
fix(route/abc): undefine item url & use ofetch
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Nov 2, 2024
1 parent eda1e39 commit 5fe242a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/routes/abc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';

export const route: Route = {
path: '/:category{.+}?',
example: '/wa',
radar: [
{
source: ['abc.net.au/:category*'],
Expand All @@ -30,7 +31,7 @@ export const route: Route = {
The supported channels are all listed in the table below. For other channels, please find the \`documentId\` in the source code of the channel page and fill it in as above.
:::`,
maintainers: ['nczitzk'],
maintainers: ['nczitzk', 'pseudoyu'],
handler,
};

Expand All @@ -50,18 +51,18 @@ async function handler(ctx) {
documentId = category;
const feedUrl = new URL(`news/feed/${documentId}/rss.xml`, rootUrl).href;

const { data: feedResponse } = await got(feedUrl);
const feedResponse = await ofetch(feedUrl);
currentUrl = feedResponse.match(/<link>([\w-./:?]+)<\/link>/)[1];
}

const { data: currentResponse } = await got(currentUrl);
const currentResponse = await ofetch(currentUrl);

const $ = load(currentResponse);

documentId = documentId ?? $('div[data-uri^="coremedia://collection/"]').first().prop('data-uri').split(/\//).pop();

const { data: response } = await got(apiUrl, {
searchParams: {
const response = await ofetch(apiUrl, {
query: {
name: 'PaginationArticles',
documentId,
size: limit,
Expand All @@ -71,7 +72,7 @@ async function handler(ctx) {
let items = response.collection.slice(0, limit).map((i) => {
const item = {
title: i.title.children ?? i.title,
link: new URL(i.link.to, rootUrl).href,
link: i.link.startsWith('/listen/programs/') ? new URL(i.link, rootUrl).href : i.link,
description: art(path.join(__dirname, 'templates/description.art'), {
image: i.image
? {
Expand Down Expand Up @@ -99,7 +100,7 @@ async function handler(ctx) {
items.map((item) =>
cache.tryGet(item.link, async () => {
try {
const { data: detailResponse } = await got(item.link);
const detailResponse = await ofetch(item.link);

const content = load(detailResponse);

Expand Down Expand Up @@ -173,7 +174,7 @@ async function handler(ctx) {
)
);

const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href;
const icon = new URL($('link[rel="apple-touch-icon"]').prop('href') || '', rootUrl).href;

return {
item: items,
Expand Down

0 comments on commit 5fe242a

Please sign in to comment.