summaryrefslogtreecommitdiff
path: root/index.html
blob: dcd7e9880f20271590a2061a572d298fa28ab3b8 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Equestria.dev Package Registry</title>
    <link rel="icon" href="/assets/favicon.png">
    <link rel="stylesheet" href="/assets/bootstrap.min.css">
    <style>
        @media (max-width: 991px) {
            .package, .pkg-grid, .version-grid {
                display: block !important;
            }
        }
    </style>
</head>
<body>
    <div class="container" style="margin-top: 50px;">
        <a onclick="switchToPage('/');" style="cursor: pointer;">
            <h1>Equestria.dev Package Registry</h1>
        </a>
        <hr>
    </div>

    <div id="loader" class="container">
        Loading...
    </div>

    <div id="page" style="display: none;"></div>

    <script src="/assets/bootstrap.bundle.min.js"></script>
    <script>
        async function loadPage() {
            document.getElementById("loader").style.display = "";
            document.getElementById("page").style.display = "none";

            let path = location.pathname.split("/")[1];
            let descriptor = location.pathname.split("/")[2] ?? null;

            if (path in window.pages) {
                await window.pages[path](path, descriptor);
            } else if (path.trim() === "" || path.trim() === "/") {
                await window.pages["home"](path, descriptor);
            } else if (path in window.packages) {
                await window.pages["package"](path, descriptor);
            } else {
                await window.pages["_404"](path, descriptor);
            }

            formatLinks();
            document.getElementById("loader").style.display = "none";
            document.getElementById("page").style.display = "";
        }

        async function getPackages() {
            let page = 1;
            let data = [];
            let lastData = [null];

            while (lastData.length > 0) {
                lastData = await (await fetch("https://source.equestria.dev/api/v4/groups/2/packages?page=" + page)).json();
                data.push(...lastData);
                page++;
            }

            window.packages = {};
            window.config = await (await fetch("https://cdn.equestria.dev/pkgconfig.json")).json();

            for (let pkg of data) {
                if (!(pkg['name'] in window.packages)) {
                    window.packages[pkg['name']] = {
                        name: pkg['name'],
                        latestVersion: null,
                        versions: []
                    }
                }

                window.packages[pkg['name']]['versions'].push({
                    name: pkg['version'],
                    id: {
                        'package': pkg['id'],
                        project: pkg['project_id'],
                        projectSlug: pkg['project_path'],
                        projectLink: "https://source.equestria.dev/" + pkg['project_path'],
                        group: 2
                    },
                    web: "https://source.equestria.dev" + pkg['_links']['web_path'],
                    date: new Date(pkg['created_at'])
                });
            }

            for (let pkg of Object.values(window.packages)) {
                pkg['versions'].sort((a, b) => b.date - a.date);
                pkg['latestVersion'] = pkg['versions'][0];
            }

            return window.packages;
        }

        async function switchToPage(path) {
            window.history.pushState({}, "", path);
            await loadPage();
        }

        function formatLinks() {
            for (let link of Array.from(document.querySelectorAll("a[href]"))) {
                if (link.getAttribute("href").startsWith("/")) {
                    link.onclick = (e) => {
                        e.preventDefault();
                        switchToPage(link.getAttribute("href"));
                        return false;
                    }
                }
            }
        }

        function formatSize(s) {
            if (s < 1024) {
                return s + " bytes";
            } else if (s < 1024**2) {
                return (s / 1024).toFixed(1) + " KiB";
            } else if (s < 1024**3) {
                return (s / 1024**2).toFixed(1) + " MiB";
            } else if (s < 1024**4) {
                return (s / 1024**3).toFixed(1) + " GiB";
            } else {
                return (s / 1024**4).toFixed(1) + " TiB";
            }
        }

        function formatType(t) {
            switch (t) {
                case "zip":
                case "xz":
                case "gz":
                    return "Archive";

                case "exe":
                    return "Windows application";

                case "pkg":
                    return "macOS package";

                case "so":
                    return "ELF shared object";

                case "dylib":
                    return "Mach-O shared object";

                case "":
                case "bin":
                    return "UNIX executable";

                case "lctpk":
                    return "Chatroom package";

                case "otf":
                    return "OpenType™ font";

                case "apk":
                    return "Android package";

                default:
                    return "Unknown file";
            }
        }

        function fileToPlatform(file) {
            let matches = Object.entries(window.config['platforms']['files']).find(i => i[1].includes(file));
            if (!matches) return "-";
            let platform = matches[0];
            let parts = platform.split("-");

            parts[0] = (Object.entries(window.config['platforms']['names']['platforms']).find(i => i[0] === parts[0]) ?? [parts[0], parts[0]])[1];
            parts[1] = (Object.entries(window.config['platforms']['names']['architectures']).find(i => i[0] === parts[1]) ?? [parts[1], parts[1]])[1];
            parts[2] = (Object.entries(window.config['platforms']['names']['profiles']).find(i => i[0] === parts[2]) ?? [parts[2], parts[2]])[1];

            if (parts.join("-") === platform) {
                return platform;
            } else {
                return parts.join(" ").trim();
            }
        }

        window.pages = {
            _404: () => {
                document.title = "Not found · Equestria.dev Package Registry";
                document.getElementById("page").innerHTML = `
                <div class="container">
                    <h2>Not found</h2>
                    <p>The requested page could not be found on this website. If you were looking for a package, it might have been deleted from the registry.</p>
                </div>
                `;
            },
            home: async () => {
                document.getElementById("page").innerHTML = `
                <div class="container">
                    <div class="list-group" id="packages"></div>
                </div>
                `;

                document.getElementById("packages").innerHTML = Object.values(packages).sort((a, b) => a.name.localeCompare(b.name)).map(i => `
                <a href="/${i.name}" class="package list-group-item list-group-item-action" style="display: grid; grid-template-columns: 3fr max-content max-content; grid-gap: 20px;">
                    <div>${i.name}</div>
                    <div class="text-muted">${i.latestVersion.name}</div>
                    <div class="text-muted font-monospace">${i.latestVersion.date.toISOString()}</div>
                </a>
                `).join("");

                document.title = "Index · Equestria.dev Package Registry";
            },
            package: async (path, selected) => {
                let pkg = window.packages[path];

                if (selected) {
                    let version = pkg.versions.find((i) => i.name === selected);
                    if (!version) {
                        await window.pages['_404']();
                        return;
                    }

                    let files = await (await fetch("https://source.equestria.dev/api/v4/projects/" + version['id']['project'] + "/packages/" + version['id']['package'] + "/package_files")).json();

                    document.getElementById("page").innerHTML = `
                    <div class="container">
                        <h2>
                            ${pkg.name}-${version.name}
                        </h2>

                        <p>
                            <a href="/${pkg.name}">↵ Return to the main page of ${pkg.name}</a><br>
                            <a href="${version.web}">View on GitLab</a>
                        </p>

                        ${pkg.latestVersion.name !== version.name ? `
                        <div class="alert alert-danger">
                            This version of ${pkg.name} is outdated, the latest version is <a href="/${pkg.name}/${pkg.latestVersion.name}">${pkg.latestVersion.name}</a>. Please update to the latest version if you can.
                        </div>
                        ` : ""}

                        <h4>Package files</h4>
                        <table class="table">
                            <thead>
                                <tr>
                                    <th scope="col">Name</th>
                                    <th scope="col">Size</th>
                                    <th scope="col">Type</th>
                                    <th scope="col">Platform</th>
                                </tr>
                            </thead>
                            <tbody>
                                ${files.map(file => `
                                <tr>
                                    <td class="col-3"><a href="${version['id']['projectLink']}/-/package_files/${file['id']}/download">${file['file_name']}</a></th>
                                    <td class="col-1">${formatSize(file['size'])}</td>
                                    <td class="col-1">${formatType(file['file_name'].split(".").length > 1 ? file['file_name'].split(".")[file['file_name'].split(".").length - 1] : "")}</td>
                                    <td class="col-2">${fileToPlatform(file['file_name'])}</td>
                                </tr>
                                `).join("")}
                            </tbody>
                        </table>

                        <!--<div class="version-grid" style="display: grid; grid-template-columns: 1fr 1fr; grid-gap: 20px; margin-top: 20px;">
                            <div>
                                <h4>Dependencies</h4>
                                <i>Dependencies are not supported in this version of the software.</i>
                            </div>
                            <div>
                                <h4>Provides</h4>
                                <ul>
                                    ${[
                                        pkg.name,
                                        "package",
                                        "equestriadev"
                                    ].sort((a, b) => a.localeCompare(b)).map(i => `<li>${i}</li>`).join("")}
                                </ul>
                            </div>
                        </div>-->
                    </div>
                    `;

                    document.title = version.name + " · " + pkg.name + " · Equestria.dev Package Registry";
                } else {
                    let prj = await (await fetch("https://source.equestria.dev/api/v4/projects/" + pkg['latestVersion']['id']['project'] + "?license=true")).json();
                    let id = crypto.randomUUID();

                    document.getElementById("page").innerHTML = `
                    <div class="container">
                        <h2>
                            ${pkg.name}
                        </h2>

                        <table class="table table-bordered" style="margin-top: 10px;">
                            <tbody>
                                <tr>
                                    <td class="col-1">
                                        <a target="_blank" href="${pkg.latestVersion.id.projectLink}/-/commits">Updates</a>
                                    </td>
                                    <td class="col-1">
                                        <a target="_blank" href="${pkg.latestVersion.id.projectLink}/-/issues">Bugs</a>
                                    </td>
                                    <td class="col-1">
                                        <a target="_blank" href="${pkg.latestVersion.id.projectLink}/-/branches">Sources</a>
                                    </td>
                                    <td class="col-1">
                                        <a target="_blank" href="${pkg.latestVersion.id.projectLink}">GitLab</a>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <div style="display: grid; grid-template-columns: 2fr 1fr; grid-gap: 20px;" class="pkg-grid">
                            <div>
                                <p>${prj['description'] ?? '<i>The maintainers have not yet provided a description for this package.</i>'}</p>

                                <h3>Releases overview</h3>
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th scope="col">Release</th>
                                            <th scope="col">Platforms</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        ${pkg.versions.map(ver => `
                                        <tr>
                                            <td class="col-1">
                                                <b><a href="/${pkg.name}/${ver.name}">${ver.name}</a></b><br>
                                                <span class="text-muted">${ver.date.toISOString()}</span>
                                            </th>
                                            <td class="col-2" id="pkg-${pkg.name}-${ver.name}-${id}">…</td>
                                        </tr>
                                        `).join("")}
                                    </tbody>
                                </table>
                            </div>
                            <div>
                                <div class="alert alert-success">This package is officially compiled and packaged by Equestria.dev.</div>
                                <hr>
                                <b>Package info</b>
                                <ul>
                                    <li>Upstream: <a target="_blank" href="${pkg.latestVersion.id.projectLink}">${pkg.latestVersion.id.projectLink}</a></li>
                                    <li>License(s): ${prj['license'] ? prj['license']['nickname'] : "Unknown/All rights reserved"}</li>
                                    <li>Maintainers: equestria.dev</li>
                                </ul>
                                <hr>
                                <p>You can contact the maintainers of this package on <a target="_blank" href="${pkg.latestVersion.id.projectLink}">GitLab</a>.</p>
                            </div>
                        </div>
                    </div>
                    `;

                    pkg.versions.map((ver, i) => {
                        setTimeout(async () => {
                            if (!document.getElementById("pkg-" + pkg.name + "-" + ver.name + "-" + id)) return;
                            let files = await (await fetch("https://source.equestria.dev/api/v4/projects/" + ver.id.project + "/packages/" + ver.id.package + "/package_files")).json();
                            let platforms = [...new Set(files.map(i => fileToPlatform(i['file_name'])))].sort((a, b) => a.localeCompare(b));
                            document.getElementById("pkg-" + pkg.name + "-" + ver.name + "-" + id).innerText = platforms.join(", ");
                        }, 1000 * i);
                    });

                    document.title = pkg.name + " · Equestria.dev Package Registry";
                }
            }
        };

        (async () => {
            await getPackages();
            await loadPage();
        })();

        window.onpopstate = loadPage;
        window.onlocationchange = loadPage;

        window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
            document.body.setAttribute("data-bs-theme", e.matches ? "dark" : "light");
        });

        if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
            document.body.setAttribute("data-bs-theme", "dark");
        } else {
            document.body.setAttribute("data-bs-theme", "light");
        }
    </script>
</body>
</html>