Skip to content

Commit

Permalink
bug fixes + csv bulk import
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch (frill-corn) committed Jul 11, 2020
1 parent ffd6e68 commit 706fe51
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 23 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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"
Expand Down
55 changes: 41 additions & 14 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -120,26 +122,50 @@ 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");
}
} else {
res.send("Please log in");
}
});

app.get("/edit_playlists", async function(req, res) {
if (req.session.logintime) {
let output = "";
Expand All @@ -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
});
}
Expand Down Expand Up @@ -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", {
Expand All @@ -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 {
Expand Down
Binary file modified sessions
Binary file not shown.
8 changes: 8 additions & 0 deletions shrinkwrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion views/admin_playlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h6 class="card-subtitle mb-2 text-muted">
<p class="card-text">
Playlist descriptions are probaly gonna be part of a future update.
</p>
<a class="card-link" href="/playlist_editor/{{name}}">Edit Playlist</a>
<a class="card-link" href="/playlist_editor/{{{escapedname}}}">Edit Playlist</a>
</div>
</div>
</div>
22 changes: 17 additions & 5 deletions views/playlist_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ <h1>
<a href="/edit_playlists" class="btn btn-success"
>Go Back</a
>
<a href="/delete_playlist/{{playlist_name}}" class="btn btn-warning"
<a href="/delete_playlist/{{playlist_escapedname}}" class="btn btn-warning"
>Delete Playlist</a
>
<div class="list-group">
{{{playlist_items}}}
</div>
<form method="POST">
<div class="row">
<form method="POST" class="col-6">
Add new item to playlist. Duplicates are allowed!
<input class="hidden" type="hidden" name="action" value="singleadd" hidden/>
<input
class="form-control"
name="item_name"
Expand All @@ -24,13 +26,23 @@ <h1>
name="item_source"
placeholder="Item source. Usually the url"
/>
Optional Position: <input type="number" id="add-number" name="new_item_pos" />
Optional Insertion Position: <input type="number" id="add-number" name="new_item_pos" />
<button class="btn btn-success" type="submit">
Add item to {{playlist_name}}
</button>
</form>
<form id="playlist-item-delete-form" method="POST" action="/delete_playlist_item/{{playlist_name}}">
<input type="number" hidden id="del-number" name="delete_item_pos" />
<form method="POST" class="col-6">
Add multiple items to a playlist. Format is name,url seperated by line breaks.
<input class="hidden" type="hidden" name="action" value="multiadd" hidden/>
<textarea class="form-control" name="bulkimportdata" rows="6" placeholder="Please use csv style format name,url"></textarea>
Optional Insertion Position: <input type="number" id="add-number-multi" name="new_items_pos" />
<button class="btn btn-success" type="submit">
Import to {{playlist_name}}
</button>
</form>
</div>
<form id="playlist-item-delete-form" method="POST" action="/delete_playlist_item/{{playlist_escapedname}}" style="display:none;">
<input type="number" hidden id="del-number" name="delete_item_pos"/>
</form>
<p>
If another administrator edits the playlist and you delete an item the wrong
Expand Down

0 comments on commit 706fe51

Please sign in to comment.