@openveo/api
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,3 +1,12 @@ | ||
# 1.1.0 / 2015-11-24 | ||
- Update fileSystem.copy to create destination directory if it does not exist | ||
- Freeze project's dependencies | ||
- Add EntityProvider.removeProp to remove a property from all entities | ||
- Remove stdout logs in production environment | ||
- Correct issue when uploading an invalid archive, process was stuck, it is now in error | ||
- Update fileSystem.rmdir to test if directory exists before trying to remove it | ||
# 1.0.0 / 2015-10-26 | ||
First stable version of OpenVeo API for [OpenVeo core](https://github.com/veo-labs/openveo-core) and plugins development. |
@@ -110,2 +110,16 @@ 'use strict'; | ||
/** | ||
* Removes a property on all documents in the collection. | ||
* | ||
* @method removeProp | ||
* @async | ||
* @param {String} collection The collection to work on | ||
* @param {String} prop The property name to remove | ||
* @param {Function} callback The function to call when it's done | ||
* - **Error** The error if an error occurred, null otherwise | ||
*/ | ||
Database.prototype.removeProp = function() { | ||
throw new Error('removeProp method not implemented for this database'); | ||
}; | ||
/** | ||
* Updates a document. | ||
@@ -112,0 +126,0 @@ * |
@@ -121,2 +121,33 @@ 'use strict'; | ||
/** | ||
* Removes a property on all documents in the collection. | ||
* | ||
* @method removeProp | ||
* @async | ||
* @param {String} collection The collection to work on | ||
* @param {String} prop The property name to remove | ||
* @param {Function} callback The function to call when it's done | ||
* - **Error** The error if an error occurred, null otherwise | ||
*/ | ||
MongoDatabase.prototype.removeProp = function(collection, prop, callback) { | ||
var query = {}; | ||
query[prop] = {$exists: true}; | ||
query['locked'] = {$ne: true}; | ||
var update = {}; | ||
update['$unset'] = {}; | ||
update['$unset'][prop] = ''; | ||
collection = this.db.collection(collection); | ||
collection.update( | ||
query, | ||
update, | ||
{ | ||
multi: true | ||
}, | ||
callback | ||
); | ||
}; | ||
/** | ||
* Updates a document. | ||
@@ -134,6 +165,7 @@ * | ||
collection = this.db.collection(collection); | ||
collection.update(criteria, { | ||
$set: data | ||
}, | ||
collection.update(criteria, | ||
{ | ||
$set: data | ||
}, | ||
{ | ||
multi: true | ||
@@ -140,0 +172,0 @@ }, |
@@ -57,2 +57,85 @@ 'use strict'; | ||
/** | ||
* Removes a directory and all its content recursively and asynchronously. | ||
* | ||
* It is assumed that the directory exists. | ||
* | ||
* @method rmdirRecursive | ||
* @private | ||
* @async | ||
* @param {String} directoryPath Path of the directory to remove | ||
* @param {Function} callback The function to call when done | ||
* - **Error** The error if an error occurred, null otherwise | ||
*/ | ||
function rmdirRecursive(directoryPath, callback) { | ||
// Open directory | ||
fs.readdir(directoryPath, function(error, resources) { | ||
// Failed reading directory | ||
if (error) | ||
return callback(error); | ||
var pendingResourceNumber = resources.length; | ||
// No more pending resources, done for this directory | ||
if (!pendingResourceNumber) { | ||
// Remove directory | ||
fs.rmdir(directoryPath, callback); | ||
} | ||
// Iterate through the list of resources in the directory | ||
resources.forEach(function(resource) { | ||
var resourcePath = path.join(directoryPath, resource); | ||
// Get resource stats | ||
fs.stat(resourcePath, function(error, stats) { | ||
if (error) | ||
return callback(error); | ||
// Resource correspond to a directory | ||
if (stats.isDirectory()) { | ||
resources = rmdirRecursive(path.join(directoryPath, resource), function(error) { | ||
if (error) | ||
return callback(error); | ||
pendingResourceNumber--; | ||
if (!pendingResourceNumber) | ||
fs.rmdir(directoryPath, callback); | ||
}); | ||
} else { | ||
// Resource does not correspond to a directory | ||
// Mark resource as treated | ||
// Remove file | ||
fs.unlink(resourcePath, function(error) { | ||
if (error) | ||
return callback(error); | ||
else { | ||
pendingResourceNumber--; | ||
if (!pendingResourceNumber) | ||
fs.rmdir(directoryPath, callback); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Extracts a tar file to the given directory. | ||
@@ -69,4 +152,7 @@ * | ||
module.exports.extract = function(filePath, destinationPath, callback) { | ||
var extractTimeout; | ||
var onError = function(error) { | ||
if (extractTimeout) | ||
clearTimeout(extractTimeout); | ||
var onError = function(error) { | ||
callback(error); | ||
@@ -86,2 +172,5 @@ }; | ||
extractor.on('end', function() { | ||
if (extractTimeout) | ||
clearTimeout(extractTimeout); | ||
callback(); | ||
@@ -96,2 +185,11 @@ }); | ||
// Listen to readable stream close event | ||
tarFileReadableStream.on('close', function(chunk) { | ||
// In case of a broken archive, the readable stream close event is dispatched but not the close event of the | ||
// writable stream, wait for 10 seconds and dispatch an error if writable stream is still not closed | ||
extractTimeout = setTimeout(onError, 10000, new Error('Unexpected end of archive')); | ||
}); | ||
// Extract file | ||
@@ -106,2 +204,4 @@ tarFileReadableStream.pipe(extractor); | ||
* | ||
* If directory does not exist it will be automatically created. | ||
* | ||
* @method copy | ||
@@ -120,20 +220,31 @@ * @async | ||
if (sourceFilePath && destinationFilePath && callback) { | ||
try { | ||
var is = fs.createReadStream(sourceFilePath); | ||
var os = fs.createWriteStream(destinationFilePath); | ||
var safecopy = function(sourceFilePath, destinationFilePath, callback) { | ||
if (sourceFilePath && destinationFilePath && callback) { | ||
try { | ||
var is = fs.createReadStream(sourceFilePath); | ||
var os = fs.createWriteStream(destinationFilePath); | ||
is.on('error', onError); | ||
os.on('error', onError); | ||
is.on('error', onError); | ||
os.on('error', onError); | ||
is.on('end', function() { | ||
os.end(); | ||
callback(); | ||
}); | ||
is.on('end', function() { | ||
os.end(); | ||
callback(); | ||
}); | ||
is.pipe(os); | ||
} catch (e) { | ||
callback(new Error(e.message)); | ||
is.pipe(os); | ||
} catch (e) { | ||
callback(new Error(e.message)); | ||
} | ||
} else callback(new Error('File path not defined')); | ||
}; | ||
var pathDir = path.dirname(destinationFilePath); | ||
this.mkdir(pathDir, | ||
function(error) { | ||
if (error) callback(error); | ||
else safecopy(sourceFilePath, destinationFilePath, callback); | ||
} | ||
} | ||
); | ||
}; | ||
@@ -209,10 +320,7 @@ | ||
/** | ||
* Removes a directory and all its content recursively | ||
* and asynchronously. | ||
* Removes a directory and all its content recursively and asynchronously. | ||
* | ||
* It is assumed that the directory exists. | ||
* | ||
* @method rmdir | ||
* @async | ||
* @param {String} directoryPath The directory to remove | ||
* @param {String} directoryPath Path of the directory to remove | ||
* @param {Function} callback The function to call when done | ||
@@ -222,71 +330,8 @@ * - **Error** The error if an error occurred, null otherwise | ||
module.exports.rmdir = function(directoryPath, callback) { | ||
var self = this; | ||
// Open directory | ||
fs.readdir(directoryPath, function(error, resources) { | ||
// Failed reading directory | ||
if (error) | ||
return callback(error); | ||
var pendingResourceNumber = resources.length; | ||
// No more pending resources, done for this directory | ||
if (!pendingResourceNumber) { | ||
// Remove directory | ||
fs.rmdir(directoryPath, callback); | ||
} | ||
// Iterate through the list of resources in the directory | ||
resources.forEach(function(resource) { | ||
var resourcePath = path.join(directoryPath, resource); | ||
// Get resource stats | ||
fs.stat(resourcePath, function(error, stats) { | ||
if (error) | ||
return callback(error); | ||
// Resource correspond to a directory | ||
if (stats.isDirectory()) { | ||
resources = self.rmdir(path.join(directoryPath, resource), function(error) { | ||
if (error) | ||
return callback(error); | ||
pendingResourceNumber--; | ||
if (!pendingResourceNumber) | ||
fs.rmdir(directoryPath, callback); | ||
}); | ||
} else { | ||
// Resource does not correspond to a directory | ||
// Mark resource as treated | ||
// Remove file | ||
fs.unlink(resourcePath, function(error) { | ||
if (error) | ||
return callback(error); | ||
else { | ||
pendingResourceNumber--; | ||
if (!pendingResourceNumber) | ||
fs.rmdir(directoryPath, callback); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
fs.exists(directoryPath, function(exists) { | ||
if (!exists) | ||
callback(); | ||
else | ||
rmdirRecursive(directoryPath, callback); | ||
}); | ||
}; | ||
@@ -293,0 +338,0 @@ |
@@ -62,2 +62,6 @@ 'use strict'; | ||
}); | ||
// Remove default logger, which log to the standard output, in production environment | ||
if (process.env.NODE_ENV == 'production') | ||
winston.loggers.get(name).remove(winston.transports.Console); | ||
} | ||
@@ -64,0 +68,0 @@ |
@@ -230,1 +230,20 @@ 'use strict'; | ||
}; | ||
/** | ||
* Removes a property on all documents in the collection. | ||
* | ||
* @method removeProp | ||
* @async | ||
* @param {String} prop The property name to remove | ||
* @param {Function} callback The function to call when it's done | ||
* - **Error** The error if an error occurred, null otherwise | ||
* - **Number** The number of removed items | ||
*/ | ||
EntityProvider.prototype.removeProp = function(prop, callback) { | ||
this.database.removeProp( | ||
this.collection, | ||
prop, | ||
callback || function() { | ||
// TODO Log the error if any | ||
}); | ||
}; |
{ | ||
"name": "@openveo/api", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "API for OpenVeo plugins", | ||
@@ -22,17 +22,17 @@ "keywords": [ | ||
"dependencies": { | ||
"tar": "^1.0.3" | ||
"tar": "1.0.3" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"glob": "^5.0.12", | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-yuidoc": "^0.8.0", | ||
"grunt-eslint": "^17.2.0", | ||
"grunt-extend-config": "^0.9.2", | ||
"grunt-gh-pages": "^0.10.0", | ||
"grunt-init": "^0.3.2", | ||
"grunt-mocha-test": "^0.12.7", | ||
"mocha": "^2.1.0", | ||
"pre-commit": "^1.1.1", | ||
"yuidoc-theme-blue": "^0.1.9" | ||
"chai": ">=1.10.0", | ||
"glob": ">=5.0.12", | ||
"grunt": ">=0.4.5", | ||
"grunt-contrib-yuidoc": ">=0.8.0", | ||
"grunt-eslint": ">=17.2.0", | ||
"grunt-extend-config": ">=0.9.2", | ||
"grunt-gh-pages": ">=0.10.0", | ||
"grunt-init": ">=0.3.2", | ||
"grunt-mocha-test": ">=0.12.7", | ||
"mocha": ">=2.1.0", | ||
"pre-commit": ">=1.1.1", | ||
"yuidoc-theme-blue": ">=0.1.9" | ||
}, | ||
@@ -39,0 +39,0 @@ "peerDependencies": { |
@@ -19,3 +19,3 @@ # OpenVeo API | ||
Documentation is available on [Github pages](http://veo-labs.github.io/openveo-api/1.0.0). | ||
Documentation is available on [Github pages](http://veo-labs.github.io/openveo-api/1.1.0). | ||
@@ -22,0 +22,0 @@ # Contributors |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
80680
1406
4
1
+ Added@openveo/api@1.0.0(transitive)
Updatedtar@1.0.3