This repository has been archived by the owner on Aug 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
105 lines (86 loc) · 2.59 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const fs = require('fs')
const request = require('request')
const fetch = require('node-fetch')
const express = require('express')
const app = express()
const config = require('./config.json')
const downloadFromGithub = (releasesURL) => {
let url
let options
for (x in config.releases) {
console.log(`===== ${config.releases[x].platform } =====`)
for (y in config.releases[x].files) {
url = `${releasesURL}/${config.releases[x].files[y]}`
options = {
directory: `${__dirname}/releases/latest/${config.releases[x].platform}`,
filename: config.releases[x].files[y]
}
console.log(`Downloading ${options.filename}...`)
request(url).pipe(fs.createWriteStream(`${options.directory}/${options.filename}`))
}
}
}
app.get('/update/:version/:platform/:file', (req, res) => {
res.sendFile(`${__dirname}/releases/${req.params.version}/${req.params.platform}/${req.params.file}`)
console.log('[UPDATER] > download + 1')
})
app.get('/update/:version/:platform/', (req, res) => {
fs.readdir(`${__dirname}/releases/${req.params.version}/${req.params.platform}`, (err, files) => {
if (err) {
res.json({
error: 'error'
})
} else {
res.json(files)
}
})
})
app.get('/update/', (req, res) => {
fs.readdir(`${__dirname}/releases`, (err, files) => {
if (err) {
res.json({
error: 'error'
})
} else {
res.json(files)
}
})
})
app.get('/upload/:tag/:password', (req, res) => {
const releasesURL = `https://github.com/${config.githubRepo}/releases/download/${req.params.tag}`
const gituhApi = `https://api.github.com/repos/${config.githubRepo}/tags`
if (req.params.password === config.password) {
fetch(gituhApi)
.then(resp => resp.json())
.then(data => {
for (i in data) {
if (data[i].name === req.params.tag) {
res.json({
message: "DOWNLOADING",
url: releasesURL
})
downloadFromGithub(releasesURL)
break
}
}
}).catch((e) => {
res.json({
message: e
})
})
} else {
res.json({
message: "BAD_PASSWORD"
})
}
})
app.get('*', (req, res) => {
res.json({
welcome: 'Welcome on pixtron, a (very) simple update server for electron-updater',
github: 'See our github here: https://github.com/ShuttleBrowser/pixtron'
})
})
const port = process.env.PORT || 1003;
app.listen(port, () => {
console.log(`[INFO] > http://localhost:${port}`)
})