From 5a8f8eafa4e30d7a0febcf804253b6853caf36e7 Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 23 Sep 2019 04:10:01 -0300 Subject: Re-add download function to fix process metadata The download code doesn't actually really depend on state, besides having access to the record for the track, which we can pass in from anywhere. --- backend.js | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/backend.js b/backend.js index d3e0db7..d68d448 100644 --- a/backend.js +++ b/backend.js @@ -28,6 +28,27 @@ const fs = require('fs') const writeFile = promisify(fs.writeFile) const readFile = promisify(fs.readFile) +async function download(item, record) { + if (isGroup(item)) { + // TODO: Download all children (recursively), show a confirmation prompt + // if there are a lot of items (remember to flatten). + return + } + + // Don't start downloading an item if we're already downloading it! + if (record.downloading) { + return + } + + const arg = item.downloaderArg + record.downloading = true + try { + return await getDownloaderFor(arg)(arg) + } finally { + record.downloading = false + } +} + class QueuePlayer extends EventEmitter { constructor({ getRecordFor @@ -460,24 +481,7 @@ class QueuePlayer extends EventEmitter { } async download(item) { - if (isGroup(item)) { - // TODO: Download all children (recursively), show a confirmation prompt - // if there are a lot of items (remember to flatten). - return - } - - // Don't start downloading an item if we're already downloading it! - if (this.getRecordFor(item).downloading) { - return - } - - const arg = item.downloaderArg - this.getRecordFor(item).downloading = true - try { - return await getDownloaderFor(arg)(arg) - } finally { - this.getRecordFor(item).downloading = false - } + return download(item, this.getRecordFor(item)) } seekAhead(seconds) { @@ -670,6 +674,10 @@ class Backend extends EventEmitter { await queuePlayer.stopPlaying() } } + + async download(item) { + return download(item, this.getRecordFor(item)) + } } module.exports = Backend -- cgit 1.3.0-6-gf8a5