Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/commands/base.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
const { Command } = require('@oclif/command')
const {Command} = require('@oclif/command')
const fetch = require('node-fetch')
const tempy = require('tempy')
const fs = require('fs')

class BaseCommand extends Command {
async init() {
if (process.env.TERM_PROGRAM !== 'iTerm.app') {
this.help()
}
async init() {
if (process.env.TERM_PROGRAM !== 'iTerm.app') {
this.help()
}
}

help() {
console.log(`For inline images, only iTerm2 3+ (with imgcat shell integration) is supported. https://iterm2.com`)
}
help() {
console.log('For inline images, only iTerm2 3+ (with imgcat shell integration) is supported. https://iterm2.com')
}

async downloadUrl(url, extension) {
const tmpFile = tempy.file({ extension })
return fetch(url)
.then(res => {
return new Promise((resolve, reject) => {
const dest = fs.createWriteStream(tmpFile)
res.body.pipe(dest)
res.body.on('error', err => reject(err))
dest.on('finish', () => resolve(tmpFile))
dest.on('error', err => reject(err))
})
})
}
async downloadUrl(url, extension) {
const tmpFile = tempy.file({extension})
return fetch(url)
.then(res => {
return new Promise((resolve, reject) => {
const dest = fs.createWriteStream(tmpFile)
res.body.pipe(dest)
res.body.on('error', err => reject(err))
dest.on('finish', () => resolve(tmpFile))
dest.on('error', err => reject(err))
})
})
}
}

BaseCommand.hidden = true

module.exports = BaseCommand
module.exports = BaseCommand
2 changes: 1 addition & 1 deletion src/commands/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RandomCommand extends BaseCommand {
throw {response, json}
}

const gifUrl = json.data.image_url
const gifUrl = json.data.images.original.url

if (flags['link-only']) {
showLink(gifUrl)
Expand Down