Commit 16cad486 authored by Max Kellermann's avatar Max Kellermann

command/QueueCommands: validate the "addid" position before adding the song

Validate early, so we avoid the rollback if an error occurs.
parent 7a6d0c2e
...@@ -113,12 +113,17 @@ handle_addid(Client &client, Request args, Response &r) ...@@ -113,12 +113,17 @@ handle_addid(Client &client, Request args, Response &r)
const char *const uri = args.front(); const char *const uri = args.front();
auto &partition = client.GetPartition(); auto &partition = client.GetPartition();
int to = -1;
if (args.size > 1) {
const auto queue_length = partition.playlist.queue.GetLength();
to = args.ParseUnsigned(1, queue_length);
}
const SongLoader loader(client); const SongLoader loader(client);
unsigned added_id = partition.AppendURI(loader, uri); unsigned added_id = partition.AppendURI(loader, uri);
if (args.size == 2) { if (to >= 0) {
unsigned to = args.ParseUnsigned(1);
try { try {
partition.MoveId(added_id, to); partition.MoveId(added_id, to);
} catch (...) { } catch (...) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment