mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 13:54:01 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { query } from "@solidjs/router"
|
|
|
|
export const github = query(async () => {
|
|
"use server"
|
|
try {
|
|
const [meta, releases, contributors] = await Promise.all([
|
|
fetch("https://api.github.com/repos/sst/opencode").then(async (res) => {
|
|
const text = await res.text()
|
|
console.log(text)
|
|
const json = JSON.parse(text)
|
|
return json
|
|
}),
|
|
fetch("https://api.github.com/repos/sst/opencode/releases").then(async (res) => {
|
|
const text = await res.text()
|
|
console.log(text)
|
|
const json = JSON.parse(text)
|
|
return json
|
|
}),
|
|
fetch("https://api.github.com/repos/sst/opencode/contributors?per_page=1"),
|
|
])
|
|
const [release] = releases
|
|
const contributorCount = Number.parseInt(
|
|
contributors.headers
|
|
.get("Link")!
|
|
.match(/&page=(\d+)>; rel="last"/)!
|
|
.at(1)!,
|
|
)
|
|
return {
|
|
stars: meta.stargazers_count,
|
|
release: {
|
|
name: release.name,
|
|
url: release.html_url,
|
|
},
|
|
contributors: contributorCount,
|
|
}
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
return undefined
|
|
}, "github")
|