2019-06-25 03:06:28 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const express = require('express')
|
|
|
|
const app = express()
|
|
|
|
const port = 3000
|
|
|
|
|
2019-12-10 04:08:49 +00:00
|
|
|
let showError = false
|
2020-05-29 20:22:58 +00:00
|
|
|
let showConfigError = false
|
2020-05-29 20:44:17 +00:00
|
|
|
let maintenance = false
|
|
|
|
let launcher = false
|
2020-05-28 06:37:20 +00:00
|
|
|
let fileExists = false
|
|
|
|
let darkMode = false
|
2019-12-10 04:08:49 +00:00
|
|
|
|
2019-06-25 03:06:28 +00:00
|
|
|
function progressSimulation (res) {
|
2019-12-10 04:08:49 +00:00
|
|
|
if (showError) {
|
2021-10-15 06:28:08 +00:00
|
|
|
const resp = JSON.stringify({ Error: 'Simulated error.' }) + '\n'
|
2019-12-10 04:08:49 +00:00
|
|
|
res.write(resp)
|
|
|
|
res.status(200).end()
|
|
|
|
return
|
|
|
|
}
|
2021-10-15 06:28:08 +00:00
|
|
|
let progress = 0.0
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
const resp = JSON.stringify({ Status: ['Processing...', progress] }) + '\n'
|
2019-06-25 03:06:28 +00:00
|
|
|
progress += 0.1
|
|
|
|
res.write(resp)
|
|
|
|
if (progress >= 1) {
|
|
|
|
res.status(200).end()
|
|
|
|
clearInterval(timer)
|
|
|
|
}
|
2020-05-29 20:44:17 +00:00
|
|
|
}, 500)
|
2019-06-25 03:06:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-29 08:29:44 +00:00
|
|
|
function returnConfig (res) {
|
2020-05-29 20:22:58 +00:00
|
|
|
if (showConfigError) {
|
2019-12-10 04:08:49 +00:00
|
|
|
res.status(500).json({})
|
|
|
|
return
|
|
|
|
}
|
2019-06-25 03:06:28 +00:00
|
|
|
res.json({
|
|
|
|
installing_message:
|
|
|
|
'Test Banner <strong>Bold</strong> <pre>Code block</pre> <i>Italic</i> <del>Strike</del>',
|
|
|
|
new_tool: null,
|
|
|
|
packages: [
|
|
|
|
{
|
|
|
|
name: 'Test 1',
|
|
|
|
description: 'LiftInstall GUI Test 1',
|
|
|
|
default: true,
|
|
|
|
source: {
|
|
|
|
name: 'github',
|
|
|
|
match: '^test$',
|
|
|
|
config: { repo: 'j-selby/liftinstall' }
|
|
|
|
},
|
|
|
|
shortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Test 2',
|
|
|
|
description:
|
|
|
|
'Different Banner <strong>Bold</strong> <pre>Code block</pre> <i>Italic</i> <del>Strike</del>',
|
|
|
|
default: null,
|
|
|
|
source: {
|
|
|
|
name: 'github',
|
|
|
|
match: '^test2$',
|
|
|
|
config: { repo: 'j-selby/liftinstall' }
|
|
|
|
},
|
|
|
|
shortcuts: []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
hide_advanced: false
|
|
|
|
})
|
2019-06-29 08:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.get('/api/attrs', (req, res) => {
|
2019-12-10 04:08:49 +00:00
|
|
|
console.log('-- Get attrs')
|
2019-06-29 08:29:44 +00:00
|
|
|
res.send(
|
2019-12-09 01:27:12 +00:00
|
|
|
{ name: 'yuzu', target_url: 'https://raw.githubusercontent.com/j-selby/test-installer/master/config.linux.v2.toml' }
|
2019-06-29 08:29:44 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/api/dark-mode', (req, res) => {
|
2020-05-28 06:37:20 +00:00
|
|
|
res.json(darkMode)
|
2019-06-29 08:29:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/api/installation-status', (req, res) => {
|
|
|
|
res.json({
|
|
|
|
database: { packages: [], shortcuts: [] },
|
|
|
|
install_path: null,
|
2020-05-29 20:44:17 +00:00
|
|
|
preexisting_install: maintenance,
|
|
|
|
is_launcher: launcher,
|
2019-06-29 08:29:44 +00:00
|
|
|
launcher_path: null
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/api/default-path', (req, res) => {
|
|
|
|
res.json({ path: '/tmp/test/' })
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/api/config', (req, res) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
returnConfig(res)
|
|
|
|
}, 3000)
|
2019-06-25 03:06:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
app.post('/api/start-install', (req, res) => {
|
2021-10-15 03:13:31 +00:00
|
|
|
console.log('-- Install:')
|
|
|
|
console.log(req.body)
|
2019-06-25 03:06:28 +00:00
|
|
|
progressSimulation(res)
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/api/exit', (req, res) => {
|
|
|
|
console.log('-- Exit')
|
2019-12-10 04:08:49 +00:00
|
|
|
if (showError) {
|
|
|
|
res.status(500).send('Simulated error: Nothing to see here.')
|
|
|
|
return
|
|
|
|
}
|
2020-05-29 20:44:17 +00:00
|
|
|
res.status(204).send()
|
2019-06-25 03:06:28 +00:00
|
|
|
})
|
|
|
|
|
2020-05-28 06:37:20 +00:00
|
|
|
app.post('/api/verify-path', (req, res) => {
|
|
|
|
console.log('-- Verify Path')
|
|
|
|
res.send({
|
|
|
|
exists: fileExists
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-10-15 06:28:08 +00:00
|
|
|
app.post('/api/check-auth', (req, res) => {
|
|
|
|
console.log('-- Check Authorization')
|
|
|
|
res.send({
|
|
|
|
username: 'test1',
|
|
|
|
token: 'token',
|
|
|
|
jwt_token: {
|
|
|
|
isPatreonAccountLinked: true,
|
|
|
|
isPatreonSubscriptionActive: true,
|
|
|
|
releaseChannels: ['early-access']
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-05-28 06:37:20 +00:00
|
|
|
process.argv.forEach((val, index) => {
|
|
|
|
switch (val) {
|
|
|
|
case 'maintenance':
|
|
|
|
maintenance = true
|
|
|
|
console.log('Simulating maintenance mode')
|
|
|
|
break
|
|
|
|
case 'launcher':
|
|
|
|
maintenance = true
|
|
|
|
launcher = true
|
|
|
|
console.log('Simulating launcher mode')
|
|
|
|
break
|
|
|
|
case 'exists':
|
|
|
|
fileExists = true
|
|
|
|
console.log('Simulating file exists situation')
|
|
|
|
break
|
|
|
|
case 'dark':
|
|
|
|
darkMode = true
|
|
|
|
console.log('Simulating dark mode')
|
|
|
|
break
|
2020-05-29 20:22:58 +00:00
|
|
|
case 'config-error':
|
|
|
|
showConfigError = true
|
|
|
|
console.log('Simulating configuration errors')
|
|
|
|
break
|
|
|
|
case 'error':
|
|
|
|
showError = true
|
|
|
|
console.log('Simulating errors')
|
|
|
|
break
|
2020-05-28 06:37:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-06-25 03:06:28 +00:00
|
|
|
console.log(`Listening on ${port}...`)
|
|
|
|
app.listen(port)
|