|
1 | 1 | import { Route } from '@/types';
|
2 | 2 | import got from '@/utils/got';
|
3 | 3 | import { config } from '@/config';
|
| 4 | +import { parseDate } from '@/utils/parse-date'; |
4 | 5 |
|
5 | 6 | export const route: Route = {
|
6 | 7 | path: '/repos/:user/:type?/:sort?',
|
@@ -49,37 +50,46 @@ async function handler(ctx) {
|
49 | 50 | },
|
50 | 51 | headers,
|
51 | 52 | });
|
52 |
| - const data = response.data.filter((item) => { |
53 |
| - switch (type) { |
54 |
| - case 'all': |
55 |
| - return true; |
56 |
| - case 'owner': |
57 |
| - return item.owner.login === user; |
58 |
| - case 'member': |
59 |
| - return item.owner.login !== user; |
60 |
| - case 'public': |
61 |
| - return item.private === false; |
62 |
| - case 'private': |
63 |
| - return item.private === true; |
64 |
| - case 'forks': |
65 |
| - return item.fork === true; |
66 |
| - case 'sources': |
67 |
| - return item.fork === false; |
68 |
| - default: |
69 |
| - return true; |
70 |
| - } |
71 |
| - }); |
| 53 | + const item = response.data |
| 54 | + .filter((item) => { |
| 55 | + switch (type) { |
| 56 | + case 'all': |
| 57 | + return true; |
| 58 | + case 'owner': |
| 59 | + return item.owner.login === user; |
| 60 | + case 'member': |
| 61 | + return item.owner.login !== user; |
| 62 | + case 'public': |
| 63 | + return item.private === false; |
| 64 | + case 'private': |
| 65 | + return item.private === true; |
| 66 | + case 'forks': |
| 67 | + return item.fork === true; |
| 68 | + case 'sources': |
| 69 | + return item.fork === false; |
| 70 | + default: |
| 71 | + return true; |
| 72 | + } |
| 73 | + }) |
| 74 | + .map((item) => { |
| 75 | + let pubDate = parseDate(item.created_at); |
| 76 | + if (sort === 'updated' && item.updated_at) { |
| 77 | + pubDate = parseDate(item.updated_at); |
| 78 | + } else if (sort === 'pushed' && item.pushed_at) { |
| 79 | + pubDate = parseDate(item.pushed_at); |
| 80 | + } |
| 81 | + return { |
| 82 | + title: item.name, |
| 83 | + description: item.description || 'No description', |
| 84 | + pubDate, |
| 85 | + updated: parseDate(item.updated_at), |
| 86 | + link: item.html_url, |
| 87 | + }; |
| 88 | + }); |
72 | 89 | return {
|
73 | 90 | allowEmpty: true,
|
74 | 91 | title: `${user}'s GitHub repositories`,
|
75 | 92 | link: `https://github.com/${user}`,
|
76 |
| - item: |
77 |
| - data && |
78 |
| - data.map((item) => ({ |
79 |
| - title: item.name, |
80 |
| - description: item.description || 'No description', |
81 |
| - pubDate: new Date(item.created_at).toUTCString(), |
82 |
| - link: item.html_url, |
83 |
| - })), |
| 93 | + item, |
84 | 94 | };
|
85 | 95 | }
|
0 commit comments