feat: try to proxy some source by vercel

chore: test proxy

chore: test proxy
This commit is contained in:
ourongxing
2025-04-26 17:57:32 +08:00
parent ef861aed05
commit f514f7ee5f
5 changed files with 32 additions and 19 deletions
-1
View File
@@ -27,7 +27,6 @@ export default defineSource({
headers: await genHeaders(),
})
if (!r.data.length) throw new Error("Failed to fetch")
console.log(r.data[0])
return r.data.filter(k => k.id).map(i => ({
id: i.id,
title: i.editor_title || load(i.message).text().split("\n")[0],
+9 -5
View File
@@ -1,7 +1,8 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
import { proxySource } from "#/utils/source"
const relativeTimeToDate = function (timeStr) {
const relativeTimeToDate = function (timeStr: string) {
const units = {
: 1000,
分钟: 60 * 1000,
@@ -18,17 +19,17 @@ const relativeTimeToDate = function (timeStr) {
}
const num = Number.parseInt(match[1])
const unit = match[2]
const unit = match[2] as keyof typeof units
const msAgo = num * units[unit]
return new Date(Date.now() - msAgo).valueOf()
}
export default defineSource(async () => {
const source = defineSource(async () => {
const html: any = await myFetch("https://www.ghxi.com/category/all")
const $ = cheerio.load(html)
const news: NewsItem[] = []
$(".sec-panel .sec-panel-body .post-loop li").each((i, elem) => {
$(".sec-panel .sec-panel-body .post-loop li").each((_, elem) => {
let summary_title = $(elem).find(".item-content .item-title").text()
if (summary_title) {
summary_title = summary_title.trim()
@@ -40,8 +41,8 @@ export default defineSource(async () => {
summary_description = summary_description.replaceAll("'", "''")
}
const date = $(elem).find(".item-content .date").text()
console.log(date)
const url = $(elem).find(".item-content .item-title a").attr("href")
if (url) {
news.push({
id: url,
url,
@@ -51,7 +52,10 @@ export default defineSource(async () => {
date: relativeTimeToDate(date),
},
})
}
})
return news
})
export default proxySource("https://newsnow-omega-one.vercel.app/api/s?id=ghxi&latest=", source)
+4 -1
View File
@@ -1,7 +1,8 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
import { proxySource } from "#/utils/source"
export default defineSource(async () => {
const source = defineSource(async () => {
const response: any = await myFetch("https://sputniknews.cn/services/widget/lenta/")
const $ = cheerio.load(response)
const $items = $(".lenta__item")
@@ -25,3 +26,5 @@ export default defineSource(async () => {
})
return news
})
export default proxySource("https://newsnow-omega-one.vercel.app/api/s?id=sputniknewscn&latest=", source)
+10
View File
@@ -1,3 +1,4 @@
import process from "node:process"
import type { AllSourceID } from "@shared/types"
import defu from "defu"
import type { RSSHubOption, RSSHubInfo as RSSHubResponse, SourceGetter, SourceOption } from "#/types"
@@ -44,3 +45,12 @@ export function defineRSSHubSource(route: string, RSSHubOptions?: RSSHubOption,
}))
}
}
export function proxySource(proxyUrl: string, source: SourceGetter) {
return process.env.CF_PAGES
? defineSource(async () => {
const data = await myFetch(proxyUrl)
return data.items
})
: source
}
-3
View File
@@ -139,8 +139,6 @@ export const originSources = {
"sputniknewscn": {
name: "卫星通讯社",
color: "orange",
// cloudflare pages cannot access
disable: "cf",
column: "world",
home: "https://sputniknews.cn",
},
@@ -340,7 +338,6 @@ export const originSources = {
name: "果核剥壳",
column: "china",
color: "yellow",
disable: "cf",
home: "https://www.ghxi.com/",
},
"smzdm": {