akos-egg-nos
Advanced tools
Comparing version 1.0.14 to 1.0.15
@@ -7,2 +7,3 @@ 'use strict'; | ||
const crypto = require('crypto'); | ||
const intoStream = require('into-stream'); | ||
module.exports = app => { | ||
@@ -28,11 +29,45 @@ const defaultConfig = { | ||
return nosClient; | ||
} | ||
}; | ||
const nosClient = app.nos.loadNosClient(Object.assign({}, defaultConfig, config)); | ||
app.nos.uploadText = async function uploadFile(key, content, hash) { | ||
const config = app.config.nos; | ||
if (hash) { // 给文件带 hash | ||
const ext = path.extname(key); | ||
const basename = path.basename(key, ext); | ||
key = `${basename}_${uuid.v4().replace(/-/g, '')}${ext}`; | ||
} | ||
const result = await new Promise((resolve, reject) => { | ||
try { | ||
nosClient.put_object_stream(Object.assign({ | ||
bucket: config.bucket, | ||
key, | ||
body: intoStream(content), | ||
length: content.length, | ||
}), result => { | ||
result.bucket = config.bucket; | ||
result.endpoint = config.endpoint; | ||
result.port = config.port; | ||
result.key = key; | ||
if (result.statusCode === 200) { | ||
resolve(result); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
} catch (err) { | ||
app.logger.error(err); | ||
reject(err); | ||
} | ||
}); | ||
return result; | ||
}; | ||
app.nos.uploadFile = async function uploadFile(filepath, key, hash) { | ||
const config = app.config.nos; | ||
if (!key) | ||
key = path.basename(filepath); | ||
if (!key) { key = path.basename(filepath); } | ||
if (hash) { // 给文件带 hash | ||
@@ -47,15 +82,15 @@ const ext = path.extname(key); | ||
nosClient.put_file(Object.assign({ | ||
bucket: config.bucket, | ||
key, | ||
filepath, | ||
bucket: config.bucket, | ||
key, | ||
filepath, | ||
}), result => { | ||
result.bucket = config.bucket; | ||
result.endpoint = config.endpoint; | ||
result.port = config.port; | ||
result.key = key; | ||
if (result.statusCode === 200) { | ||
resolve(result); | ||
} else { | ||
resolve(result); | ||
} | ||
result.bucket = config.bucket; | ||
result.endpoint = config.endpoint; | ||
result.port = config.port; | ||
result.key = key; | ||
if (result.statusCode === 200) { | ||
resolve(result); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
@@ -62,0 +97,0 @@ } catch (err) { |
{ | ||
"name": "akos-egg-nos", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"description": "[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][download-url]", | ||
@@ -15,2 +15,3 @@ "eggPlugin": { | ||
"dependencies": { | ||
"into-stream": "^5.1.1", | ||
"nos-node-sdk": "^0.0.5", | ||
@@ -17,0 +18,0 @@ "uuid": "^3.4.0" |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
11918
149
3
8
1
+ Addedinto-stream@^5.1.1
+ Addedfrom2@2.3.0(transitive)
+ Addedinto-stream@5.1.1(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedp-is-promise@3.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)