|
|
@ -3,6 +3,8 @@ import dns from 'dns'; |
|
|
|
import Now from '../lib'; |
|
|
|
import toHost from './to-host'; |
|
|
|
import chalk from 'chalk'; |
|
|
|
import table from 'text-table'; |
|
|
|
import ms from 'ms'; |
|
|
|
|
|
|
|
export default class Alias extends Now { |
|
|
|
|
|
|
@ -37,22 +39,26 @@ export default class Alias extends Now { |
|
|
|
throw err; |
|
|
|
} |
|
|
|
|
|
|
|
return this.retry(async (bail, attempt) => { |
|
|
|
const res = await this._fetch(`/now/aliases/${_alias.uid}`, { |
|
|
|
method: 'DELETE' |
|
|
|
}); |
|
|
|
if (await readConfirmation(_alias)) { |
|
|
|
return this.retry(async (bail, attempt) => { |
|
|
|
const res = await this._fetch(`/now/aliases/${_alias.uid}`, { |
|
|
|
method: 'DELETE' |
|
|
|
}); |
|
|
|
|
|
|
|
if (403 === res.status) { |
|
|
|
return bail(new Error('Unauthorized')); |
|
|
|
} |
|
|
|
if (403 === res.status) { |
|
|
|
return bail(new Error('Unauthorized')); |
|
|
|
} |
|
|
|
|
|
|
|
if (res.status !== 200) { |
|
|
|
const err = new Error('Deletion failed. Try again later.'); |
|
|
|
throw err; |
|
|
|
} |
|
|
|
if (res.status !== 200) { |
|
|
|
const err = new Error('Deletion failed. Try again later.'); |
|
|
|
throw err; |
|
|
|
} |
|
|
|
|
|
|
|
console.log(`${chalk.cyan('> Success!')}`); |
|
|
|
}); |
|
|
|
console.log(`${chalk.cyan('> Success!')} The alias has been removed.`); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
console.log('> Aborted'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async findAlias (alias) { |
|
|
@ -271,3 +277,23 @@ function resolve4 (host) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function readConfirmation (alias) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
const time = chalk.gray(ms(new Date() - new Date(alias.created)) + ' ago'); |
|
|
|
const tbl = table( |
|
|
|
[[alias.uid, `https://${alias.alias}`, time]], |
|
|
|
{ align: ['l', 'r', 'l'], hsep: ' '.repeat(3) } |
|
|
|
); |
|
|
|
|
|
|
|
process.stdout.write('> The following alias will be removed permanently\n'); |
|
|
|
process.stdout.write(' ' + tbl + '\n'); |
|
|
|
process.stdout.write(`${chalk.bold.red('> Are you sure?')} ${chalk.gray('[yN] ')}`); |
|
|
|
|
|
|
|
process.stdin.on('data', (d) => { |
|
|
|
process.stdin.pause(); |
|
|
|
process.stdin.write('\n'); |
|
|
|
resolve('y' === d.toString().trim()); |
|
|
|
}).resume(); |
|
|
|
}); |
|
|
|
} |
|
|
|