1
0
forked from security/hakurei

cmd/pkgserver: guard sass/ts behind build tag

Packaging nodejs and ruby is an immense burden for the Rosa OS base system, and these files diff poorly.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-12 01:40:04 +09:00
committed by mae
parent 99f1c6aab4
commit 770fd46510
9 changed files with 20 additions and 184 deletions

3
.gitignore vendored
View File

@@ -28,6 +28,9 @@ go.work.sum
# go generate
/cmd/hakurei/LICENSE
/cmd/pkgserver/.sass-cache
/cmd/pkgserver/ui/static/*.js
/cmd/pkgserver/ui/static/*.css*
/cmd/pkgserver/ui/static/*.css.map
/internal/pkg/testdata/testtool
/internal/rosa/hakurei_current.tar.gz

View File

@@ -1,13 +1,6 @@
package main
import (
"embed"
"net/http"
)
//go:generate sh -c "sass ui/static/dark.scss ui/static/dark.css && sass ui/static/light.scss ui/static/light.css && tsc -p ui/static"
//go:embed ui/*
var content embed.FS
import "net/http"
func serveWebUI(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")

View File

@@ -1,6 +0,0 @@
@use 'common';
html {
background-color: #2c2c2c;
color: ghostwhite; }
/*# sourceMappingURL=dark.css.map */

View File

@@ -1,7 +0,0 @@
{
"version": 3,
"mappings": "AAAA,aAAa;AAEb,IAAK;EACH,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,UAAU",
"sources": ["dark.scss"],
"names": [],
"file": "dark.css"
}

View File

@@ -1,150 +0,0 @@
class PackageIndexEntry {
name;
size;
description;
website;
version;
report;
}
function toHTML(entry) {
let v = entry.version != null ? `<span>${escapeHtml(entry.version)}</span>` : "";
let s = entry.size != null ? `<p>Size: ${toByteSizeString(entry.size)} (${entry.size})</p>` : "";
let d = entry.description != null ? `<p>${escapeHtml(entry.description)}</p>` : "";
let w = entry.website != null ? `<a href="${encodeURI(entry.website)}">Website</a>` : "";
let r = entry.report ? `Log (<a href=\"${encodeURI('/api/v1/status/' + entry.name)}\">View</a> | <a href=\"${encodeURI('/status/' + entry.name)}\">Download</a>)` : "";
let row = (document.createElement('tr'));
row.innerHTML = `<td>
<h2>${escapeHtml(entry.name)} ${v}</h2>
${d}
${s}
${w}
${r}
</td>`;
return row;
}
function toByteSizeString(bytes) {
if (bytes < 1024)
return `${bytes}B`;
if (bytes < Math.pow(1024, 2))
return `${(bytes / 1024).toFixed(2)}kiB`;
if (bytes < Math.pow(1024, 3))
return `${(bytes / Math.pow(1024, 2)).toFixed(2)}MiB`;
if (bytes < Math.pow(1024, 4))
return `${(bytes / Math.pow(1024, 3)).toFixed(2)}GiB`;
if (bytes < Math.pow(1024, 5))
return `${(bytes / Math.pow(1024, 4)).toFixed(2)}TiB`;
return "not only is it big, it's large";
}
const API_VERSION = 1;
const ENDPOINT = `/api/v${API_VERSION}`;
class InfoPayload {
count;
hakurei_version;
}
async function infoRequest() {
const res = await fetch(`${ENDPOINT}/info`);
const payload = await res.json();
return payload;
}
class GetPayload {
count;
values;
}
var SortOrders;
(function (SortOrders) {
SortOrders[SortOrders["DeclarationAscending"] = 0] = "DeclarationAscending";
SortOrders[SortOrders["DeclarationDescending"] = 1] = "DeclarationDescending";
SortOrders[SortOrders["NameAscending"] = 2] = "NameAscending";
SortOrders[SortOrders["NameDescending"] = 3] = "NameDescending";
})(SortOrders || (SortOrders = {}));
async function getRequest(limit, index, sort) {
const res = await fetch(`${ENDPOINT}/get?limit=${limit}&index=${index}&sort=${sort.valueOf()}`);
const payload = await res.json();
return payload;
}
class State {
entriesPerPage = 10;
entryIndex = 0;
maxEntries = 0;
sort = SortOrders.DeclarationAscending;
getEntriesPerPage() {
return this.entriesPerPage;
}
setEntriesPerPage(entriesPerPage) {
this.entriesPerPage = entriesPerPage;
this.setEntryIndex(Math.floor(this.getEntryIndex() / entriesPerPage) * entriesPerPage);
}
getEntryIndex() {
return this.entryIndex;
}
setEntryIndex(entryIndex) {
this.entryIndex = entryIndex;
this.updatePage();
this.updateRange();
this.updateListings();
}
getMaxEntries() {
return this.maxEntries;
}
setMaxEntries(max) {
this.maxEntries = max;
}
getSortOrder() {
return this.sort;
}
setSortOrder(sortOrder) {
this.sort = sortOrder;
this.setEntryIndex(0);
}
updatePage() {
let page = Math.ceil(((this.getEntryIndex() + this.getEntriesPerPage()) - 1) / this.getEntriesPerPage());
document.getElementById("page-number").innerText = String(page);
}
updateRange() {
let max = Math.min(this.getEntryIndex() + this.getEntriesPerPage(), this.getMaxEntries());
document.getElementById("entry-counter").innerText = `${this.getEntryIndex() + 1}-${max} of ${this.getMaxEntries()}`;
}
updateListings() {
getRequest(this.getEntriesPerPage(), this.getEntryIndex(), this.getSortOrder())
.then(res => {
let table = document.getElementById("pkg-list");
table.innerHTML = '';
for (let i = 0; i < res.count; i++) {
table.appendChild(toHTML(res.values[i]));
}
});
}
}
let STATE;
function prevPage() {
let index = STATE.getEntryIndex();
STATE.setEntryIndex(Math.max(0, index - STATE.getEntriesPerPage()));
}
function nextPage() {
let index = STATE.getEntryIndex();
STATE.setEntryIndex(Math.min((Math.ceil(STATE.getMaxEntries() / STATE.getEntriesPerPage()) * STATE.getEntriesPerPage()) - STATE.getEntriesPerPage(), index + STATE.getEntriesPerPage()));
}
function escapeHtml(str) {
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
}
document.addEventListener("DOMContentLoaded", () => {
STATE = new State();
infoRequest()
.then(res => {
STATE.setMaxEntries(res.count);
document.getElementById("hakurei-version").innerText = res.hakurei_version;
STATE.updateRange();
STATE.updateListings();
});
document.getElementById("count").addEventListener("change", (event) => {
STATE.setEntriesPerPage(parseInt(event.target.value));
});
document.getElementById("sort").addEventListener("change", (event) => {
STATE.setSortOrder(parseInt(event.target.value));
});
});

View File

@@ -1,6 +0,0 @@
@use 'common';
html {
background-color: #d3d3d3;
color: black; }
/*# sourceMappingURL=light.css.map */

View File

@@ -1,7 +0,0 @@
{
"version": 3,
"mappings": "AAAA,aAAa;AAEb,IAAK;EACH,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,KAAK",
"sources": ["light.scss"],
"names": [],
"file": "light.css"
}

9
cmd/pkgserver/ui_full.go Normal file
View File

@@ -0,0 +1,9 @@
//go:build frontend
package main
import "embed"
//go:generate sh -c "sass ui/static/dark.scss ui/static/dark.css && sass ui/static/light.scss ui/static/light.css && tsc -p ui/static"
//go:embed ui/*
var content embed.FS

7
cmd/pkgserver/ui_stub.go Normal file
View File

@@ -0,0 +1,7 @@
//go:build !frontend
package main
import "testing/fstest"
var content fstest.MapFS