Skip to content

Commit

Permalink
fix(cache): fixes no such file or directory when running in title mod…
Browse files Browse the repository at this point in the history
…e with no config (fixes #5)
  • Loading branch information
naholyr committed Oct 17, 2017
1 parent 7ffe8aa commit 81e0885
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ const dedupeSubtitles = partialRight(uniqBy, 'SubDownloadLink')

module.exports = (options/*:Options*/) /*:Promise<any>*/ =>
checkOptions(options)
.then(opts =>
cacheReady(opts) // void
.then(selectVideo(opts)) // { url, title }
.then(opts => // void
selectVideo(opts) // { url, title }
.then((video/*:?Show*/) => (debug('Selected (1/3)', video), video))
.then(selectTorrent) // when url is an array of described torrents
.then((torrent/*:?Show*/) => (debug('Selected (2/3)', torrent), torrent))
Expand All @@ -49,7 +48,7 @@ const checkOptions = options => {
return Promise.reject(Error('Using option --browse or <title> is incompatible with offline mode'))
}
// Grab 'feed' option from browsing showrss
return selectShow(opts).then(feed => {
return cacheReady(opts).then(() => selectShow(opts)).then(feed => {
if (!feed) {
process.exit(0)
}
Expand All @@ -59,7 +58,7 @@ const checkOptions = options => {
if (opts.offline && !opts.cache) {
return Promise.reject(Error('Cannot use "offline" option while cache is disabled'))
}
return Promise.resolve(opts)
return cacheReady(opts).then(() => opts)
}

const cacheReady = ({ cache }) => cache ? utils.createDir(cache) : Promise.resolve()
Expand Down Expand Up @@ -94,12 +93,12 @@ const searchSubtitles = (title, cache, _skipReadCache) /*:Promise<OrigSubtitles[
}

const selectVideo = (opts) /*:() => Promise<?Show>*/ => opts.movie
? () => selectMovie(opts)
? selectMovie(opts)
: selectEpisode(opts)

const selectEpisode = ({ feed, cache, offline, log }) /*:() => Promise<Show>*/ => offline
? // Offline mode
() => glob(path.join(cache, '*/'))
glob(path.join(cache, '*/'))
.then(dirs => utils.ask.list('Partially or complete available episodes', dirs.map(d => ({
name: path.basename(d),
value: d
Expand All @@ -113,7 +112,7 @@ const selectEpisode = ({ feed, cache, offline, log }) /*:() => Promise<Show>*/ =
return show
})
: // Online
() => readFeed(feed)
readFeed(feed)
.then(articles => utils.ask.list('Recent available episodes', articles.map(a => ({ name: a.title, value: {
title: a.title,
url: a.link
Expand Down
4 changes: 1 addition & 3 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ const buildDirStats = (files/*:NamedStat[]*/) /*:DirStat*/ => {
}
}

const dirStats = (dir/*:string|string[]*/) => {
return listFiles(dir, true).then(buildDirStats)
}
const dirStats = (dir/*:string|string[]*/) => listFiles(dir, true).then(buildDirStats)

const isInDir = (dir/*:string*/, file/*:string*/) /*:boolean*/ => {
const parent = path.dirname(file)
Expand Down

0 comments on commit 81e0885

Please sign in to comment.