« get me outta code hell

Add simple list-cache debug tool - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-11-12 13:47:36 -0400
committerFlorrie <towerofnix@gmail.com>2018-11-12 13:47:36 -0400
commit6993905eaf1714de40babae53f5154238cde1172 (patch)
tree96665d5cad70e72acb2de534b00f21ac93b62103
parente0e8e85105de083a66e47f4d125cc621b95fbc02 (diff)
Add simple list-cache debug tool
It's not really practical for use right now. Well, more like I haven't
figured out *what* the "ordinary use" is.
-rw-r--r--list-cache.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/list-cache.js b/list-cache.js
new file mode 100644
index 0000000..71dbbcc
--- /dev/null
+++ b/list-cache.js
@@ -0,0 +1,33 @@
+const { Base64 } = require('js-base64')
+const fs = require('fs')
+const util = require('util')
+const downloaders = require('./downloaders')
+const ansi = require('./tui-lib/util/ansi')
+
+const readdir = util.promisify(fs.readdir)
+
+async function main(args) {
+  const dlPath = downloaders.rootCacheDir
+  const type = args[0] || null
+
+  async function list(dir) {
+    console.log(await readdir(dir))
+  }
+
+  if (!type) {
+    console.log('No type specified. Pass one of the following as an argument:', (await readdir(dlPath)).join(', '))
+    return
+  }
+
+  console.log(`${ansi.setAttributes([ansi.A_BRIGHT])}Downloads of type "${type}"${ansi.resetAttributes()}`)
+  for (const entry of await readdir(dlPath + '/' + type)) {
+    const files = await readdir(`${dlPath}/${type}/${entry}`)
+    console.log(`  ${Base64.decode(entry)}: ${ansi.setAttributes([ansi.A_BRIGHT])}${files.join(', ')} ${ansi.resetAttributes()}${ansi.setAttributes([ansi.A_DIM])}(${type}/${entry})${ansi.resetAttributes()}`)
+  }
+}
+
+module.exports = main
+
+if (require.main === module) {
+  main(process.argv.slice(2)).catch(err => console.error(err))
+}