Skip to content

Commit

Permalink
feat: Force update
Browse files Browse the repository at this point in the history
  • Loading branch information
firejune committed Nov 17, 2023
1 parent fc9c18b commit c8c1661
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/app/api/v1/[username]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ type Params = {
}

export async function GET(request: NextRequest, { params }: Params) {
console.log('GET', `/api/v1/${params.username}`)
const v = request.nextUrl.searchParams.get('v')
console.log('GET', `/api/v1/${params.username}${v ? `?v=${v}` : ''}`)

const data = await fetch(`https://github.com/users/${params.username}/contributions`)
const data = await fetch(`https://github.com/users/${params.username}/contributions${v ? `?v=${v}` : ''}`)
const $ = load(await data.text())
const $days = $('table.ContributionCalendar-grid td.ContributionCalendar-day')
const $graph = $('div.js-calendar-graph').get(0)
const contribText = $('.js-yearly-contributions h2')
.text()
.trim()
.match(/^([0-9,]+)\s/)
const contribCount = contribText ? parseInt(contribText[0].replace(/,/g, ''), 10) : 0

const struct = {
total: contribCount,
range: {
start: $($days.get(0)).attr('data-date') as string,
end: $($days.get($days.length - 1)).attr('data-date') as string,
start: $($graph).attr('data-from') as string,
end: $($graph).attr('data-to') as string,
},
contributions: (() => {
const parseDay = (day: Element) => {
Expand All @@ -38,7 +39,14 @@ export async function GET(request: NextRequest, { params }: Params) {
}
return { date, value }
}
return $days.get().map(day => parseDay(day).value)
return $days
.get()
.map(day => parseDay(day).value)
.sort((a, b) => {
if (a.date < b.date) return 1
else if (a.date > b.date) return -1
return 0
})
})(),
}

Expand Down

0 comments on commit c8c1661

Please sign in to comment.