From 4c0925157f97b662999a5ba80b8e6c3dfd3596ce Mon Sep 17 00:00:00 2001
From: pseudoyu <pseudoyu@connect.hku.hk>
Date: Mon, 2 Dec 2024 11:33:35 +0800
Subject: [PATCH] feat(route/qingting): return first page program instead of 10

---
 lib/routes/qingting/channel.ts | 18 ++++++++---------
 lib/routes/qingting/podcast.ts | 36 ++++++++++++----------------------
 2 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/lib/routes/qingting/channel.ts b/lib/routes/qingting/channel.ts
index 27c08b96c768af..8833715da67f22 100644
--- a/lib/routes/qingting/channel.ts
+++ b/lib/routes/qingting/channel.ts
@@ -1,6 +1,6 @@
 import { Route } from '@/types';
 import cache from '@/utils/cache';
-import got from '@/utils/got';
+import ofetch from '@/utils/ofetch';
 import timezone from '@/utils/timezone';
 import { parseDate } from '@/utils/parse-date';
 
@@ -18,18 +18,18 @@ export const route: Route = {
         supportScihub: false,
     },
     name: '专辑',
-    maintainers: ['nczitzk'],
+    maintainers: ['nczitzk', 'pseudoyu'],
     handler,
 };
 
 async function handler(ctx) {
     const channelUrl = `https://i.qingting.fm/capi/v3/channel/${ctx.req.param('id')}`;
-    let response = await got(channelUrl);
-    const title = response.data.data.title;
-    const programUrl = `https://i.qingting.fm/capi/channel/${ctx.req.param('id')}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`;
-    response = await got(programUrl);
+    let response = await ofetch(channelUrl);
+    const title = response.data.title;
+    const programUrl = `https://i.qingting.fm/capi/channel/${ctx.req.param('id')}/programs/${response.data.v}?curpage=1&order=asc`;
+    response = await ofetch(programUrl);
 
-    const items = response.data.data.programs.map((item) => ({
+    const items = response.data.programs.map((item) => ({
         title: item.title,
         link: `https://www.qingting.fm/channels/${ctx.req.param('id')}/programs/${item.id}/`,
         pubDate: timezone(parseDate(item.update_time), +8),
@@ -41,8 +41,8 @@ async function handler(ctx) {
         item: await Promise.all(
             items.map((item) =>
                 cache.tryGet(item.link, async () => {
-                    response = await got(item.link);
-                    const data = JSON.parse(response.data.match(/},"program":(.*?),"plist":/)[1]);
+                    response = await ofetch(item.link);
+                    const data = JSON.parse(response.match(/},"program":(.*?),"plist":/)[1]);
                     item.description = data.richtext;
                     return item;
                 })
diff --git a/lib/routes/qingting/podcast.ts b/lib/routes/qingting/podcast.ts
index 17d1c6b4bab23a..5df881379fcd6d 100644
--- a/lib/routes/qingting/podcast.ts
+++ b/lib/routes/qingting/podcast.ts
@@ -1,7 +1,7 @@
 import type { DataItem, Route } from '@/types';
 import cache from '@/utils/cache';
 import crypto from 'crypto';
-import got from '@/utils/got';
+import ofetch from '@/utils/ofetch';
 import timezone from '@/utils/timezone';
 import { parseDate } from '@/utils/parse-date';
 import { config } from '@/config';
@@ -29,7 +29,7 @@ export const route: Route = {
         },
     ],
     name: '播客',
-    maintainers: ['RookieZoe', 'huyyi'],
+    maintainers: ['RookieZoe', 'huyyi', 'pseudoyu'],
     handler,
     description: `获取的播放 URL 有效期只有 1 天,需要开启播客 APP 的自动下载功能。`,
 };
@@ -44,35 +44,27 @@ async function handler(ctx) {
     const channelId = ctx.req.param('id');
 
     const channelUrl = `https://i.qingting.fm/capi/v3/channel/${channelId}`;
-    const response = await got({
-        method: 'get',
-        url: channelUrl,
+    const response = await ofetch(channelUrl, {
         headers: {
             Referer: 'https://www.qingting.fm/',
         },
     });
 
-    const title = response.data.data.title;
-    const channel_img = response.data.data.thumbs['400_thumb'];
-    const authors = response.data.data.podcasters.map((author) => author.nick_name).join(',');
-    const desc = response.data.data.description;
-    const programUrl = `https://i.qingting.fm/capi/channel/${channelId}/programs/${response.data.data.v}?curpage=1&pagesize=10&order=asc`;
+    const title = response.data.title;
+    const channel_img = response.data.thumbs['400_thumb'];
+    const authors = response.data.podcasters.map((author) => author.nick_name).join(',');
+    const desc = response.data.description;
+    const programUrl = `https://i.qingting.fm/capi/channel/${channelId}/programs/${response.data.v}?curpage=1&pagesize=10&order=asc`;
 
     const {
-        data: {
-            data: { programs },
-        },
-    } = await got({
-        method: 'get',
-        url: programUrl,
+        data: { programs },
+    } = await ofetch(programUrl, {
         headers: {
             Referer: 'https://www.qingting.fm/',
         },
     });
 
-    const {
-        data: { data: channelInfo },
-    } = await got(`https://i.qingting.fm/capi/v3/channel/${channelId}?user_id=${qingtingId}`);
+    const { data: channelInfo } = await ofetch(`https://i.qingting.fm/capi/v3/channel/${channelId}?user_id=${qingtingId}`);
 
     const isCharged = channelInfo.purchase?.item_type !== 0;
 
@@ -83,15 +75,13 @@ async function handler(ctx) {
             const data = (await cache.tryGet(`qingting:podcast:${channelId}:${item.id}`, async () => {
                 const link = `https://www.qingting.fm/channels/${channelId}/programs/${item.id}/`;
 
-                const detailRes = await got({
-                    method: 'get',
-                    url: link,
+                const detailRes = await ofetch(link, {
                     headers: {
                         Referer: 'https://www.qingting.fm/',
                     },
                 });
 
-                const detail = JSON.parse(detailRes.data.match(/},"program":(.*?),"plist":/)[1]);
+                const detail = JSON.parse(detailRes.match(/},"program":(.*?),"plist":/)[1]);
 
                 const rssItem = {
                     title: item.title,