Comments (1)
This comment provided the missing puzzle piece - thank you!!!
Based on it, the following diff made it work for me:
diff --git a/.gitignore b/.gitignore
index be81578..25c04c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@ coverage
# dependencies
node_modules
+
+.vercel
diff --git a/lib/aliases.js b/lib/aliases.js
index 187c40b..f331675 100644
--- a/lib/aliases.js
+++ b/lib/aliases.js
@@ -4,7 +4,8 @@ const aliases = {
deb: ['debian'],
rpm: ['fedora'],
AppImage: ['appimage'],
- dmg: ['dmg']
+ dmg: ['dmg'],
+ nupkg: ['nupkg']
}
for (const existingPlatform of Object.keys(aliases)) {
diff --git a/lib/cache.js b/lib/cache.js
index 65e9d30..7b1a1c4 100644
--- a/lib/cache.js
+++ b/lib/cache.js
@@ -12,6 +12,7 @@ module.exports = class Cache {
const { account, repository, token, url } = config
this.config = config
+
if (!account || !repository) {
const error = new Error('Neither ACCOUNT, nor REPOSITORY are defined')
error.code = 'missing_configuration_properties'
@@ -35,21 +36,22 @@ module.exports = class Cache {
this.isOutdated = this.isOutdated.bind(this)
}
- async cacheReleaseList(url) {
+ async cacheReleaseList({ url, browser_download_url }) {
const { token } = this.config
- const headers = { Accept: 'application/vnd.github.preview' }
+ const shouldProxyPrivateDownload = token && typeof token === 'string' && token.length > 0
+ const headers = { Accept: 'application/octet-stream' }
if (token && typeof token === 'string' && token.length > 0) {
headers.Authorization = `token ${token}`
}
- const { status, body } = await retry(
+ const { body } = await retry(
async () => {
const response = await fetch(url, { headers })
if (response.status !== 200) {
throw new Error(
- `Tried to cache RELEASES, but failed fetching ${url}, status ${status}`
+ `Tried to cache RELEASES, but failed fetching ${url}, status ${response.status}`
)
}
@@ -67,10 +69,6 @@ module.exports = class Cache {
)
}
- for (let i = 0; i < matches.length; i += 1) {
- const nuPKG = url.replace('RELEASES', matches[i])
- content = content.replace(matches[i], nuPKG)
- }
return content
}
@@ -133,15 +131,16 @@ module.exports = class Cache {
for (const asset of release.assets) {
const { name, browser_download_url, url, content_type, size } = asset
-
+
if (name === 'RELEASES') {
try {
if (!this.latest.files) {
this.latest.files = {}
}
- this.latest.files.RELEASES = await this.cacheReleaseList(
+ this.latest.files.RELEASES = await this.cacheReleaseList({
+ url,
browser_download_url
- )
+ })
} catch (err) {
console.error(err)
}
@@ -163,7 +162,7 @@ module.exports = class Cache {
}
}
- console.log(`Finished caching version ${tag_name}`)
+ console.log(`Finished caching version ${tag_name}`, this.latest)
this.lastUpdate = Date.now()
}
diff --git a/lib/index.js b/lib/index.js
index 631abb7..e0fc426 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -35,7 +35,7 @@ module.exports = config => {
router.get('/download', routes.download)
router.get('/download/:platform', routes.downloadPlatform)
router.get('/update/:platform/:version', routes.update)
- router.get('/update/win32/:version/RELEASES', routes.releases)
+ router.get('/update/win32/:version/:filename', routes.squirrelWindows)
return (req, res) => {
router(req, res, finalhandler(req, res))
diff --git a/lib/platform.js b/lib/platform.js
index a717d0a..4362004 100644
--- a/lib/platform.js
+++ b/lib/platform.js
@@ -12,6 +12,6 @@ module.exports = fileName => {
return 'darwin' + arch
}
- const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage']
+ const directCache = ['exe', 'dmg', 'rpm', 'deb', 'AppImage', 'nupkg']
return directCache.includes(extension) ? (extension + arch) : false
}
diff --git a/lib/routes.js b/lib/routes.js
index bbd6f14..4e0c2ab 100644
--- a/lib/routes.js
+++ b/lib/routes.js
@@ -87,6 +87,7 @@ module.exports = ({ cache, config }) => {
// Get the latest version from the cache
const latest = await loadCache()
+ console.log('CACHE: ', latest)
// Check platform for appropiate aliases
platform = checkAlias(platform)
@@ -159,14 +160,18 @@ module.exports = ({ cache, config }) => {
if (compare(latest.version, version) !== 0) {
const { notes, pub_date } = latest
- send(res, 200, {
+ const sanitizedBaseUrl = url.startsWith('http') ? url : `https://${url}`
+
+ const responseData = {
name: latest.version,
notes,
pub_date,
url: shouldProxyPrivateDownload
- ? `${url}/download/${platformName}?update=true`
+ ? `${sanitizedBaseUrl}/download/${platformName}?update=true`
: latest.platforms[platform].url
- })
+ }
+ console.log('RESPONSE DATA:', responseData)
+ send(res, 200, responseData)
return
}
@@ -175,25 +180,52 @@ module.exports = ({ cache, config }) => {
res.end()
}
- exports.releases = async (req, res) => {
+ exports.squirrelWindows = async (req, res) => {
+ const { filename } = req.params
// Get the latest version from the cache
const latest = await loadCache()
- if (!latest.files || !latest.files.RELEASES) {
- res.statusCode = 204
- res.end()
+ if (filename.toLowerCase().startsWith('releases')) {
+ if (!latest.files || !latest.files.RELEASES) {
+ res.statusCode = 204
+ res.end()
+
+ return
+ }
+
+ const content = latest.files.RELEASES
+
+ console.log('RESPONSE DATA:', content)
+ res.writeHead(200, {
+ 'content-length': Buffer.byteLength(content, 'utf8'),
+ 'content-type': 'application/octet-stream'
+ })
+
+ res.end(content)
+ } else if (filename.toLowerCase().endsWith('nupkg')) {
+ if (!latest.platforms || !latest.platforms['nupkg']) {
+ res.statusCode = 204
+ res.end()
+
+ return
+ }
- return
- }
+ const nupkgAsset = latest.platforms['nupkg']
- const content = latest.files.RELEASES
+ if (shouldProxyPrivateDownload) {
+ proxyPrivateDownload(nupkgAsset, req, res)
+ return
+ }
- res.writeHead(200, {
- 'content-length': Buffer.byteLength(content, 'utf8'),
- 'content-type': 'application/octet-stream'
- })
+ res.writeHead(302, {
+ Location: nupkgAsset.url
+ })
+ res.end()
- res.end(content)
+ } else {
+ res.statusCode = 400
+ res.end()
+ }
}
☝️ Disclaimer: This is a quick fix and it might or might not work for your case. For example, I think it breaks if you have a private repo and multiple nupkg
rows in your RELEASES
file.
It would be great to have an official solution by the maintainers for this, given that private repo support is advertised for this project.
from hazel.
Related Issues (20)
- Keep getting "invalid JSON response" on private GitHub repo HOT 6
- Programmatic Usage Documentation
- Documentation update HOT 1
- Cannot find channel "latest.yml" update info: HttpError: 404 HOT 2
- Why is the program integrated through vercel 404 ? HOT 1
- Does hazel supports release channels? Alpha/Beta/Latest/Prod....
- Error: Update check failed. The server sent an invalid JSON response HOT 2
- vercel dev must not recursively invoke itself. HOT 6
- ReferenceError: Cannot access 'status' before initialization HOT 3
- rizwan92 #0247 i am facing System.aggregate Exception 81513513 is notvalid string error while checking for update. HOT 4
- proxyPrivateDownload can't fetch asset HOT 1
- installing updates from vercel/hazel giving me error deployment path folder doesn't exists HOT 1
- Protect releases in some way.
- Anyone looking for private github repository update this repo seems to be unkept HOT 1
- missing_configuration_properties HOT 1
- The remote server returned an error: (308) Permanent Redirect. HOT 3
- Help on how this works
- lack of documentation
- It can not support with electron-updater package
- Is there way to change the frontend ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hazel.