diff --git a/.env.example b/.env.example
index 8421bf7..9068157 100755
--- a/.env.example
+++ b/.env.example
@@ -4,4 +4,8 @@ HCAPTCHA_SECRET=hcaptcha
ANNOUNCEMENT_KEY=text.
GROQ_API_KEY=["groq_api"]
NTFY_ALERT=ntfy_channel
-DATA_PATH=where_to_store_data
\ No newline at end of file
+DATA_PATH=where_to_store_data
+NODE_ENV=production
+DISCORD_AI_WEBHOOK=discord_webhook_url
+PROCESSING_SERVER=https://git.ceres.rip/selenite/processing
+PROCESSING_SERVER_SECRET=secret
\ No newline at end of file
diff --git a/accounts/music.js b/accounts/music.js
index 8a22e36..fb9a59e 100644
--- a/accounts/music.js
+++ b/accounts/music.js
@@ -9,30 +9,16 @@ async function search(query) {
let data = sc.search(query);
return data;
}
-async function download(url, res) {
- if (!url) {
- return res.status(400).send('Please provide a SoundCloud track URL as ?url=')
- }
-
+async function download(url) {
try {
- const info = await sc.getByUrl(url)
+ const info = await sc.getByUrl(url);
- if (info.type !== 'track') {
- return res.status(400).send('URL is not a SoundCloud track')
- }
+ const { stream } = await info.getStream();
- const { stream, mimeType, sizeBytes } = await info.getStream()
-
- res.setHeader('Content-Type', mimeType)
- if (sizeBytes) {
- res.setHeader('Content-Length', sizeBytes.toString())
- }
- res.setHeader('Cache-Control', 'no-cache')
-
- stream.pipe(res)
+ return stream.path;
} catch (err) {
console.error('Stream error:', err)
- res.status(500).send(err.message || 'Failed to stream track')
+ return(err.message || 'Failed to stream track')
}
}
diff --git a/accounts/profile.js b/accounts/profile.js
index 3bc1775..72ce3d1 100755
--- a/accounts/profile.js
+++ b/accounts/profile.js
@@ -4,6 +4,7 @@ import sanitizeHtml from "sanitize-html";
import sharp from "sharp";
import { accs } from "../database.js";
import { getUserFromCookie, isBanned, decryptCookie, verifyCookie } from "./manage.js";
+import { download } from "./music.js";
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime.js";
@@ -208,6 +209,31 @@ async function editProfile(body, token, admin) {
updateAccount.get({ $url: url, $user: user });
}
}
+ if (body.artist) {
+ let path = await download(body.url);
+ console.log("exit download");
+ let file = Bun.file(path);
+ let request = new Request({
+ url: process.env.PROCESSING_SERVER + "/process",
+ method: "POST",
+ body: await file.arrayBuffer(),
+ headers: {
+ "X-Authentication": process.env.PROCESSING_SERVER_SECRET
+ }
+ });
+ console.log("created request");
+ let oggFile = await fetch(request);
+ console.log("finished request");
+ let filePath = `/data/${existingAccount.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({
+ path: filePath,
+ name: body.title,
+ artist: body.artist
+ }), $user: user });
+ console.log("database");
+ }
return { success: true };
}
@@ -228,6 +254,7 @@ async function generateAccountPage(name, cookie, admin) {
}
let modifiedHTML = rawProfileHTML;
+ let songData = JSON.parse(userData.music) || false;
modifiedHTML = modifiedHTML.replaceAll("{{ name }}", sanitizeHtml(userData.name, allowNone));
modifiedHTML = modifiedHTML.replaceAll("{{ join_date }}", dayjs(userData.createdAt).fromNow());
modifiedHTML = modifiedHTML.replaceAll("{{ about }}", sanitizeHtml(userData.about, sanitizeConfig) || "No about me available..");
@@ -236,6 +263,14 @@ async function generateAccountPage(name, cookie, admin) {
modifiedHTML = modifiedHTML.replaceAll("{{ custom_css }}", userData.custom_css || "");
modifiedHTML = modifiedHTML.replaceAll("{{ online_time }}", dayjs(userData.last_login).fromNow());
modifiedHTML = modifiedHTML.replaceAll("{{ username }}", sanitizeHtml(userData.username, allowNone));
+ if(songData) {
+ modifiedHTML = modifiedHTML.replaceAll("{{ song_title }}", sanitizeHtml(songData.name, allowNone));
+ modifiedHTML = modifiedHTML.replaceAll("{{ song_artist }}", sanitizeHtml(songData.artist, allowNone));
+ modifiedHTML = modifiedHTML.replaceAll("{{ song_url }}", sanitizeHtml(songData.path, allowNone));
+ modifiedHTML = modifiedHTML.replaceAll("{{ is_music }}", "true");
+ } else {
+ modifiedHTML = modifiedHTML.replaceAll("{{ is_music }}", "false");
+ }
let badges_html = "";
if (userData.badges !== null) {
@@ -269,7 +304,6 @@ async function generateAccountPage(name, cookie, admin) {
modifiedHTML = modifiedHTML.replaceAll("{{ url_gen }}", `https://selenite.cc/u/${userData.username}`);
modifiedHTML = modifiedHTML.replaceAll("{{ online_time }}", dayjs(userData.last_login).fromNow());
modifiedHTML = modifiedHTML.replaceAll("{{ css_edit }}", (userData.badges ? userData.badges.length : 0) > 0 ? '' : "");
- modifiedHTML = modifiedHTML.replaceAll("{{ played_games }}", buildGameHTML(userData));
let badges_html = "";
if (userData.badges !== null) {
@@ -282,43 +316,7 @@ async function generateAccountPage(name, cookie, admin) {
return modifiedHTML;
}
}
-function buildGameHTML(existingAccount) {
- if (existingAccount.playedgames) {
- let games = JSON.parse(existingAccount.playedgames);
- let sortedGames = Object.keys(games).sort((a, b) => games[b] - games[a]);
- let return_data = [];
- if (Object.keys(games).length < 10) {
- for (let i = 0; i < sortedGames.length; i++) {
- try {
- let origin = gamesExceptions[sortedGames[i]] ? "sppa" : "semag";
- sortedGames[i] = gamesExceptions[sortedGames[i]] ? gamesExceptions[sortedGames[i]] : sortedGames[i];
- return_data[i] = { name: profileReadyJSON[sortedGames[i]].name, image: profileReadyJSON[sortedGames[i]].image, path: sortedGames[i], origin: origin, valid: true };
- } catch (e) {
- return_data[i] = { valid: false };
- }
- }
- } else {
- for (let i = 0; i < 10; i++) {
- try {
- let origin = gamesExceptions[sortedGames[i]] ? "sppa" : "semag";
- sortedGames[i] = gamesExceptions[sortedGames[i]] ? gamesExceptions[sortedGames[i]] : sortedGames[i];
- return_data[i] = { name: profileReadyJSON[sortedGames[i]].name, image: profileReadyJSON[sortedGames[i]].image, path: sortedGames[i], origin: origin, valid: true };
- } catch (e) {
- return_data[i] = { valid: false };
- }
- }
- }
- let return_html = "";
- for (let i = 0; i < Object.keys(return_data).length; i++) {
- if (return_data[i].valid) {
- return_html += `
${return_data[i].name}