page.tsx 811 Bytes
Newer Older
Jeffrey Morgan's avatar
Jeffrey Morgan committed
1
2
3
import { redirect } from 'next/navigation'

export default async function Download() {
4
5
6
7
8
9
10
11
12
13
14
15
16
  const res = await fetch('https://api.github.com/repos/jmorganca/ollama/releases', { next: { revalidate: 60 } })
  const data = await res.json()

  if (data.length === 0) {
    return new Response('not found', { status: 404 })
  }

  const latest = data[0]
  const assets = latest.assets || []

  if (assets.length === 0) {
    return new Response('not found', { status: 404 })
  }
Jeffrey Morgan's avatar
Jeffrey Morgan committed
17
18

  // todo: get the correct asset for the current arch/os
19
20
21
22
23
24
25
  const asset = assets.find(
    (a: any) => a.name.toLowerCase().includes('darwin') && a.name.toLowerCase().includes('.zip')
  )

  if (!asset) {
    return new Response('not found', { status: 404 })
  }
Jeffrey Morgan's avatar
Jeffrey Morgan committed
26
27
28
29
30
31
32

  if (asset) {
    redirect(asset.browser_download_url)
  }

  return null
}