diff --git a/accounts/profile.js b/accounts/profile.js index 257bb8e..20049f9 100755 --- a/accounts/profile.js +++ b/accounts/profile.js @@ -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({ diff --git a/html/profile.html b/html/profile.html index a2f6e4b..c874996 100755 --- a/html/profile.html +++ b/html/profile.html @@ -46,25 +46,31 @@ +

{{ name }}'s profile

+

click on one of the following areas to edit

+

profile picture, name, song, and about me

+

share your profile at {{ url_gen }}

- - -
-
-

{{ name }}

- -
+ +
+

{{ name }}

/u/{{ username }}

{{ badges }}
-
-
-

{{ song_title }}

- -
+
+

{{ song_title }}

{{ song_artist }}

0:00

@@ -405,17 +433,14 @@
-
+

Joined {{ join_date }}

Last online {{ online_time }}

-
-
-

about me

- -
-

{{ about }}

+
+

about me

+

{{ about }}

diff --git a/html/users.html b/html/users.html index 0f9faed..d1660c2 100644 --- a/html/users.html +++ b/html/users.html @@ -42,17 +42,93 @@ + Selenite +

users

-
- -
+
+
diff --git a/index.js b/index.js index 69fd89f..8fcf001 100755 --- a/index.js +++ b/index.js @@ -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));