2023-07-06 04:04:06 +00:00
|
|
|
import { NextResponse } from 'next/server'
|
|
|
|
import semver from 'semver'
|
|
|
|
|
|
|
|
export async function GET(req: Request) {
|
|
|
|
const { searchParams } = new URL(req.url)
|
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
const os = searchParams.get('os') || 'darwin'
|
|
|
|
const version = searchParams.get('version') || '0.0.0'
|
2023-07-06 04:04:06 +00:00
|
|
|
|
2023-07-06 20:18:40 +00:00
|
|
|
if (!version) {
|
|
|
|
return new Response('not found', { status: 404 })
|
|
|
|
}
|
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
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 || []
|
2023-07-06 04:04:06 +00:00
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
if (assets.length === 0) {
|
|
|
|
return new Response('not found', { status: 404 })
|
|
|
|
}
|
2023-07-06 04:04:06 +00:00
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
// todo: get the correct asset for the current arch/os
|
|
|
|
const asset = assets.find((a: any) => a.name.toLowerCase().includes(os) && a.name.toLowerCase().includes('.zip'))
|
2023-07-06 04:04:06 +00:00
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
if (!asset) {
|
|
|
|
return new Response('not found', { status: 404 })
|
|
|
|
}
|
2023-07-06 20:18:40 +00:00
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
console.log(asset)
|
2023-07-06 04:04:06 +00:00
|
|
|
|
2023-07-08 20:47:58 +00:00
|
|
|
if (semver.lt(version, latest.tag_name)) {
|
|
|
|
return NextResponse.json({ version: data.tag_name, url: asset.browser_download_url })
|
2023-07-06 04:04:06 +00:00
|
|
|
}
|
2023-07-08 20:47:58 +00:00
|
|
|
|
|
|
|
return new Response(null, { status: 204 })
|
2023-07-06 04:04:06 +00:00
|
|
|
}
|