Skip to content

Commit

Permalink
Update for Wallet/Blogs and Messenger APKs
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Oct 31, 2024
1 parent a5631ec commit 2818fd6
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
32 changes: 32 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ app.use('/', express.static('files'), serveIndex('files', {
template: createHtmlRender()
}))

const downloadTmpl = fs.readFileSync('template.html', 'utf-8')

function listApps() {
let apps = {}
const dirs = fs.readdirSync('files', { withFileTypes: true })
Expand Down Expand Up @@ -85,6 +87,7 @@ function getAppVersions(name, platform, after = null, latest = false) {
versions[curVer].exe = file
versions[curVer].exe_url = '/api/exe/' + url
}
versions[curVer].html_url = '/api/html/' + url
latestVersion = { [curVer]: versions[curVer] }
}
if (latest) {
Expand Down Expand Up @@ -145,6 +148,22 @@ app.get('/api/:app/:platform?', tryCatch(async (req, res) => {
})
}))

function renderHtml(res, data, app, platform, version) {
let htmlStr = downloadTmpl
htmlStr = htmlStr.split('{$TITLE}').join('GOLOS ' + app + ' - ' + version)
if (data[version].exe_url) {
htmlStr = htmlStr.split('{$EXE_URL}').join(data[version].exe_url)
}
if (data[version].txt_url) {
htmlStr = htmlStr.split('{$TXT_URL}').join(data[version].txt_url)
} else {
htmlStr = htmlStr.split('{$TXT_URL}').join('')
}

res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.send(htmlStr)
}

async function getSpecific(req, res, what) {
const { app, platform, version} = req.params
const data = getAppVersions(app, platform)
Expand All @@ -153,6 +172,8 @@ async function getSpecific(req, res, what) {
if (data[version]) {
if (data[version][what]) {
res.redirect(307, dir + '/' + data[version][what])
} else if (what === 'html' && data[version].html_url) {
renderHtml(res, data, app, platform, version)
} else {
throw new Error('No such ' + what + ' ' + version + ' of ' + app + '-' + platform)
}
Expand All @@ -164,6 +185,10 @@ async function getSpecific(req, res, what) {
if (!entries.length) {
throw new Error('No latest ' + what + ' of ' + app + '-' + platform)
}
if (what === 'html') {
res.redirect(307, entries[entries.length - 1][1].html_url)
return
}
res.redirect(307, dir + '/' + entries[entries.length - 1][1][what])
}
}
Expand All @@ -182,6 +207,13 @@ app.get('/api/txt/:app/:platform/:version', tryCatch(async (req, res) => {
await getSpecific(req, res, 'txt')
}))

app.get('/api/html/:app/:version', tryCatch(async (req, res) => {
await getSpecific(req, res, 'html')
}))
app.get('/api/html/:app/:platform/:version', tryCatch(async (req, res) => {
await getSpecific(req, res, 'html')
}))

app.use((err, req, res, next) => {
console.error(err)
res.status(400).json({
Expand Down
108 changes: 108 additions & 0 deletions template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
Golos Update
</title>
</head>
<body>
<div style="padding: 1rem;">
<h2>{$TITLE}</h2>
<hr>
<div id="txt" style="white-space: pre-line;">...</div>
<div>
<a href="{$EXE_URL}">
<button type="button" class="button" style="margin-top: 1rem;">Скачать</button>
</a>
</div>
</div>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900,900i&subset=cyrillic,cyrillic-ext">
<style>
body {
font-family: "Roboto", "Helvetica Neue", Arial, sans-serif;
font-weight: normal;
line-height: 1.6;
}
h2 {
font-size: 1.25rem;

line-height: 1.4;
margin-top: 0;
margin-bottom: 0.5rem;

font-family: "Roboto", "Helvetica Neue", Arial, sans-serif;
font-style: normal;
font-weight: normal;
color: inherit;
text-rendering: optimizeLegibility;
}
@media print, screen and (min-width: 40em) {
h2 {
font-size: 2.5rem;
}
}
hr {
clear: both;
max-width: 75rem;
height: 0;
margin: 1.25rem auto;
border-top: 0;
border-right: 0;
border-bottom: 1px solid #cacaca;
border-left: 0;
}
.button {
text-align: center;
font-weight: bold;

text-transform: uppercase;

background-color: #0078C4;
color: #fefefe;

display: inline-block;
vertical-align: middle;
margin: 0 0 1rem 0;
margin-top: 0px;
margin-right: 0px;
padding: 0.85em 1em;
border: 1px solid transparent;
border-radius: 100px;
-webkit-transition: background-color 0.25s ease-out, color 0.25s ease-out;
transition: background-color 0.25s ease-out, color 0.25s ease-out;
font-family: "Roboto";
font-size: 0.9rem;
-webkit-appearance: none;
line-height: 1;
text-align: center;
cursor: pointer;
}
.button:hover, .button:focus {
background-color: rgb(0, 102, 167);
}
</style>
<script>
async function loadTxt() {
let res
if (!'{$TXT_URL}') {
res = ''
} else {
try {
const decoder = new TextDecoder('windows-1251')
res = await fetch('{$TXT_URL}')
res = decoder.decode(await res.arrayBuffer())
} catch (err) {
console.error(err)
res = err.toString()
}
}
document.getElementById('txt').textContent = res
}
loadTxt()
</script>
</body>
</html>

0 comments on commit 2818fd6

Please sign in to comment.