add processing server check

This commit is contained in:
sky
2025-08-12 14:14:36 -04:00
parent 9389d0c7e4
commit db94e9fe49
5 changed files with 228 additions and 110 deletions

View File

@ -194,22 +194,29 @@ async function editProfile(body, token, admin) {
let fileType = (await fileTypeFromBuffer(pfp))["ext"];
if (["png", "jpg", "gif", "avif", "webp", "tiff"].includes(fileType)) {
let url;
let dir = `${process.env.DATA_PATH}/data/${existingAccount.id}/`;
let dir = `${process.env.DATA_PATH}/data/${userData.id}/`;
let uuid = crypto.randomUUID();
let path = `${process.env.DATA_PATH}/data/${existingAccount.id}/${uuid}.webp`;
url = `/data/${existingAccount.id}/${uuid}.webp`;
let path = `${process.env.DATA_PATH}/data/${userData.id}/${uuid}.webp`;
url = `/data/${userData.id}/${uuid}.webp`;
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path, "");
await sharp(pfp, { animated: fileType == "gif" })
.resize({ width: 300, withoutEnlargement: true })
.webp({ quality: 70, effort: 4 })
.toFile(path);
await fs.unlink(`${__dirname}/${existingAccount.pfp_url}`, () => {});
await fs.unlink(`${__dirname}/${userData.pfp_url}`, () => {});
const updateAccount = accs.query(`UPDATE accounts SET pfp_url = $url WHERE username = $user`)
updateAccount.get({ $url: url, $user: user });
}
}
if (body.artist) {
let checkStatus = new Request({
url: process.env.PROCESSING_SERVER + "/status"
});
let checkStatusRequest = await fetch(checkStatus);
if(checkStatusRequest.status != 200) {
return { success: false, err: "processing server is down, try again later"};
}
let path = await download(body.url);
console.log("exit download");
let file = Bun.file(path);
@ -224,7 +231,7 @@ async function editProfile(body, token, admin) {
console.log("created request");
let oggFile = await fetch(request);
console.log("finished request");
let filePath = `/data/${existingAccount.id}/${crypto.randomUUID()}.ogg`;
let filePath = `/data/${userData.id}/${crypto.randomUUID()}.ogg`;
await Bun.write(process.env.DATA_PATH + filePath, oggFile);
const updateAccount = accs.query(`UPDATE accounts SET music = $music WHERE username = $user`)
updateAccount.get({ $music: JSON.stringify({

View File

@ -46,25 +46,31 @@
<link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
<script>
let audioObject;
document.addEventListener("DOMContentLoaded", ()=>{
let music = {{ is_music }};
let audioObject;
if(music) {
let url = "{{ song_url }}";
audioObject = new Audio(url);
audioObject.addEventListener("loadeddata", () => {
document.getElementById("totalLength").innerText = `${Math.floor(audioObject.duration/60)}:${String(Math.floor(audioObject.duration%60)).padStart(2, "0")}`;
document.getElementById("playbar").value = 0;
})
document.getElementById("enter").addEventListener("click", async ()=>{
document.getElementById("enter").style.backgroundColor = "#00000000"
document.getElementById("enter").style.backdropFilter = "blur(0px)"
document.getElementById("enter").style.opacity = "0";
setTimeout( () => {
document.getElementById("enter").style.display = "none";
setTimeout(() => {
audioObject.play();
audioObject.loop = true;
}, 700);
}, 500)
setTimeout( () => {
document.getElementById("enter").style.display = "none";
}, 950);
});
} else {
document.getElementById("enter").style.display = "none";
document.querySelectorAll("section")[0].querySelectorAll(".profile-element")[1].style.display = "none";
}
document.getElementById("playPause").addEventListener("click", ()=>{
if(audioObject.paused) {

View File

@ -130,10 +130,12 @@
document.getElementById("title").innerText = "Upload successful!";
document.getElementById("text").style.display = "none";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
} else {
document.getElementById("title").innerText = "Upload failed. This probably means something bad happened, send an email to support@selenite.cc or ping @skysthelimit.dev";
document.getElementById("text").style.display = "none";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
}
return;
} else if (state == "download") {
@ -156,11 +158,13 @@
document.getElementById("title").innerText = "Download successful!";
document.getElementById("text").style.display = "none";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
} else {
document.getElementById("title").innerText = "Download failed.";
document.getElementById("body-text").innerText = data.reason;
document.getElementById("body-text").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
}
console.log(data);
data = JSON.parse(data.data);
@ -193,7 +197,8 @@
document.getElementById("search").style.display = "none";
document.querySelector("results").style.display = "none";
document.getElementById("popup").style.display = "flex";
await fetch("/api/profile/edit", {
document.getElementById("blur").style.display = "flex";
let data = await fetch("/api/profile/edit", {
credentials: "include",
headers: {
"Content-type": "application/json; charset=UTF-8",
@ -202,7 +207,24 @@
method: "POST",
mode: "cors",
});
let resp = await data.json();
if(data.status == 200) {
location.reload();
} else {
document.getElementById("title").innerText = "error!";
document.getElementById("pfp_upload").style.display = "none";
document.getElementById("pfp_reminder").style.display = "none";
document.getElementById("body-text").style.display = "flex";
document.getElementById("body-text").innerText = resp.err;
document.getElementById("clear").style.display = "none";
document.getElementById("text").style.display = "none";
document.getElementById("counter").style.display = "none";
document.getElementById("submit").style.display = "none";
document.getElementById("search").style.display = "none";
document.querySelector("results").style.display = "none";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
}
}
document.addEventListener("DOMContentLoaded", async () => {
document.getElementById("pfp_upload").addEventListener("change", (e) => {
@ -213,10 +235,22 @@
});
document.getElementById("submit").addEventListener("click", await setProfile);
document.getElementById("clear").addEventListener("click", async()=>{state="clearpfp";await setProfile()});
document.querySelectorAll("#edit").forEach((element) => {
element.addEventListener("click", (e) => {
console.log(e.target.parentElement.children[0].id);
if (e.target.parentElement.children[0].id == "name") {
document.getElementById("pfp").addEventListener("click", () => {
state = "pfp";
document.getElementById("title").innerText = "upload a new profile picture";
document.getElementById("pfp_upload").style.display = "flex";
document.getElementById("pfp_reminder").style.display = "flex";
document.getElementById("body-text").style.display = "none";
document.getElementById("clear").style.display = "flex";
document.getElementById("text").style.display = "none";
document.getElementById("counter").style.display = "none";
document.getElementById("submit").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
document.getElementById("search").style.display = "none";
document.querySelector("results").style.display = "none";
});
document.getElementById("name").addEventListener("click", () => {
state = "name";
document.getElementById("title").innerText = "change your name";
document.getElementById("text").setAttribute("maxlength", "20");
@ -230,9 +264,11 @@
document.getElementById("counter").style.display = "flex";
document.getElementById("submit").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
document.getElementById("search").style.display = "none";
document.querySelector("results").style.display = "none";
} else if (e.target.parentElement.children[0].id == "bio") {
});
document.getElementById("about").addEventListener("click", () => {
state = "bio";
document.getElementById("title").innerText = "change your about me";
document.getElementById("text").setAttribute("maxlength", "200");
@ -246,9 +282,11 @@
document.getElementById("counter").style.display = "flex";
document.getElementById("submit").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
document.getElementById("search").style.display = "none";
document.querySelector("results").style.display = "none";
} else if (e.target.parentElement.children[0].id == "song") {
});
document.getElementById("song").addEventListener("click", () => {
state = "song";
document.getElementById("title").innerText = "pick a song";
document.getElementById("text").setAttribute("maxlength", "2048");
@ -260,26 +298,13 @@
document.getElementById("counter").style.display = "none";
document.getElementById("submit").style.display = "none";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
document.getElementById("search").style.display = "flex";
document.querySelector("results").style.display = "flex";
} else if (e.target.parentElement.children[0].id == "pfp") {
state = "pfp";
document.getElementById("title").innerText = "upload a new profile picture";
document.getElementById("pfp_upload").style.display = "flex";
document.getElementById("pfp_reminder").style.display = "flex";
document.getElementById("body-text").style.display = "none";
document.getElementById("clear").style.display = "flex";
document.getElementById("text").style.display = "none";
document.getElementById("counter").style.display = "none";
document.getElementById("submit").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("search").style.display = "none";
document.querySelector("results").style.display = "none";
}
});
});
})
document.getElementById("close").addEventListener("click", () => {
document.getElementById("popup").style.display = "none";
document.getElementById("blur").style.display = "none";
});
document.getElementById("text").addEventListener("input", () => {
document.getElementById("counter").innerText = `${document.getElementById("text").value.length} / ${document.getElementById("text").attributes.maxlength.value}`;
@ -295,8 +320,10 @@
let i = 0;
json.tracks.forEach((e)=>{
document.querySelectorAll("result")[i].querySelector("h2").innerText = e.title;
document.querySelectorAll("result")[i].querySelector("p").innerText = e.artists[0].name;
document.querySelectorAll("result")[i].querySelectorAll("p")[0].innerText = e.artists[0].name;
document.querySelectorAll("result")[i].querySelectorAll("p")[1].innerText = e.url.slice(22);
document.querySelectorAll("result")[i].setAttribute("data-url", e.url);
document.querySelectorAll("result")[i].style.display = "flex";
i++;
})
}
@ -304,7 +331,9 @@
document.querySelectorAll("result").forEach((e) => {
e.removeAttribute("data-url");
e.querySelector("h2").innerText = null;
e.querySelector("p").innerText = null;
e.querySelectorAll("p")[0].innerText = null;
e.querySelectorAll("p")[1].innerText = null;
e.style.display = "none";
})
}
})
@ -320,6 +349,7 @@
document.getElementById("counter").style.display = "none";
document.getElementById("submit").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
});
document.getElementById("download").addEventListener("click", async () => {
state = "download";
@ -333,6 +363,7 @@
document.getElementById("counter").style.display = "none";
document.getElementById("submit").style.display = "flex";
document.getElementById("popup").style.display = "flex";
document.getElementById("blur").style.display = "flex";
});
document.querySelectorAll("result").forEach(async e => {
e.addEventListener("click", async (element) => {
@ -349,22 +380,23 @@
</script>
</head>
<body>
<div id="blur"></div>
<div id="popup" style="display: none">
<h1 id="title"></h1>
<p id="body-text"></p>
<input type="text" id="text" />
<input type="text" id="search" />
<input type="text" id="search" placeholder="search a song title here.."/>
<results id="results">
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
<result><h2></h2><p></p><p></p></result>
</results>
<p id="counter">0 / 0</p>
<input type="file" id="pfp_upload" name="filename" accept=".png,.jpg,.jpeg,.gif,.avif,.webp,.tiff,.svg" />
@ -378,22 +410,18 @@
<button id="upload">Upload Backup</button>
</div>
<h1 class="title">{{ name }}'s profile</h1>
<h3>click on one of the following areas to edit</h3>
<h3>profile picture, name, song, and about me</h3>
<p style="font-size: 16px;">share your profile at {{ url_gen }}</p>
<section>
<img src="{{ user_pfp }}" class="pfp" id="pfp"/>
<img src="/img/edit.svg" id="edit" />
<div>
<div class="samerow" id="name">
<h1 id="name">{{ name }}</h1>
<img src="/img/edit.svg" id="edit" />
</div>
<img src="{{ user_pfp }}" class="pfp edit" id="pfp" />
<div class="profile-element edit" id="name">
<h1>{{ name }}</h1>
<p>/u/{{ username }}</p>
<div class="badges">{{ badges }}</div>
</div>
<div>
<div class="samerow" id="song">
<h2 id="song">{{ song_title }}</h2>
<img src="/img/edit.svg" id="edit" />
</div>
<div class="profile-element edit" id="song">
<h2>{{ song_title }}</h2>
<h3>{{ song_artist }}</h3>
<div class="samerow">
<p id="curPos">0:00</p>
@ -405,17 +433,14 @@
<img id="mute" src="/img/volume.svg" class="controls"/>
</div>
</div>
<div>
<div class="profile-element">
<h2>Joined {{ join_date }}</h2>
<h2>Last online {{ online_time }}</h2>
</div>
</section>
<section class="column">
<div class="samerow edit" id="about">
<h1 id="bio">about me</h1>
<img src="/img/edit.svg" id="edit" />
</div>
<p>{{ about }}</p>
<section class="column edit" id="about">
<h1>about me</h1>
<p class="about">{{ about }}</p>
</section>
</body>
</html>

View File

@ -42,17 +42,93 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/pages.css" />
<link rel="stylesheet" href="/css/users.css" />
<link rel="manifest" href="/manifest.json" />
<!-- seo + other things -->
<title>Selenite</title>
<script>
async function loadUsers(query, page) {
let above = false;
let below = false;
let data = await (await fetch(`/api/getUsers?page=${page - 1}&query=${query}`)).json();
let users = data['users'];
let url = new URL(location.href);
pages = Math.floor(data.count / 12);
document.getElementById("users").innerHTML = "";
for (let i = 0; i < Object.keys(users).length; i++) {
document.getElementById("users").innerHTML += `<a href="/u/${users[i].username}" class="users"><img class="pfp" src="${users[i].pfp_url}"/><div class="user_info"><h1>${users[i].name}</h1><p>${users[i].about}</p></div></a>`;
}
document.getElementById("pages").innerHTML = "";
for (let i = 1; i < pages + 1; i++) {
if (i + 6 > page && i - 6 < page) {
let curPage = parseInt(page);
let element = document.createElement("a");
if (!(i == curPage)) {
url.searchParams.set("page", i);
element.setAttribute("href", url);
}
element.setAttribute("class", `pages-btn`);
element.innerText = i;
document.getElementById("pages").append(element);
} else {
if (i + 6 > page) {
above = true;
}
if (i - 6 < page) {
below = true;
}
}
}
if (above) {
let element = document.createElement("a");
element.setAttribute("class", "pages-btn");
element.innerText = "...";
document.getElementById("pages").append(element);
}
if (below) {
let element = document.createElement("a");
element.setAttribute("class", "pages-btn");
element.innerText = "...";
document.getElementById("pages").prepend(element);
}
}
let pages;
document.addEventListener("DOMContentLoaded", async () => {
let params = location.search.substring(1).split("&");
let query;
let page;
if (params) {
for (let i = 0; i < params.length; i++) {
if (params[i].startsWith("query")) {
query = params[i].substring(6);
}
if (params[i].startsWith("page")) {
page = params[i].substring(5);
if (isNaN(page)) {
page = 1;
}
}
}
}
await loadUsers(query ? query : "", page ? page : 0);
document.getElementById("search").addEventListener("keydown", async (e) => {
if (e.key == "Enter") {
let url = new URL(location.href);
url.searchParams.set("query", document.getElementById("search").value);
url.searchParams.set("page", 1);
location.href = url;
}
});
});
</script>
<link rel="icon" href="/favicon.ico" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
</head>
<alerts> </alerts>
<body>
<h1 class="title">users</h1>
<div id="users">
</div>
<div id="users"></div>
<div id="pages"></div>
</body>
</html>

View File

@ -338,6 +338,10 @@ app.post("/api/admin/ban", async (req, res) => {
app.use("/api/music/search", async (req, res, next) => {
res.status(200).send(await search(req.query.q))
});
app.use("/api/music/download", async (req, res, next) => {
res.status(200).send(await download(req.query.url))
});
const server = app.listen(port, () => {
console.log(log.success("Express is online."));
console.log("- " + log.info("http://localhost:" + port));