« get me outta code hell

list-cache.js - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/list-cache.js
blob: 71dbbcc518497ce1cd9147cfd34693b2fb597d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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))
}