Skip to content

Commit 21963c0

Browse files
authored
Create download.html
1 parent e35df58 commit 21963c0

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

download.html

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
2+
<title>MultiPaper Downloads</title>
3+
4+
<style>
5+
html {
6+
height: 100%;
7+
}
8+
9+
body {
10+
background: #f8fff8;
11+
display: flex;
12+
font-family: Arial, Helvetica, sans-serif;
13+
height: 100%;
14+
justify-content: center;
15+
margin: 0;
16+
}
17+
18+
main {
19+
background: white;
20+
box-shadow: 0 0 5px #637063;
21+
height: fit-content;
22+
margin: 0 auto;
23+
min-width: 850px;
24+
padding: 40px 10px;
25+
text-align: center;
26+
}
27+
28+
table {
29+
font-size: 0.9em;
30+
width: 100%;
31+
}
32+
33+
tr.header {
34+
font-size: 1.2em;
35+
text-align: center;
36+
}
37+
38+
td {
39+
border-bottom: 1px #aaa solid;
40+
min-width: 170px;
41+
padding: 15px;
42+
padding-top: 17px;
43+
text-align: center;
44+
}
45+
46+
ul {
47+
list-style-type: none;
48+
padding-left: 0;
49+
margin: 0;
50+
text-align: left;
51+
}
52+
53+
li {
54+
width: 450px;
55+
white-space: nowrap;
56+
overflow: hidden;
57+
text-overflow: ellipsis;
58+
}
59+
60+
code {
61+
position: relative;
62+
top: -2px;
63+
}
64+
65+
a {
66+
color: rgb(0, 153, 0);
67+
}
68+
</style>
69+
70+
<main>
71+
<h1>MultiPaper Downloads</h1>
72+
<p>
73+
MultiPaper downloads on this page are licensed under <a href="https://github.com/MultiPaper/MultiPaper/blob/main/LICENSE.txt">GPLv3</a><br/>
74+
MultiPaper-Master downloads are licensed under <a href="https://github.com/MultiPaper/MultiPaper/blob/main/MultiPaper-Master/LICENSE.txt">MIT</a>
75+
</p>
76+
</main>
77+
78+
<script>
79+
const insertVersionGroupLinks = (versions, selectedVersion, latestVersion) => {
80+
const p = document.createElement('p');
81+
p.innerHTML = versions
82+
.map(version => version == selectedVersion ? version : `<a href="?${version}">${version}</a>`)
83+
.join(' | ');
84+
document.querySelector('main').appendChild(p);
85+
86+
if (selectedVersion != latestVersion) {
87+
const error = document.createElement('p');
88+
error.innerHTML = 'Warning: These versions are outdated and may not contain the latest security and stability features.<br/>No support will be given for these builds.';
89+
error.style.color = 'red';
90+
document.querySelector('main').appendChild(error);
91+
}
92+
}
93+
94+
const insertVersion = version => {
95+
const h2 = document.createElement('h2');
96+
h2.innerText = `Version ${version}`;
97+
document.querySelector('main').appendChild(h2);
98+
99+
table = document.createElement('table');
100+
table.innerHTML = '<tr class="header"><td>Build No.</td><td>Changes</td><td>Download</td></tr>'
101+
table.cellSpacing = 0;
102+
document.querySelector('main').appendChild(table);
103+
104+
return table;
105+
};
106+
107+
const insertBuild = (data, table) => {
108+
const tr = document.createElement('tr');
109+
110+
table.appendChild(tr);
111+
112+
const build = document.createElement('td');
113+
build.innerHTML = `<b>#${data.build}</b> ${new Date(data.time).toLocaleDateString()}`;
114+
tr.appendChild(build);
115+
116+
const changes = document.createElement('td');
117+
changes.innerHTML = `<ul>${data.changes.map(change => `<li><code>[<a href="https://github.com/MultiPaper/MultiPaper/commit/${change.commit}">${change.commit.substr(0, 7)}</a>]</code> ${change.summary}</li>`).join('')}</ul>`;
118+
tr.appendChild(changes);
119+
120+
const downloads = document.createElement('td');
121+
downloads.innerHTML = Object.values(data.downloads).map(download => `<a href="${getFileUrl(data, download.name)}">${download.name}</a>`).join('<br/>');
122+
tr.appendChild(downloads);
123+
};
124+
125+
const getFileUrl = (build, file) => {
126+
return `https://api.multipaper.io/v2/projects/multipaper/versions/${build.version}/builds/${build.build}/downloads/${file}`;
127+
};
128+
129+
const fetchBuilds = async (url) => {
130+
const data = await (await fetch(url)).json();
131+
132+
let lastVersion;
133+
let table;
134+
135+
for (let i = data.builds.length - 1; i >= 0 && i >= data.builds.length - 50; i--) {
136+
const build = data.builds[i];
137+
138+
if (build.version != lastVersion) {
139+
lastVersion = build.version;
140+
table = insertVersion(lastVersion);
141+
}
142+
143+
insertBuild(build, table);
144+
}
145+
};
146+
147+
const fetchVersions = async (url) => {
148+
const data = await (await fetch(url)).json();
149+
150+
const lastestVersion = data.version_groups[data.version_groups.length - 1];
151+
let versionGroup;
152+
if (location.search.length && ~data.version_groups.indexOf(location.search.substr(1))) {
153+
versionGroup = location.search.substr(1);
154+
} else {
155+
versionGroup = lastestVersion;
156+
}
157+
158+
insertVersionGroupLinks(data.version_groups, versionGroup, lastestVersion);
159+
160+
fetchBuilds(`${url}/version_group/${versionGroup}/builds`);
161+
};
162+
163+
fetchVersions('https://api.multipaper.io/v2/projects/multipaper');
164+
</script>

0 commit comments

Comments
 (0)