refactor(route/techpowerup): replace got with ofetch (#19918)
This commit is contained in:
parent
aae0386d9e
commit
97913ccaa4
|
|
@ -1,6 +1,6 @@
|
|||
import { Route } from '@/types';
|
||||
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 { baseUrl, headers, fixImages, parseReviews } from './utils';
|
||||
|
|
@ -10,17 +10,17 @@ export const route: Route = {
|
|||
radar: [
|
||||
{
|
||||
source: ['techpowerup.com/'],
|
||||
target: '',
|
||||
},
|
||||
],
|
||||
name: 'Unknown',
|
||||
name: 'Latest Content',
|
||||
maintainers: ['TonyRL'],
|
||||
example: '/techpowerup',
|
||||
handler,
|
||||
url: 'techpowerup.com/',
|
||||
url: 'www.techpowerup.com/',
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const { data: response } = await got(baseUrl, {
|
||||
const response = await ofetch(baseUrl, {
|
||||
headers,
|
||||
});
|
||||
|
||||
|
|
@ -29,15 +29,15 @@ async function handler() {
|
|||
const list = $('.newspost')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const a = item.find('h1 a');
|
||||
const date = item.find('time').attr('datetime');
|
||||
const $item = $(item);
|
||||
const a = $item.find('h1 a');
|
||||
const date = $item.find('time').attr('datetime');
|
||||
return {
|
||||
title: a.text(),
|
||||
link: baseUrl + a.attr('href'),
|
||||
pubDate: date ? parseDate(date) : null, // 2023-05-21T16:05:14+00:00
|
||||
author: item.find('.byline address').text(),
|
||||
category: item
|
||||
author: $item.find('.byline address').text(),
|
||||
category: $item
|
||||
.find('.byline .flags span')
|
||||
.toArray()
|
||||
.map((item) => $(item).text().trim()),
|
||||
|
|
@ -47,7 +47,7 @@ async function handler() {
|
|||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link, {
|
||||
const response = await ofetch(item.link, {
|
||||
headers,
|
||||
});
|
||||
const $ = load(response);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@ import type { Namespace } from '@/types';
|
|||
|
||||
export const namespace: Namespace = {
|
||||
name: 'TechPowerUp',
|
||||
url: 'techpowerup.com',
|
||||
url: 'www.techpowerup.com',
|
||||
lang: 'en',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Route } from '@/types';
|
||||
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 { baseUrl, headers, fixImages, parseReviews } from './utils';
|
||||
|
|
@ -8,7 +8,7 @@ import { baseUrl, headers, fixImages, parseReviews } from './utils';
|
|||
export const route: Route = {
|
||||
path: '/review/:keyword?',
|
||||
categories: ['new-media'],
|
||||
example: '/techpowerup/review/4090',
|
||||
example: '/techpowerup/review/amd',
|
||||
parameters: { keyword: 'Search Keyword' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
|
|
@ -20,14 +20,14 @@ export const route: Route = {
|
|||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['techpowerup.com/'],
|
||||
source: ['techpowerup.com/review/search', 'techpowerup.com/review'],
|
||||
target: '',
|
||||
},
|
||||
],
|
||||
name: 'Reviews',
|
||||
maintainers: ['TonyRL'],
|
||||
handler,
|
||||
url: 'techpowerup.com/',
|
||||
url: 'www.techpowerup.com/review/',
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
|
|
@ -36,10 +36,10 @@ async function handler(ctx) {
|
|||
const url = new URL(`${baseUrl}/review/${keyword ? 'search/' : ''}`);
|
||||
if (keyword) {
|
||||
url.searchParams.set('q', keyword);
|
||||
url.searchParams.set('_', Date.now());
|
||||
url.searchParams.set('_', Date.now().toString());
|
||||
}
|
||||
|
||||
const { data: response } = await got(url, {
|
||||
const response = await ofetch(url.href, {
|
||||
headers,
|
||||
});
|
||||
|
||||
|
|
@ -48,19 +48,19 @@ async function handler(ctx) {
|
|||
const list = $('.reviewlist-bit')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
const a = item.find('.title a');
|
||||
const $item = $(item);
|
||||
const a = $item.find('.title a');
|
||||
return {
|
||||
title: a.text(),
|
||||
link: baseUrl + a.attr('href'),
|
||||
pubDate: parseDate(item.find('.date time').attr('datetime')), // 2023-05-21T16:05:14+00:00
|
||||
author: item
|
||||
pubDate: parseDate($item.find('.date time').attr('datetime')), // 2023-05-21T16:05:14+00:00
|
||||
author: $item
|
||||
.find('.author')
|
||||
.contents()
|
||||
.filter((_, c) => c.type === 'text')
|
||||
.text()
|
||||
.trim(),
|
||||
category: item
|
||||
category: $item
|
||||
.find('.category')
|
||||
.contents()
|
||||
.filter((_, c) => c.type === 'text')
|
||||
|
|
@ -72,7 +72,7 @@ async function handler(ctx) {
|
|||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link, {
|
||||
const response = await ofetch(item.link, {
|
||||
headers,
|
||||
});
|
||||
const $ = load(response);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import md5 from '@/utils/md5';
|
||||
|
|
@ -48,7 +48,7 @@ const parseReviews = async ($, item) => {
|
|||
if (nextPages.length) {
|
||||
const pages = await Promise.all(
|
||||
nextPages.map(async (url) => {
|
||||
const { data: response } = await got(url, {
|
||||
const response = await ofetch(url, {
|
||||
headers,
|
||||
});
|
||||
const $ = load(response);
|
||||
|
|
|
|||
Loading…
Reference in New Issue