This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drop.js
executable file
·122 lines (99 loc) · 3.04 KB
/
drop.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /usr/bin/env node
/*
DSDROP: Instant file sharing server
Copyright (C) 2014-2015 Callan Bryant <callan.bryant@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
// basic implementation
// TODO: config system
// TODO: oneshot flag
if (!process.argv[2]) {
console.log('usage:',process.argv[1],'<file to send>')
process.exit()
}
var filepath = process.argv[2]
var Upload = require('../lib/Upload')
var clipboard = require('copy-paste')
var prompt = require('prompt')
var ProgressBar = require('progress')
require('colors')
var upload = new Upload()
upload.on('uploadStart',function() {
var bar = new ProgressBar('Uploading [:bar] :percent :etas', {
complete: '=',
incomplete: ' ',
width: 30,
total: upload.filesize,
})
upload.on('uploadProgress',function(val) {
bar.update(val/upload.filesize)
})
})
upload.on('hashStart',function() {
var bar = new ProgressBar('Analysing [:bar] :percent :etas', {
complete: '=',
incomplete: ' ',
width: 30,
total: upload.filesize,
})
upload.on('hashProgress',function(val) {
bar.update(val/upload.filesize)
})
})
// programatic error
upload.on('error',function(err) {
console.error(err.message.red)
process.exit(23)
})
upload.on('authenticationFailure',function(msg) {
process.stderr.write(err.red+"\n")
proces.exit()
})
upload.on('done',function(url) {
// TMUX messes up copy and paste in mac os x
clipboard.copy(url,function(err) {
if (!err && ! (process.env.TMUX && process.platform == 'darwin') )
process.stderr.write("\nURL in clipboard: ".green)
else
process.stderr.write("\nURL: ".green)
console.log(url)
// this is necessary, due to
// https://github.com/xavi-/node-copy-paste/issues/17 (Process will not exit)
// https://github.com/xavi-/node-copy-paste/issues/18 (error callback fired twice)
process.exit(0)
})
})
upload.on('plsLogin',function(){
console.log('Connecting to '+upload.url)
process.stderr.write("\n"+upload.description+"\n\n")
prompt.start()
prompt.get({
properties: {
username: {
required: true,
default: process.env.USER
},
password: {
hidden: true,
required: true,
}
}
},function (err, result) {
if (err) return console.log('Invalid input'.yellow)
upload.login(result.username,result.password)
})
})
upload.on('authenticated',function() {
console.log("\nAuthentication and authorisation successful".green)
})
upload.uploadFile(filepath)