Skip to content

Commit

Permalink
Kotlin rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
starscouts committed Sep 7, 2024
1 parent e0305c9 commit 642a12b
Show file tree
Hide file tree
Showing 45 changed files with 713 additions and 235 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ serverkt/build
serverkt/out
serverkt/.kotlin
serverkt/*.jar
serverkt/blocklist.txt
34 changes: 1 addition & 33 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/sshConfigs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/webServers.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

171 changes: 171 additions & 0 deletions client/admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Administrator Tools | Floofi Voice Generator</title>
<link rel="stylesheet" href="https://fella.floo.fi/0.3.3/fella.min.css" integrity="sha384-1Im8AmCEPI7+gL0sQFNekjJ/RE5oo3q2Up8muPiUO5Ho6QKmdx74KgECaEx4yWqV" crossorigin="anonymous">
<link rel="shortcut icon" href="/assets/favicon.png" type="image/svg+xml">
<!--suppress JSUnusedGlobalSymbols -->
<script>
let FF_FOUC_FIX;
</script>
<script src="/assets/src/config.js"></script>
</head>
<body>
<br><br>

<main>
<div id="loader" class="fella-loader-container">
<svg class="fella-loader" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" style="shape-rendering: auto; display: block; background: transparent;">
<g><g transform="rotate(0 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.9166666666666666s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(30 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.8333333333333334s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(60 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.75s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(90 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.6666666666666666s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(120 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.5833333333333334s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(150 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.5s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(180 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.4166666666666667s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(210 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.3333333333333333s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(240 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.25s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(270 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.16666666666666666s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(300 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="-0.08333333333333333s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g transform="rotate(330 50 50)">
<rect fill="#8f8f8f" height="16" width="5" ry="2.56" rx="2.5" y="22" x="47.5">
<animate repeatCount="indefinite" begin="0s" dur="1s" keyTimes="0;1" values="1;0" attributeName="opacity"></animate>
</rect>
</g><g></g></g>
</svg>
</div>

<div id="prompt" style="display: none;">
<div id="navbar-placeholder"></div>

<section class="fella-section fella-container fella-section-linked">
<h2 class="fella-title">Administrator Tools</h2>

<div style="margin-top: 20px;" id="list-outer">
<div id="list" class="fella-list-container" style="display: none;"></div>
<div id="list-message" style="font-style: italic;">Loading generations to review...</div>
<div id="list-message2">There are no more generations that need review.</div>
</div>
</section>
</div>

<script src="/assets/src/navbar.js"></script>
<script>
(async () => {
let code = (await (await fetch(window.SERVER + "/api/v2/status", {
credentials: "include",
headers: {
"Authorization": localStorage.getItem('token') ? "PrivateToken " + localStorage.getItem('token') : ''
}
})).json()).error?.code;

if (code === 401) {
location.href = "/";
} else if (code === 403) {
location.href = "/banned";
} else {
let allowed = (await (await fetch(window.SERVER + "/api/v2/admin/available", {
credentials: "include",
headers: {
"Authorization": localStorage.getItem('token') ? "PrivateToken " + localStorage.getItem('token') : ''
}
})).json()).output['available'];

if (allowed) {
await prepareNavbar();
await load();
document.getElementById("loader").style.display = "none";
document.getElementById("prompt").style.display = "";
} else {
location.href = "/app";
}
}
})();

async function completeReview(id) {
document.getElementById("list").style.display = "none";
document.getElementById("list-message").style.display = "";
document.getElementById("list-message2").style.display = "none";

await fetch(window.SERVER + "/api/v2/admin/history/" + id, {
method: "DELETE",
credentials: "include",
headers: {
"Authorization": localStorage.getItem('token') ? "PrivateToken " + localStorage.getItem('token') : ''
}
});

await load();
}

async function load() {
window.generations = (await (await fetch(window.SERVER + "/api/v2/admin/history", {
credentials: "include",
headers: {
"Authorization": localStorage.getItem('token') ? "PrivateToken " + localStorage.getItem('token') : ''
}
})).json()).output.history;

document.getElementById("list").innerHTML = window.generations.map(i => `
<div class="fella-list-item fella-list-item-padded" style="display: grid; grid-template-columns: 1fr 2.5fr .5fr; grid-gap: 30px;">
<span><b>${i['authorName']}</b><br>${i.status}<br>${i['model']}</span>
<span>${i['input']}</span>
<span>
<a href="#" onclick="completeReview('${i.id}');">Review</a> / <a target="_blank" href="${i['audioUrl']}">View</a><br>
<a href="#" onclick="navigator.clipboard.writeText('${i['authorId']}');">Copy user ID</a><br>
<a href="#" onclick="navigator.clipboard.writeText('${i.id}');">Copy job ID</a>
</span>
</div>
`).join("");

if (window.generations.length > 0) {
document.getElementById("list").style.display = "";
document.getElementById("list-message").style.display = "none";
document.getElementById("list-message2").style.display = "none";
} else {
document.getElementById("list").style.display = "none";
document.getElementById("list-message").style.display = "none";
document.getElementById("list-message2").style.display = "";
}
}
</script>
</main>

</body>
</html>
6 changes: 5 additions & 1 deletion client/assets/src/config.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
window.SERVER = "http://127.0.0.1:8080";
if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') {
window.SERVER = "http://127.0.0.1:8080";
} else {
window.SERVER = "https://voice-api.floo.fi";
}
24 changes: 12 additions & 12 deletions client/assets/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
return await _fetch(input, init);
}

window.models = (await (await fetch(window.SERVER + "/api/v2/models")).json()).output;
window.models = (await (await fetch(window.SERVER + "/api/v2/models")).json()).output.models;
window.processing = false;

document.getElementById("model").innerHTML = window.models.map(i => `
<option value="${i.id}">${i.name}</option>
`).join("");
<option value="${i.id}">${i.name}</option>
`).join("");
document.getElementById("model-details").innerHTML = window.models.map(i => `
<div id="model-${i.id}" class="model text-muted small" style="text-align: center; display: none;">v${i.version}${i.source}</div>
`).join("");
<div id="model-${i.id}" class="model text-muted small" style="text-align: center; display: none;">v${i.version}${i.source}</div>
`).join("");

refreshModel();

Expand Down Expand Up @@ -81,7 +81,7 @@
if (!data['error']) {
document.getElementById("input").value = "";

fetch(window.SERVER + "/api/v2/history?amount=30").then((res) => {
fetch(window.SERVER + "/api/v2/history").then((res) => {
res.json().then((data) => {
window.listData = data['output']['history'];
refreshList();
Expand Down Expand Up @@ -175,7 +175,7 @@
fetch(window.SERVER + "/api/v2/history/" + id, {
method: "DELETE"
}).then(() => {
fetch(window.SERVER + "/api/v2/history?amount=30").then((res) => {
fetch(window.SERVER + "/api/v2/history").then((res) => {
res.json().then((data) => {
window.listData = data['output']['history'];
window.lastList = data['output']['history'];
Expand All @@ -192,7 +192,7 @@
window.playerDownload = (id, name) => {
let element = document.createElement("a");
element.setAttribute("download", name);
element.setAttribute("href", "https://cdn.equestria.dev/sunnystarbot/content/" + id + "/audio.wav");
element.setAttribute("href", "https://cdn.floo.fi/voice-generator/content/" + id + "/audio.wav");
element.click();
}

Expand All @@ -205,7 +205,7 @@
document.getElementById("list-message").style.display = "none";
document.getElementById("list").style.display = "";

for (let id of Array.from(document.getElementById("list").children).map(i => i.id.split("-")[1])) {
for (let id of Array.from(document.getElementById("list").children).map(i => i.id.split("-").slice(1).join("-"))) {
if (!data.map(i => i.id).includes(id)) {
document.getElementById("history-" + id).outerHTML = "";
}
Expand Down Expand Up @@ -348,11 +348,11 @@
if (item.status === "processed") {
document.querySelector("#history-" + item.id + " .history-player").style.display = "";
document.querySelector("#history-" + item.id + " .history-spectrogram").style.display = "flex";
document.querySelector("#history-" + item.id + " .history-spectrogram-img").src = "https://cdn.equestria.dev/sunnystarbot/content/" + item.id + "/figure.png";
document.querySelector("#history-" + item.id + " .history-spectrogram-img").src = "https://cdn.floo.fi/voice-generator/" + item.id + "/figure.png";
if (document.querySelector("#history-" + item.id + " .history-loading")) document.querySelector("#history-" + item.id + " .history-loading").style.display = "none";

if (document.querySelector("#history-" + item.id + " .history-player audio").src.trim() === "") {
document.querySelector("#history-" + item.id + " .history-player audio").src = "https://cdn.equestria.dev/sunnystarbot/content/" + item.id + "/audio.wav";
document.querySelector("#history-" + item.id + " .history-player audio").src = "https://cdn.floo.fi/voice-generator/" + item.id + "/audio.wav";
}
} else {
document.querySelector("#history-" + item.id + " .history-player").style.display = "none";
Expand Down Expand Up @@ -387,7 +387,7 @@

window.configureRefresh = () => {
function refresh() {
fetch(window.SERVER + "/api/v2/history?amount=30").then((res) => {
fetch(window.SERVER + "/api/v2/history").then((res) => {
res.json().then((data) => {
window.listData = data['output']['history'];
refreshList();
Expand Down
Loading

0 comments on commit 642a12b

Please sign in to comment.