Skip to content

Commit

Permalink
Merge pull request #657 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Dec 5, 2024
2 parents eec85d4 + ce2b89a commit 79bbb9e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 92 deletions.
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const server = serve({
hostname: config.listenInaddrAny ? '::' : '127.0.0.1',
port,
serverOptions: {
maxHeaderSize: 1024 * 64,
maxHeaderSize: 1024 * 32,
},
});

Expand Down
5 changes: 5 additions & 0 deletions lib/routes/36kr/hot-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';

import { rootUrl, ProcessItem } from './utils';
import InvalidParameterError from '@/errors/types/invalid-parameter';

const categories = {
24: {
Expand Down Expand Up @@ -54,6 +55,10 @@ export const route: Route = {
async function handler(ctx) {
const category = ctx.req.param('category') ?? '24';

if (!categories[category]) {
throw new InvalidParameterError('This category does not exist. Please refer to the documentation for the correct usage.');
}

const currentUrl = category === '24' ? rootUrl : `${rootUrl}/hot-list/catalog`;

const response = await got({
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/mihoyo/bbs/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function handler(ctx) {
page_size,
};
const link = 'https://www.miyoushe.com/ys/timeline';
const url = 'https://bbs-api.miyoushe.com/post/wapi/timelines';
const url = 'https://bbs-api.miyoushe.com/painter/wapi/timeline/list';
const response = await got({
method: 'get',
url,
Expand Down
7 changes: 4 additions & 3 deletions lib/routes/qweather/3days.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ export const route: Route = {
name: '近三天天气',
maintainers: ['Rein-Ou', 'la3rence'],
handler,
description: `需自行注册获取 api 的 key,并在环境变量 HEFENG\_KEY 中进行配置,获取订阅近三天天气预报`,
description: '获取订阅近三天天气预报',
};

async function handler(ctx) {
if (!config.hefeng.key) {
throw new ConfigNotFoundError('QWeather RSS is disabled due to the lack of <a href="https://docs.rsshub.app/zh/install/config#%E5%92%8C%E9%A3%8E%E5%A4%A9%E6%B0%94">relevant config</a>');
}
const id = await cache.tryGet(ctx.req.param('location') + '_id', async () => {

const id = await cache.tryGet('qweather:' + ctx.req.param('location') + ':id', async () => {
const response = await got(`${CIRY_LOOKUP_API}?location=${ctx.req.param('location')}&key=${config.hefeng.key}`);
return response.data.location[0].id;
});
const weatherData = await cache.tryGet(
ctx.req.param('location'),
'qweather:' + ctx.req.param('location'),
async () => {
const response = await got(`${WEATHER_API}?key=${config.hefeng.key}&location=${id}`);
return response.data;
Expand Down
21 changes: 12 additions & 9 deletions lib/routes/qweather/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import { art } from '@/utils/render';
import path from 'node:path';
import { parseDate } from '@/utils/parse-date';
import { config } from '@/config';
import ConfigNotFoundError from '@/errors/types/config-not-found';

const rootUrl = 'https://devapi.qweather.com/v7/weather/now?';

export const route: Route = {
path: '/now/:location',
categories: ['forecast'],
example: '/qweather/广州',
example: '/qweather/now/广州',
parameters: { location: 'N' },
features: {
requireConfig: [
{
name: 'HEFENG_KEY',
description: '',
description: '访问 `https://www.qweather.com/` 注册开发 API Key。',
},
],
requirePuppeteer: false,
Expand All @@ -30,21 +33,21 @@ export const route: Route = {
name: '实时天气',
maintainers: ['Rein-Ou'],
handler,
description: `需自行注册获取 api 的 key,每小时更新一次数据`,
};

async function handler(ctx) {
const id = await cache.tryGet(ctx.req.param('location') + '_id', async () => {
if (!config.hefeng.key) {
throw new ConfigNotFoundError('QWeather RSS is disabled due to the lack of <a href="https://docs.rsshub.app/zh/install/config#%E5%92%8C%E9%A3%8E%E5%A4%A9%E6%B0%94">relevant config</a>');
}

const id = await cache.tryGet('qweather:' + ctx.req.param('location') + ':id', async () => {
const response = await got(`https://geoapi.qweather.com/v2/city/lookup?location=${ctx.req.param('location')}&key=${config.hefeng.key}`);
const data = [];
for (const i in response.data.location) {
data.push(response.data.location[i]);
}
const data = response.data.location.map((loc) => loc);
return data[0].id;
});
const requestUrl = rootUrl + 'key=' + config.hefeng.key + '&location=' + id;
const responseData = await cache.tryGet(
ctx.req.param('location') + '_now',
'qweather:' + ctx.req.param('location') + ':now',
async () => {
const response = await got(requestUrl);
return response.data;
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
"@hono/zod-openapi": "0.18.3",
"@notionhq/client": "2.2.15",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/exporter-prometheus": "0.55.0",
"@opentelemetry/exporter-trace-otlp-http": "0.55.0",
"@opentelemetry/resources": "1.28.0",
"@opentelemetry/sdk-metrics": "1.28.0",
"@opentelemetry/sdk-trace-base": "1.28.0",
"@opentelemetry/exporter-prometheus": "0.56.0",
"@opentelemetry/exporter-trace-otlp-http": "0.56.0",
"@opentelemetry/resources": "1.29.0",
"@opentelemetry/sdk-metrics": "1.29.0",
"@opentelemetry/sdk-trace-base": "1.29.0",
"@opentelemetry/semantic-conventions": "1.28.0",
"@postlight/parser": "2.2.3",
"@rss3/sdk": "0.0.23",
Expand Down
140 changes: 67 additions & 73 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79bbb9e

Please sign in to comment.