1
0
mirror of https://github.com/Tygs/0bin.git synced 2023-08-10 21:13:00 +03:00

zerobinpaste: add --expire option

This commit is contained in:
Mike Kazantsev 2013-04-23 00:39:29 +06:00 committed by fraggod@sacrilege
parent ce7ede3e35
commit 4eb40b9c8f

View File

@ -2,7 +2,9 @@
program program
.version('0.0.1') .version('0.0.1')
.usage('[options] [ file ... ]\n\n' + ' Paste contents of file(s) or stdin to 0bin site.') .usage('[options] [ file ... ]\n\n' + ' Paste contents of file(s) or stdin to 0bin site.')
.option('-u, --url [url]', 'URL of a 0bin site') .option('-u, --url [url]', 'URL of a 0bin site.')
.option('-e, --expire [period]',
'Expiration period - one of: 1_view, 1_day (default), 1_month, never.', '1_day')
.option('-c, --config [path]', 'Path to zerobin configuration file (default: ~/.zerobinpasterc).\n'\ .option('-c, --config [path]', 'Path to zerobin configuration file (default: ~/.zerobinpasterc).\n'\
+ ' Should be json-file with the same keys as can be specified on the command line.\n'\ + ' Should be json-file with the same keys as can be specified on the command line.\n'\
+ ' Example contents: {"url": "http://some-0bin.com"}', '~/.zerobinpasterc') + ' Example contents: {"url": "http://some-0bin.com"}', '~/.zerobinpasterc')
@ -22,11 +24,22 @@ try
(program[k] = v) for own k, v of config (program[k] = v) for own k, v of config
# Sanity checks # Sanity checks and option processing
if not program.url if not program.url
console.error('ERROR: URL option must be specified.') console.error('ERROR: URL option must be specified.')
process.exit(1) process.exit(1)
if program.expire == '1_view'
# "burn_after_reading" is too damn long for cli
program.expire = 'burn_after_reading'
expire_opts = ['burn_after_reading', '1_day', '1_month', 'never']
if program.expire not in expire_opts
console.error(
"ERROR: --expire value (provided: '#{program.expire}')"\
+ ' must be one of: ' + expire_opts.join(', ') + "." )
process.exit(1)
# Paste one dump and print URL, optionally prefixed with name # Paste one dump and print URL, optionally prefixed with name
paste_file = (content, name) -> paste_file = (content, name) ->
@ -39,7 +52,7 @@ paste_file = (content, name) ->
content = sjcl.encrypt(key, content) content = sjcl.encrypt(key, content)
content = qs.stringify content = qs.stringify
content: content content: content
expiration: '1_day' # burn_after_reading 1_day 1_month never expiration: program.expire
# host.com -> http://host.com # host.com -> http://host.com
if not program.url.match(/^https?:\/\//) if not program.url.match(/^https?:\/\//)