Comparing version 1.0.2 to 1.0.3
21
index.js
@@ -13,2 +13,8 @@ #!/usr/bin/env node | ||
if (process.argv.length < 3) { | ||
console.error(`Usage: gupl <filepath>`) | ||
process.exit(1) | ||
} | ||
const ALLOWED_FILETYPES = ['gif', 'jpg', 'jpeg', 'png', 'docx', 'gz', 'log', 'pdf', 'pptx', 'txt', 'xlsx', 'zip'] | ||
const REPOURL = 'https://github.com/isaacs/github/issues/new' | ||
@@ -18,2 +24,9 @@ const COOKIEFILE = path.join(__dirname, 'cookie.json') | ||
const isFileAllowed = ALLOWED_FILETYPES.some(ext => FILEPATH.toLowerCase().endsWith(ext)) | ||
if (!isFileAllowed) { | ||
console.log('Your file is not allowed to upload to GitHub.') | ||
console.log(`Only ${ALLOWED_FILETYPES.join(', ')} are allowed.`) | ||
process.exit(1) | ||
} | ||
const readCookie = async () => { | ||
@@ -41,3 +54,3 @@ if (await fs.exists(COOKIEFILE)) { | ||
name: 'has2fa', | ||
message: 'Do you have 2fa?' | ||
message: 'Do you have 2fa enabled?' | ||
}, | ||
@@ -47,4 +60,4 @@ { | ||
name: 'otp', | ||
message: 'Please tell me your current otp code.', | ||
validate: v => !!v | ||
message: 'Please enter current otp here:', | ||
validate: v => !!v && /^\d{6}$/.test(v) | ||
} | ||
@@ -55,2 +68,4 @@ ] | ||
await fs.writeFile(COOKIEFILE, JSON.stringify(cookie.toJSON())) | ||
console.log(`Your GitHub login credentials(cookies) have been saved to "${COOKIEFILE}".`) | ||
console.log('To delete it, you can execute "gupl-reset" or "ghfileupl-reset".') | ||
return cookie | ||
@@ -57,0 +72,0 @@ } |
@@ -44,2 +44,5 @@ const got = require('got') | ||
// 2fa | ||
if (!otp) { | ||
throw new Error('2fa otp code is required but not given!') | ||
} | ||
const $fa = await client.get('https://github.com/sessions/two-factor').then(r => cheerio.load(r.body)) | ||
@@ -46,0 +49,0 @@ const authenticity_token2 = $fa('input[name=authenticity_token]').attr('value') |
{ | ||
"name": "ghfileupl", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"author": "maple3142", | ||
"main": "index.js", | ||
"bin": { | ||
"gupl": "./index.js" | ||
"gupl": "./index.js", | ||
"ghfileupl": "./index.js", | ||
"gupl-reset": "./reset.js", | ||
"ghfileupl-reset": "./reset.js" | ||
}, | ||
@@ -9,0 +12,0 @@ "license": "MIT", |
@@ -18,4 +18,6 @@ # ghfileupl | ||
![step](https://user-images.githubusercontent.com/9370547/48206784-10ee7600-e367-11e8-9dd6-6250843eb981.jpg) | ||
When you use this at the first time, it will ask you to login GitHub account with account and password. | ||
I suggest you to register another alt account when using this tool. |
185
23
7026
3