From 706fe51877fa3c04bd72f959f71f080ce0af5025 Mon Sep 17 00:00:00 2001 From: "Glitch (frill-corn)" Date: Sat, 11 Jul 2020 01:44:34 +0000 Subject: [PATCH] bug fixes + csv bulk import --- package.json | 6 ++-- server.js | 55 +++++++++++++++++++++++++++---------- sessions | Bin 12288 -> 12288 bytes shrinkwrap.yaml | 8 ++++++ views/admin_playlist.html | 2 +- views/playlist_editor.html | 22 +++++++++++---- 6 files changed, 70 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 46556f9..2966e3d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "//1": "OpenRadio", "//2": "https://docs.npmjs.com/files/package.json", "//3": "updating this file will download and update your packages", - "info":"Type here to reinstall modules in glitch", + "info": "Type here to reinstall modules in glitch", "name": "hello-empowered-express", "version": "0.0.1", "description": "A simple Node app built on Express, instantly up and running.", @@ -27,8 +27,8 @@ "sqlite3": "^4.2.0", "better-sqlite3": "^7.0.1", "butterchurn": "^2.6.7", - "butterchurn-presets": "^2.4.7" - + "butterchurn-presets": "^2.4.7", + "csv-string": "^4.0.1" }, "engines": { "node": "10.x" diff --git a/server.js b/server.js index 967693e..80dcd92 100644 --- a/server.js +++ b/server.js @@ -7,6 +7,8 @@ var session = require("express-session"); const exphbs = require("express-handlebars"); const config = require("./config"); const Endb = require("endb"); +let CSV = require("csv-string"); + var { retrieveStream } = require("./contentHandler"); app.engine(".html", exphbs({ extname: ".html" })); app.set("view engine", ".html"); @@ -102,7 +104,7 @@ app.get("/playlist_editor/:name", async function(req, res) { } res.render(__dirname + "/views/playlist_editor.html", { ...config.webexports, - ...{ playlist_items: output, playlist_name: name } + ...{ playlist_items: output, playlist_name: name, playlist_escapedname: encodeURIComponent(name) } }); } else { req.send("Not a playlist"); @@ -120,19 +122,42 @@ app.post("/playlist_editor/:name", async function(req, res) { } if (await playlists.has(name)) { let playlist = await playlists.get(name); - if (!req.body.new_item_pos || req.body.new_item_pos == "") { - playlist.push({ - name: req.body.item_name, - source: req.body.item_source - }); + if (req.body.action == "singleadd") { + if (!req.body.new_item_pos || req.body.new_item_pos == "") { + playlist.push({ + name: req.body.item_name, + source: req.body.item_source + }); + } else { + playlist.splice(req.body.new_item_pos, 0, { + name: req.body.item_name, + source: req.body.item_source + }); + } } else { - playlist.splice(req.body.new_item_pos, 0, { - name: req.body.item_name, - source: req.body.item_source - }); + if (!req.body.new_item_pos || req.body.new_item_pos == "") { + let lines = CSV.parse(req.body.bulkimportdata) + for (let i = 0; i < lines.length; i++) { + //console.log(lines[i]); + // console.log(lines[i]); + playlist.push({ + name: lines[i][0], + source: lines[i][1] + }); + } + } else { + let lines = req.body.bulkimportdata; + for (let i = 0; i < lines.length; i++) { + let lineData = CSV.parse(lines[i]); + playlist.splice(req.body.new_item_pos, 0, { + name: lineData[0], + source: lineData[1] + }); + } + } } await playlists.set(name, playlist); - res.redirect("/playlist_editor/" + name); + res.redirect("/playlist_editor/" + encodeURIComponent(name)); } else { res.send("Playlist doesn't exist"); } @@ -140,6 +165,7 @@ app.post("/playlist_editor/:name", async function(req, res) { res.send("Please log in"); } }); + app.get("/edit_playlists", async function(req, res) { if (req.session.logintime) { let output = ""; @@ -149,6 +175,7 @@ app.get("/edit_playlists", async function(req, res) { output + admin_playlist_template({ name: all_playlists[i]["key"], + escapedname: encodeURIComponent(all_playlists[i]["key"]), count: all_playlists[i]["value"].length }); } @@ -236,7 +263,7 @@ app.get("/", async (req, res) => { for (var i = 0; i < streams.length; i++) { output = output + - template({ name: streams[i], streamaudiopath: "/stream/" + streams[i] }); + template({ name: streams[i], streamaudiopath: "/stream/" + encodeURIComponent(streams[i]), escapedname: encodeURIComponent(streams[i])}); } //console.log(output); res.render(__dirname + "/views/index.html", { @@ -257,8 +284,8 @@ io.on("connection", function(socket) { idtoplaylist[socket.id] = data.name; socket.join(data.name); socket.emit("itemchange", { - name: playlistToName[idtoplaylist[socket.id]] - }); + name: playlistToName[idtoplaylist[socket.id]] + }); }); socket.on("getcurrentitem", function(data) { try { diff --git a/sessions b/sessions index 50b8a6029ffed70d830b72648918575408482ad2..06dde8d6a0c4056a755fd18ead652273b0d72494 100644 GIT binary patch delta 215 zcmZojXh@hK#l-b%qKp%e+?cS0pNolaE(5q8w>C7PJSi3*`QIcO^?-=y@}s9 zC%`b(ry|oO*|WSL(9^}m!qwH#%g3p*EXg;>+u6ja-1Mi99K+-~c?C^#OCYe&QA({S z$Sg`NRZ!X`QjfHo3C%=;2Y{0<4n9SkQmJE~q<+lRuy3N3Un|~|+md%0+wfvL2^|jO(7#O?> M*~7>%`L@0)0OpQ4{{R30 diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml index 62a3ef1..b1ba5bd 100644 --- a/shrinkwrap.yaml +++ b/shrinkwrap.yaml @@ -4,6 +4,7 @@ dependencies: butterchurn: 2.6.7 butterchurn-presets: 2.4.7 connect-sqlite3: 0.9.11 + csv-string: 4.0.1 endb: 0.22.9 express: 4.17.1 express-handlebars: 4.0.3 @@ -340,6 +341,12 @@ packages: dev: false resolution: integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= + /csv-string/4.0.1: + dev: false + engines: + node: '>=12.0' + resolution: + integrity: sha512-nCdK+EWDbqLvZ2MmVQhHTmidMEsHbK3ncgTJb4oguNRpkmH5OOr+KkDRB4nqsVrJ7oK0AdO1QEsBp0+z7KBtGQ== /dashdash/1.14.1: dependencies: assert-plus: 1.0.0 @@ -1880,6 +1887,7 @@ specifiers: butterchurn: ^2.6.7 butterchurn-presets: ^2.4.7 connect-sqlite3: ^0.9.11 + csv-string: ^4.0.1 endb: ^0.22.9 express: ^4.17.1 express-handlebars: ^4.0.3 diff --git a/views/admin_playlist.html b/views/admin_playlist.html index e91d6fa..f1fec99 100644 --- a/views/admin_playlist.html +++ b/views/admin_playlist.html @@ -9,7 +9,7 @@

Playlist descriptions are probaly gonna be part of a future update.

- Edit Playlist + Edit Playlist diff --git a/views/playlist_editor.html b/views/playlist_editor.html index 76a25de..11bb6e4 100644 --- a/views/playlist_editor.html +++ b/views/playlist_editor.html @@ -6,14 +6,16 @@

Go Back - Delete Playlist
{{{playlist_items}}}
-
+
+ Add new item to playlist. Duplicates are allowed! + name="item_source" placeholder="Item source. Usually the url" /> - Optional Position: + Optional Insertion Position: -
- + + Add multiple items to a playlist. Format is name,url seperated by line breaks. + + + Optional Insertion Position: + +
+
+

If another administrator edits the playlist and you delete an item the wrong