Skip to content

Commit

Permalink
fix(route): github notification (#15659)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored May 22, 2024
1 parent f23e933 commit e22e424
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/routes/github/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Route } from '@/types';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

const apiUrl = 'https://api.github.com';
Expand All @@ -10,19 +10,13 @@ export const route: Route = {
path: '/notifications',
categories: ['programming'],
example: '/github/notifications',
parameters: {},
features: {
requireConfig: [
{
name: 'GITHUB_ACCESS_TOKEN',
description: '',
},
],
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
Expand All @@ -45,10 +39,10 @@ async function handler(ctx) {
'X-GitHub-Api-Version': '2022-11-28',
};

const response = await got(`${apiUrl}/notifications`, {
const response = await ofetch.raw(`${apiUrl}/notifications`, {
headers,
});
const notifications = response.data;
const notifications = response._data;

const items = notifications.map((item) => {
let originUrl = item.subject.url ? item.subject.url.replace('https://api.github.com/repos/', 'https://github.com/') : 'https://github.com/notifications';
Expand All @@ -68,11 +62,11 @@ async function handler(ctx) {
title: 'Github Notifications',
item: notifications,
rateLimit: {
limit: Number.parseInt(response.headers['X-RateLimit-Limit']),
remaining: Number.parseInt(response.headers['X-RateLimit-Remaining']),
reset: parseDate(Number.parseInt(response.headers['X-RateLimit-Reset']) * 1000),
resoure: response.headers['X-RateLimit-Resource'],
used: Number.parseInt(response.headers['X-RateLimit-Used']),
limit: Number.parseInt(response.headers['x-ratelimit-limit']),
remaining: Number.parseInt(response.headers['x-ratelimit-remaining']),
reset: parseDate(Number.parseInt(response.headers['x-ratelimit-reset']), 'X'),
resoure: response.headers['x-ratelimit-resource'],
used: Number.parseInt(response.headers['x-ratelimit-used']),
},
});

Expand Down

0 comments on commit e22e424

Please sign in to comment.