github-picbed
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "github-picbed", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Upload file to github and Get Url", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,6 +10,7 @@ const request = require('./request'); | ||
repository = null, | ||
branch = null | ||
branch = null, | ||
httpProxy = null | ||
}) { | ||
let isPage = false; | ||
async function getOptions({ token, repository, branch }) { | ||
async function getOptions({ token, repository, branch, httpProxy }) { | ||
repository = repository.replace(/http(s|):\/\/github.com\//, ''); | ||
@@ -26,3 +27,3 @@ if (repository.split('/').length != 2) throw new Error('Not a invaild repository url.'); | ||
path: pagesInfo.path, | ||
branch: pagesInfo.branch | ||
branch: pagesInfo.branch | ||
} | ||
@@ -44,2 +45,3 @@ isPage = true; | ||
repository, | ||
httpProxy, | ||
...options | ||
@@ -53,3 +55,4 @@ }; | ||
token, | ||
method: 'GET' | ||
method: 'GET', | ||
httpProxy | ||
}); | ||
@@ -71,3 +74,3 @@ | ||
if (!token && !repository) return; | ||
_options = await getOptions({ token, repository, branch }); | ||
_options = await getOptions({ token, repository, branch, httpProxy }); | ||
console.dir(_options); | ||
@@ -100,3 +103,4 @@ } catch (error) { | ||
token: _options.token, | ||
method: 'GET' | ||
method: 'GET', | ||
httpProxy: _options.httpProxy | ||
}); | ||
@@ -109,2 +113,3 @@ | ||
method: 'PUT', | ||
httpProxy: _options.httpProxy, | ||
data: { | ||
@@ -130,5 +135,6 @@ message: `Upload file ${filename}`, | ||
repository, | ||
branch | ||
branch, | ||
httpProxy | ||
}) { | ||
_options = await getOptions({ token, repository, branch }); | ||
_options = await getOptions({ token, repository, branch, httpProxy }); | ||
}, | ||
@@ -153,2 +159,2 @@ get options() { | ||
return fs.readFileSync(pathname); | ||
} | ||
} |
@@ -7,3 +7,4 @@ const https = require('https'); | ||
data = null, | ||
method | ||
method, | ||
httpProxy = null | ||
}) { | ||
@@ -23,2 +24,6 @@ return new Promise((resolve, reject) => { | ||
if (httpProxy) { | ||
options.agent = new https.Agent({ proxy: httpProxy }); | ||
} | ||
let req = https.request(options, (res) => { | ||
@@ -32,3 +37,3 @@ let body = ''; | ||
}); | ||
res.on('end', () => { | ||
@@ -47,6 +52,6 @@ try { | ||
if(data) req.write(JSON.stringify(data)); | ||
if (data) req.write(JSON.stringify(data)); | ||
req.end(); | ||
}); | ||
} | ||
} |
12
test.js
@@ -7,3 +7,4 @@ const test = require('tape'); | ||
username: '', | ||
repository: '' | ||
repository: '', | ||
httpProxy: '' | ||
}; | ||
@@ -24,3 +25,4 @@ | ||
repository: `https://github.com/${options.username}/${options.repository}`, | ||
branch: 'main' | ||
branch: options.branch, | ||
httpProxy: options.httpProxy | ||
}); | ||
@@ -30,3 +32,3 @@ | ||
while(!github.isInitialized()) await sleep(100); | ||
test('Upload readme to repository', async function(assert) { | ||
@@ -36,6 +38,6 @@ assert.deepEqual(await github.upload({ | ||
filename: 'readme.txt' | ||
}), `https://cdn.jsdelivr.net/gh/${username}/${repository}/readme.txt`); | ||
}), {'filename': 'readme.txt', 'url':`https://cdn.jsdelivr.net/gh/${options.username}/${options.repository}@${options.branch}/readme.txt`}); | ||
assert.end() | ||
}) | ||
})() | ||
})() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11846
209