Comparing version 2.3.1 to 2.3.2
@@ -15,8 +15,16 @@ var crypto = require('crypto'); | ||
var params = { | ||
"scope": this.scope, | ||
"deadline": this.expires + Math.floor(Date.now() / 1000), | ||
"callbackUrl": this.callbackUrl, | ||
"callbackBodyType": this.callbackBodyType, | ||
"customer": this.customer, | ||
}; | ||
if (this.scope !== null) { | ||
params["scope"] = this.scope; | ||
} | ||
if (this.callbackUrl !== null) { | ||
params["callbackurl"] = this.callbackUrl; | ||
} | ||
if (this.callbackBodyType !== null) { | ||
params["callbackBodyType"] = this.callbackBodyType; | ||
} | ||
if (this.customer !== null) { | ||
params["customer"] = this.customer; | ||
} | ||
var paramsString = JSON.stringify(params) | ||
@@ -23,0 +31,0 @@ return util.encode(paramsString); |
var fs = require('fs'); | ||
var path = require('path'); | ||
var crc = require('crc'); | ||
var crc32 = require('crc32'); | ||
var mime = require('mime'); | ||
@@ -87,3 +87,3 @@ var formstream = require('formstream'); | ||
if (!mimeType) { | ||
mimeType = mime.lookup(filename); | ||
mimeType = "application/octet-stream"; | ||
} | ||
@@ -121,9 +121,13 @@ var entryURI = this.bucket + ':' + key; | ||
Service.prototype.uploadWithToken = function(uploadToken, localFile, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) { | ||
Service.prototype.uploadWithToken = function(uploadToken, stream, key, mimeType, customMeta, callbackParams, crc32, onret) { | ||
/* | ||
* func UploadWithToken(uploadToken, localFile, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) => (data PutRet, code int, err Error) | ||
* func UploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, crc32, onret) => (data PutRet, code int, err Error) | ||
* 使用upload_token以multipart/form-data形式上传ReadStream流 | ||
**/ | ||
var bucket = this.bucket; | ||
var actionString = util.generateActionString(localFile, bucket, key, mimeType, customMeta, enableCrc32Check); | ||
if (!mimeType) { | ||
mimeType = "application/octet-stream"; | ||
} | ||
var actionString = util.generateActionString(bucket, key, mimeType, customMeta, crc32); | ||
if (callbackParams === null) { | ||
@@ -139,5 +143,4 @@ callbackParams = { | ||
var filename = path.basename(localFile); | ||
var filename = path.basename(key); | ||
var form = formstream(); | ||
var mimeType = mime.lookup(localFile); | ||
form.field('action', actionString); | ||
@@ -153,3 +156,2 @@ form.field('params', callbackQueryString); | ||
Service.prototype.uploadFileWithToken = function(uploadToken, localFile, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret) { | ||
@@ -160,14 +162,28 @@ /* | ||
**/ | ||
var self = this; | ||
var self = this | ||
, bucket = self.bucket; | ||
if (!mimeType) { | ||
mimeType = mime.lookup(localFile); | ||
mimeType = mime.lookup(localFile); | ||
} | ||
fs.stat(localFile, function(err, fi) { | ||
if (err) { | ||
onret({code: -1, error: err.toString(), detail: err}); | ||
return; | ||
} | ||
fs.stat(localFile, function(err, fi) { | ||
if (err) { | ||
onret({code: -1, error: err.toString(), detail: err}); | ||
return; | ||
} | ||
var stream = fs.createReadStream(localFile); | ||
self.uploadWithToken(uploadToken, localFile, stream, key, mimeType, customMeta, callbackParams, enableCrc32Check, onret); | ||
}); | ||
var fileCrc32 = null | ||
, stream = fs.createReadStream(localFile); | ||
if (enableCrc32Check) { | ||
var fileStat = fs.statSync(localFile) | ||
, fileSize = fileStat.size | ||
, buf = new Buffer(fileSize) | ||
, fd = fs.openSync(localFile, 'r'); | ||
fs.readSync(fd, buf, 0, fileSize, 0); | ||
fs.closeSync(fd); | ||
fileCrc32 = parseInt("0x" + crc32(buf)).toString(); | ||
} | ||
self.uploadWithToken(uploadToken, stream, key, mimeType, customMeta, callbackParams, fileCrc32, onret); | ||
}); | ||
}; | ||
@@ -174,0 +190,0 @@ |
var fs = require('fs'); | ||
var path = require('path'); | ||
var mime = require('mime'); | ||
var crypto = require('crypto'); | ||
var crc32 = require('crc32'); | ||
@@ -18,16 +18,10 @@ // ------------------------------------------------------------------------------------------ | ||
exports.generateActionString = function(localFile, bucket, key, mimeType, customMeta, enableCrc32Check) { | ||
if (!fs.existsSync(localFile)) { | ||
exports.generateActionString = function(bucket, key, mimeType, customMeta, crc32) { | ||
if (!key) { | ||
console.error("Please specify your key!"); | ||
return; | ||
} | ||
if (key == null) { | ||
var today = new Date(); | ||
key = crypto.createHash('sha1').update(localFile + today.toString()).digest('hex'); | ||
} | ||
var entryUri = bucket + ":" + key; | ||
if (mimeType === "") { | ||
mimeType = mime.lookup(localFile); | ||
if (mimeType === "") { | ||
mimeType = "application/octet-stream"; | ||
} | ||
if (!mimeType) { | ||
mimeType = "application/octet-stream"; | ||
} | ||
@@ -38,11 +32,5 @@ var actionParams = '/rs-put/' + this.encode(entryUri) + '/mimeType/' + this.encode(mimeType); | ||
} | ||
if (enableCrc32Check) { | ||
var fileStat = fs.statSync(localFile); | ||
var fileSize = fileStat.size; | ||
var buf = new Buffer(fileSize); | ||
var fd = fs.openSync(localFile, 'r'); | ||
fs.readSync(fd, buf, 0, fileSize, 0); | ||
var fileCrc32 = parseInt("0x" + crc32(buf)).toString(); | ||
actionParams += '/crc32/' + fileCrc32; | ||
} | ||
if ((crc32 !== undefined) && (crc32 !== null) && (crc32 !== "")) { | ||
actionParams += '/crc32/' + crc32; | ||
} | ||
return actionParams; | ||
@@ -49,0 +37,0 @@ } |
{ | ||
"name": "qiniu", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Node wrapper for Qiniu Resource (Cloud) Storage API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
28089
600