Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
a8dc0c9b
Commit
a8dc0c9b
authored
Jul 08, 2023
by
Jeffrey Morgan
Browse files
web: use proper caching for autoupdate endpoint
parent
1e978078
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
78 deletions
+89
-78
web/app/api/update/route.ts
web/app/api/update/route.ts
+24
-26
web/app/download/page.tsx
web/app/download/page.tsx
+20
-7
web/package-lock.json
web/package-lock.json
+44
-44
web/package.json
web/package.json
+1
-1
No files found.
web/app/api/update/route.ts
View file @
a8dc0c9b
import
{
NextResponse
}
from
'
next/server
'
import
{
NextResponse
}
from
'
next/server
'
import
semver
from
'
semver
'
import
semver
from
'
semver
'
import
{
Octokit
}
from
'
@octokit/rest
'
import
{
RequestError
}
from
'
@octokit/types
'
const
octokit
=
new
Octokit
()
export
async
function
GET
(
req
:
Request
)
{
export
async
function
GET
(
req
:
Request
)
{
const
{
searchParams
}
=
new
URL
(
req
.
url
)
const
{
searchParams
}
=
new
URL
(
req
.
url
)
const
os
=
searchParams
.
get
(
'
os
'
)
||
''
const
os
=
searchParams
.
get
(
'
os
'
)
||
'
darwin
'
const
version
=
searchParams
.
get
(
'
version
'
)
||
''
const
version
=
searchParams
.
get
(
'
version
'
)
||
'
0.0.0
'
if
(
!
version
)
{
if
(
!
version
)
{
return
new
Response
(
'
not found
'
,
{
status
:
404
})
return
new
Response
(
'
not found
'
,
{
status
:
404
})
}
}
try
{
const
res
=
await
fetch
(
'
https://api.github.com/repos/jmorganca/ollama/releases
'
,
{
next
:
{
revalidate
:
60
}
})
const
{
data
}
=
await
octokit
.
repos
.
getLatestRelease
({
const
data
=
await
res
.
json
()
owner
:
'
jmorganca
'
,
repo
:
'
ollama
'
,
})
// todo: get the correct asset for the current arch/os
const
asset
=
data
.
assets
.
find
(
a
=>
a
.
name
.
toLowerCase
().
includes
(
os
))
if
(
!
asset
)
{
if
(
data
.
length
===
0
)
{
return
new
Response
(
'
not found
'
,
{
status
:
404
})
return
new
Response
(
'
not found
'
,
{
status
:
404
})
}
}
if
(
semver
.
lt
(
version
,
data
.
tag_name
))
{
const
latest
=
data
[
0
]
return
NextResponse
.
json
({
version
:
data
.
tag_name
,
url
:
asset
.
browser_download_url
})
const
assets
=
latest
.
assets
||
[]
if
(
assets
.
length
===
0
)
{
return
new
Response
(
'
not found
'
,
{
status
:
404
})
}
}
return
new
Response
(
'
up to date
'
,
{
status
:
204
})
// todo: get the correct asset for the current arch/os
}
catch
(
error
)
{
const
asset
=
assets
.
find
((
a
:
any
)
=>
a
.
name
.
toLowerCase
().
includes
(
os
)
&&
a
.
name
.
toLowerCase
().
includes
(
'
.zip
'
))
const
e
=
error
as
RequestError
if
(
e
.
status
===
404
)
{
if
(
!
asset
)
{
return
new
Response
(
'
not found
'
,
{
status
:
404
})
return
new
Response
(
'
not found
'
,
{
status
:
404
})
}
}
return
new
Response
(
'
internal server error
'
,
{
status
:
500
})
console
.
log
(
asset
)
if
(
semver
.
lt
(
version
,
latest
.
tag_name
))
{
return
NextResponse
.
json
({
version
:
data
.
tag_name
,
url
:
asset
.
browser_download_url
})
}
}
return
new
Response
(
null
,
{
status
:
204
})
}
}
web/app/download/page.tsx
View file @
a8dc0c9b
...
@@ -3,16 +3,29 @@ import { redirect } from 'next/navigation'
...
@@ -3,16 +3,29 @@ import { redirect } from 'next/navigation'
const
octokit
=
new
Octokit
()
const
octokit
=
new
Octokit
()
export
const
revalidate
=
60
export
default
async
function
Download
()
{
export
default
async
function
Download
()
{
const
{
data
}
=
await
octokit
.
repos
.
getLatestRelease
({
const
res
=
await
fetch
(
'
https://api.github.com/repos/jmorganca/ollama/releases
'
,
{
next
:
{
revalidate
:
60
}
})
owner
:
'
jmorganca
'
,
const
data
=
await
res
.
json
()
repo
:
'
ollama
'
,
})
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
})
}
// todo: get the correct asset for the current arch/os
// todo: get the correct asset for the current arch/os
const
asset
=
data
.
assets
.
find
(
a
=>
a
.
name
.
toLowerCase
().
includes
(
'
darwin
'
)
&&
a
.
name
.
toLowerCase
().
includes
(
'
.zip
'
))
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
})
}
if
(
asset
)
{
if
(
asset
)
{
redirect
(
asset
.
browser_download_url
)
redirect
(
asset
.
browser_download_url
)
...
...
web/package-lock.json
View file @
a8dc0c9b
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
"encoding"
:
"^0.1.13"
,
"encoding"
:
"^0.1.13"
,
"eslint"
:
"8.44.0"
,
"eslint"
:
"8.44.0"
,
"eslint-config-next"
:
"13.4.7"
,
"eslint-config-next"
:
"13.4.7"
,
"next"
:
"13.4.
7
"
,
"next"
:
"13.4.
9
"
,
"postcss"
:
"8.4.24"
,
"postcss"
:
"8.4.24"
,
"react"
:
"18.2.0"
,
"react"
:
"18.2.0"
,
"react-dom"
:
"18.2.0"
,
"react-dom"
:
"18.2.0"
,
...
@@ -191,9 +191,9 @@
...
@@ -191,9 +191,9 @@
"integrity"
:
"sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
"integrity"
:
"sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
},
},
"node_modules/@next/env"
:
{
"node_modules/@next/env"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/env/-/env-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/env/-/env-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
ZlbiFulnwiFsW9UV1ku1OvX/oyIPLtMk9p/nnvDSwI0s7vSoZdRtxXNsaO+ZXrLv/pMbXVGq4lL8TbY9iuGmV
w=="
"integrity"
:
"sha512-
vuDRK05BOKfmoBYLNi2cujG2jrYbEod/ubSSyqgmEx9n/W3eZaJQdRNhTfumO+qmq/QTzLurW487n/PM/fHOk
w=="
},
},
"node_modules/@next/eslint-plugin-next"
:
{
"node_modules/@next/eslint-plugin-next"
:
{
"version"
:
"13.4.7"
,
"version"
:
"13.4.7"
,
...
@@ -204,9 +204,9 @@
...
@@ -204,9 +204,9 @@
}
}
},
},
"node_modules/@next/swc-darwin-arm64"
:
{
"node_modules/@next/swc-darwin-arm64"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
VZTxPv1b59KGiv/pZHTO5Gbsdeoxcj2rU2cqJu03btMhHpn3vwzEK0gUSVC/XW96aeGO67X+cMahhwHzef24/w
=="
,
"integrity"
:
"sha512-
TVzGHpZoVBk3iDsTOQA/R6MGmFp0+17SWXMEWd6zG30AfuELmSSMe2SdPqxwXU0gbpWkJL1KgfLzy5ReN0crqQ
=="
,
"cpu"
:
[
"cpu"
:
[
"arm64"
"arm64"
],
],
...
@@ -219,9 +219,9 @@
...
@@ -219,9 +219,9 @@
}
}
},
},
"node_modules/@next/swc-darwin-x64"
:
{
"node_modules/@next/swc-darwin-x64"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
gO2bw+2Ymmga+QYujjvDz9955xvYGrWofmxTq7m70b9pDPvl7aDFABJOZ2a8SRCuSNB5mXU8eTOmVVwyp/nAew
=="
,
"integrity"
:
"sha512-
aSfF1fhv28N2e7vrDZ6zOQ+IIthocfaxuMWGReB5GDriF0caTqtHttAvzOMgJgXQtQx6XhyaJMozLTSEXeNN+A
=="
,
"cpu"
:
[
"cpu"
:
[
"x64"
"x64"
],
],
...
@@ -234,9 +234,9 @@
...
@@ -234,9 +234,9 @@
}
}
},
},
"node_modules/@next/swc-linux-arm64-gnu"
:
{
"node_modules/@next/swc-linux-arm64-gnu"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
6cqp3vf1eHxjIDhEOc7Mh/s8z1cwc/l5B6ZNkOofmZVyu1zsbEM5Hmx64s12Rd9AYgGoiCz4OJ4M/oRnkE16/Q
=="
,
"integrity"
:
"sha512-
JhKoX5ECzYoTVyIy/7KykeO4Z2lVKq7HGQqvAH+Ip9UFn1MOJkOnkPRB7v4nmzqAoY+Je05Aj5wNABR1N18DMg
=="
,
"cpu"
:
[
"cpu"
:
[
"arm64"
"arm64"
],
],
...
@@ -249,9 +249,9 @@
...
@@ -249,9 +249,9 @@
}
}
},
},
"node_modules/@next/swc-linux-arm64-musl"
:
{
"node_modules/@next/swc-linux-arm64-musl"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
T1kD2FWOEy5WPidOn1si0rYmWORNch4a/NR52Ghyp4q7KyxOCuiOfZzyhVC5tsLIBDH3+cNdB5DkD9afpNDaO
w=="
,
"integrity"
:
"sha512-
OOn6zZBIVkm/4j5gkPdGn4yqQt+gmXaLaSjRSO434WplV8vo2YaBNbSHaTM9wJpZTHVDYyjzuIYVEzy9/5RVZ
w=="
,
"cpu"
:
[
"cpu"
:
[
"arm64"
"arm64"
],
],
...
@@ -264,9 +264,9 @@
...
@@ -264,9 +264,9 @@
}
}
},
},
"node_modules/@next/swc-linux-x64-gnu"
:
{
"node_modules/@next/swc-linux-x64-gnu"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
zaEC+iEiAHNdhl6fuwl0H0shnTzQoAoJiDYBUze8QTntE/GNPfTYpYboxF5LRYIjBwETUatvE0T64W6SKDipv
g=="
,
"integrity"
:
"sha512-
iA+fJXFPpW0SwGmx/pivVU+2t4zQHNOOAr5T378PfxPHY6JtjV6/0s1vlAJUdIHeVpX98CLp9k5VuKgxiRHUp
g=="
,
"cpu"
:
[
"cpu"
:
[
"x64"
"x64"
],
],
...
@@ -279,9 +279,9 @@
...
@@ -279,9 +279,9 @@
}
}
},
},
"node_modules/@next/swc-linux-x64-musl"
:
{
"node_modules/@next/swc-linux-x64-musl"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
X6r12F8d8SKAtYJqLZBBMIwEqcTRvUdVm+xIq+l6pJqlgT2tNsLLf2i5Cl88xSsIytBICGsCNNHd+siD2fbWB
A=="
,
"integrity"
:
"sha512-
rlNf2WUtMM+GAQrZ9gMNdSapkVi3koSW3a+dmBVp42lfugWVvnyzca/xJlN48/7AGx8qu62WyO0ya1ikgOxh6
A=="
,
"cpu"
:
[
"cpu"
:
[
"x64"
"x64"
],
],
...
@@ -294,9 +294,9 @@
...
@@ -294,9 +294,9 @@
}
}
},
},
"node_modules/@next/swc-win32-arm64-msvc"
:
{
"node_modules/@next/swc-win32-arm64-msvc"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
NPnmnV+vEIxnu6SUvjnuaWRglZzw4ox5n/MQTxeUhb5iwVWFedolPFebMNwgrWu4AELwvTdGtWjqof53AiWHcw
=="
,
"integrity"
:
"sha512-
5T9ybSugXP77nw03vlgKZxD99AFTHaX8eT1ayKYYnGO9nmYhJjRPxcjU5FyYI+TdkQgEpIcH7p/guPLPR0EbKA
=="
,
"cpu"
:
[
"cpu"
:
[
"arm64"
"arm64"
],
],
...
@@ -309,9 +309,9 @@
...
@@ -309,9 +309,9 @@
}
}
},
},
"node_modules/@next/swc-win32-ia32-msvc"
:
{
"node_modules/@next/swc-win32-ia32-msvc"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
6Hxijm6/a8XqLQpOOf/XuwWRhcuc/g4rBB2oxjgCMuV9Xlr2bLs5+lXyh8w9YbAUMYR3iC9mgOlXbHa79elmXw
=="
,
"integrity"
:
"sha512-
ojZTCt1lP2ucgpoiFgrFj07uq4CZsq4crVXpLGgQfoFq00jPKRPgesuGPaz8lg1yLfvafkU3Jd1i8snKwYR3LA
=="
,
"cpu"
:
[
"cpu"
:
[
"ia32"
"ia32"
],
],
...
@@ -324,9 +324,9 @@
...
@@ -324,9 +324,9 @@
}
}
},
},
"node_modules/@next/swc-win32-x64-msvc"
:
{
"node_modules/@next/swc-win32-x64-msvc"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
sW9Yt36Db1nXJL+mTr2Wo0y+VkPWeYhygvcHj1FF0srVtV+VoDjxleKtny21QHaG05zdeZnw2fCtf2+dEqgwqA
=="
,
"integrity"
:
"sha512-
QbT03FXRNdpuL+e9pLnu+XajZdm/TtIXVYY4lA9t+9l0fLZbHXDYEKitAqxrOj37o3Vx5ufxiRAniaIebYDCgw
=="
,
"cpu"
:
[
"cpu"
:
[
"x64"
"x64"
],
],
...
@@ -2983,11 +2983,11 @@
...
@@ -2983,11 +2983,11 @@
"integrity"
:
"sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw=="
"integrity"
:
"sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw=="
},
},
"node_modules/next"
:
{
"node_modules/next"
:
{
"version"
:
"13.4.
7
"
,
"version"
:
"13.4.
9
"
,
"resolved"
:
"https://registry.npmjs.org/next/-/next-13.4.
7
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/next/-/next-13.4.
9
.tgz"
,
"integrity"
:
"sha512-
M8z3k9VmG51SRT6v5uDKdJXcAqLzP3C+vaKfLIAM0Mhx1um1G7MDnO63+m52qPdZfrTFzMZNzfsgvm3ghuVHIQ
=="
,
"integrity"
:
"sha512-
vtefFm/BWIi/eWOqf1GsmKG3cjKw1k3LjuefKRcL3iiLl3zWzFdPG3as6xtxrGO6gwTzzaO1ktL4oiHt/uvTjA
=="
,
"dependencies"
:
{
"dependencies"
:
{
"@next/env"
:
"13.4.
7
"
,
"@next/env"
:
"13.4.
9
"
,
"@swc/helpers"
:
"0.5.1"
,
"@swc/helpers"
:
"0.5.1"
,
"busboy"
:
"1.6.0"
,
"busboy"
:
"1.6.0"
,
"caniuse-lite"
:
"^1.0.30001406"
,
"caniuse-lite"
:
"^1.0.30001406"
,
...
@@ -3003,15 +3003,15 @@
...
@@ -3003,15 +3003,15 @@
"node"
:
">=16.8.0"
"node"
:
">=16.8.0"
},
},
"optionalDependencies"
:
{
"optionalDependencies"
:
{
"@next/swc-darwin-arm64"
:
"13.4.
7
"
,
"@next/swc-darwin-arm64"
:
"13.4.
9
"
,
"@next/swc-darwin-x64"
:
"13.4.
7
"
,
"@next/swc-darwin-x64"
:
"13.4.
9
"
,
"@next/swc-linux-arm64-gnu"
:
"13.4.
7
"
,
"@next/swc-linux-arm64-gnu"
:
"13.4.
9
"
,
"@next/swc-linux-arm64-musl"
:
"13.4.
7
"
,
"@next/swc-linux-arm64-musl"
:
"13.4.
9
"
,
"@next/swc-linux-x64-gnu"
:
"13.4.
7
"
,
"@next/swc-linux-x64-gnu"
:
"13.4.
9
"
,
"@next/swc-linux-x64-musl"
:
"13.4.
7
"
,
"@next/swc-linux-x64-musl"
:
"13.4.
9
"
,
"@next/swc-win32-arm64-msvc"
:
"13.4.
7
"
,
"@next/swc-win32-arm64-msvc"
:
"13.4.
9
"
,
"@next/swc-win32-ia32-msvc"
:
"13.4.
7
"
,
"@next/swc-win32-ia32-msvc"
:
"13.4.
9
"
,
"@next/swc-win32-x64-msvc"
:
"13.4.
7
"
"@next/swc-win32-x64-msvc"
:
"13.4.
9
"
},
},
"peerDependencies"
:
{
"peerDependencies"
:
{
"@opentelemetry/api"
:
"^1.1.0"
,
"@opentelemetry/api"
:
"^1.1.0"
,
...
...
web/package.json
View file @
a8dc0c9b
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
"encoding"
:
"^0.1.13"
,
"encoding"
:
"^0.1.13"
,
"eslint"
:
"8.44.0"
,
"eslint"
:
"8.44.0"
,
"eslint-config-next"
:
"13.4.7"
,
"eslint-config-next"
:
"13.4.7"
,
"next"
:
"13.4.
7
"
,
"next"
:
"13.4.
9
"
,
"postcss"
:
"8.4.24"
,
"postcss"
:
"8.4.24"
,
"react"
:
"18.2.0"
,
"react"
:
"18.2.0"
,
"react-dom"
:
"18.2.0"
,
"react-dom"
:
"18.2.0"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment