page.tsx 882 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { Octokit } from '@octokit/rest'
  2. import { redirect } from 'next/navigation'
  3. const octokit = new Octokit()
  4. export default async function Download() {
  5. const res = await fetch('https://api.github.com/repos/jmorganca/ollama/releases', { next: { revalidate: 60 } })
  6. const data = await res.json()
  7. if (data.length === 0) {
  8. return new Response('not found', { status: 404 })
  9. }
  10. const latest = data[0]
  11. const assets = latest.assets || []
  12. if (assets.length === 0) {
  13. return new Response('not found', { status: 404 })
  14. }
  15. // todo: get the correct asset for the current arch/os
  16. const asset = assets.find(
  17. (a: any) => a.name.toLowerCase().includes('darwin') && a.name.toLowerCase().includes('.zip')
  18. )
  19. if (!asset) {
  20. return new Response('not found', { status: 404 })
  21. }
  22. if (asset) {
  23. redirect(asset.browser_download_url)
  24. }
  25. return null
  26. }