Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function upload(stream, idOrPath, tag, done) {
var blob = blobManager.create(account);
var tx = db.begin();
var blobIdP = blob.put(stream);
var fileP = self.byUuidOrPath(idOrPath).get();
var previousIdP = p.ternary(fileP, p.get(fileP, 'version'), null);
var versionP = p.allObject({
userAccountId: userAccount.id,
date: new Date(),
blobId: blobIdP,
creatorId: userAccount.id,
previousId: previousIdP,
});
versionP = p.set(versionP, p.allObject({
id: fn.call(Version.createHash, versionP)
}));
// Even if Version.insert has been lifted, it returns a promise and
// therefore we cannot call execWithin. We have to wait for the promise
// to resolve
var versionInsert = p.eventuallyCall(
Version.insert(versionP), 'execWithin', tx);
var versionIdP = p.get(versionP, 'id');
var fileIdP = p.if (p.not(fileP), function () {
var splitPath = idOrPath.split('/');
var fileName = splitPath[splitPath.length - 1];
var newId = uuid.v1();
p.eventuallyCall(self.createQuery(idOrPath, p.allObject({
id: newId,
userAccountId: userAccount.id,
name: fileName,
version: versionIdP
preserveSpecRunner: true,
outDir: 'tests'
});
var target = this.target;
var tempFiles = [];
var specRunnerPath = path.join(options.outDir, 'specrunner-tmp.html');
// Use specs argument, if provided
if (opt_specs) {
options.specs = opt_specs.split(',');
// Do not exclude any specs, if specs argument is passed
options.exclude = [];
}
fn.call(setup).
then(run).
then(done).
catch(function(err) {
var errObj = err instanceof Error ? err : new Error(err);
done(errObj);
}).
finally(tearDown);
function setup() {
var specs = grunt.file.expand(options.specs);
var excludedSpecs = grunt.file.expand(options.exclude);
grunt.verbose.write('Running specs: ' + JSON.stringify(specs, null, 2) + '\n');
grunt.verbose.write('Excluding specs: ' + JSON.stringify(excludedSpecs, null, 2) + '\n');
createTempFile(specRunnerPath, generateSpecRunner(options));
}
module.exports = function upload(stream, idOrPath, tag, done) {
var blob = blobManager.create(account);
var tx = db.begin();
var blobIdP = blob.put(stream);
var fileP = self.byUuidOrPath(idOrPath).get();
var previousIdP = p.ternary(fileP, p.get(fileP, 'version'), null);
var versionP = p.allObject({
userAccountId: userAccount.id,
date: new Date(),
blobId: blobIdP,
creatorId: userAccount.id,
previousId: previousIdP,
});
versionP = p.set(versionP, p.allObject({
id: fn.call(Version.createHash, versionP)
}));
// Even if Version.insert has been lifted, it returns a promise and
// therefore we cannot call execWithin. We have to wait for the promise
// to resolve
var versionInsert = p.eventuallyCall(
Version.insert(versionP), 'execWithin', tx);
var versionIdP = p.get(versionP, 'id');
var fileIdP = p.if (p.not(fileP), function () {
var splitPath = idOrPath.split('/');
var fileName = splitPath[splitPath.length - 1];
var newId = uuid.v1();
p.eventuallyCall(self.createQuery(idOrPath, p.allObject({
id: newId,
userAccountId: userAccount.id,
name: fileName,
version: versionIdP
if (kwargs_len) {
progress_msg.push(kwargs);
}
}
self._send_wamp(progress_msg);
}
};
var cd = new Invocation(details.caller, progress, details.procedure);
// We use the following whenjs call wrapper, which automatically
// wraps a plain, non-promise value in a (immediately resolved) promise
//
// See: https://github.com/cujojs/when/blob/master/docs/api.md#fncall
//
when_fn.call(endpoint, args, kwargs, cd).then(
function (res) {
// construct YIELD message
// FIXME: Options
//
var reply = [MSG_TYPE.YIELD, request, {}];
if (res instanceof Result) {
var kwargs_len = Object.keys(res.kwargs).length;
if (res.args.length || kwargs_len) {
reply.push(res.args);
if (kwargs_len) {
reply.push(res.kwargs);
}
}
} else {
// we want to provide the regitration procedure to the handler and may
// need to get this from the registration object attached to the registration
// since for non-pattern registrations this is not sent over the wire
var cd = new Invocation(details.procedure || reg.procedure,
progress,
details.caller,
details.caller_authid,
details.caller_authrole
);
// We use the following whenjs call wrapper, which automatically
// wraps a plain, non-promise value in a (immediately resolved) promise
//
// See: https://github.com/cujojs/when/blob/master/docs/api.md#fncall
//
when_fn.call(reg.endpoint, args, kwargs, cd).then(
function (res) {
// construct YIELD message
// FIXME: Options
//
var reply = [MSG_TYPE.YIELD, request, {}];
if (res instanceof Result) {
var kwargs_len = Object.keys(res.kwargs).length;
if (res.args.length || kwargs_len) {
reply.push(res.args);
if (kwargs_len) {
reply.push(res.kwargs);
}
}
} else {
LogicSaga.prototype.handleTimer = function handleTimer(timerID, actualTriggerTime, deps){
var self = this;
// NOTE: Dynamic dispatch! Watch out for name collisions!
var timerType = this._activeTimers[timerID];
var timerHandlerName = 'handle' + timerType + 'Timer';
this._finishTimer(timerID, actualTriggerTime);
if(typeof(this[timerHandlerName]) === 'function'){
return whenFunctions.call(this[timerHandlerName].bind(this), timerID, actualTriggerTime, deps);
}
else{
throw new LogicSagaTimerHandlerMissingError(timerID, timerType);
}
};
var post = utils.createPost(file, options).then(function(post) {
var viewOpts = {
source: '',
filename: file,
locals: poet.app ? poet.app.locals : {}
};
return when.join(fn.call(template, _.extend({}, viewOpts, { source: post.content })),
fn.call(template, _.extend({}, viewOpts, { source: post.preview })))
.then(function(contents) {
post.content = contents[0];
post.preview = contents[1] + options.readMoreLink(post);
return post;
}, function(err) {
console.error('Unable to parse file ' + file + ': ' + err);
if (process.env.NODE_ENV === 'production') {
return err;
}
post.content = post.preview = '<pre style="font-family: monospace">' + err + '</pre>';
return post;
});
}).then(function(post) {
if (!(post instanceof Error))
var post = utils.createPost(file, options).then(function(post) {
var viewOpts = {
source: '',
filename: file,
locals: poet.app ? poet.app.locals : {}
};
return when.join(fn.call(template, _.extend({}, viewOpts, { source: post.content })),
fn.call(template, _.extend({}, viewOpts, { source: post.preview })))
.then(function(contents) {
post.content = contents[0];
post.preview = contents[1] + options.readMoreLink(post);
return post;
}, function(err) {
console.error('Unable to parse file ' + file + ': ' + err);
if (process.env.NODE_ENV === 'production') {
return err;
}
post.content = post.preview = '<pre style="font-family: monospace">' + err + '</pre>';
return post;
});
}).then(function(post) {
if (!(post instanceof Error))
var details = msg[1];
var reason = msg[2];
if (self.onleave) {
self.onleave(reason, details);
}
} else if (msg_type === MSG_TYPE.CHALLENGE) {
if (self._onchallenge) {
var method = msg[1];
var extra = msg[2];
when_fn.call(self._onchallenge, self, method, extra).then(
function (signature) {
var msg = [MSG_TYPE.AUTHENTICATE, signature, {}];
self._send_wamp(msg);
},
function (err) {
log.debug("onchallenge() raised:", err);
var msg = [MSG_TYPE.ABORT, {message: "sorry, I cannot authenticate (onchallenge handler raised an exception)"}, "wamp.error.cannot_authenticate"];
self._send_wamp(msg);
self._socket.close(1000);
}
);
} else {
log.debug("received WAMP challenge, but no onchallenge() handler set");
var msg = [MSG_TYPE.ABORT, {message: "sorry, I cannot authenticate (no onchallenge handler set)"}, "wamp.error.cannot_authenticate"];
var details = msg[1];
var reason = msg[2];
if (self.onleave) {
self.onleave(reason, details);
}
} else if (msg_type === MSG_TYPE.CHALLENGE) {
if (self._onchallenge) {
var method = msg[1];
var extra = msg[2];
when_fn.call(self._onchallenge, self, method, extra).then(
function (signature) {
if(typeof signature === "string"){
var msg = [MSG_TYPE.AUTHENTICATE, signature, {}];
} else if (typeof signature === "object") {
var signatureString = signature[0];
var authExtra = signature[1];
var msg = [MSG_TYPE.AUTHENTICATE, signatureString, authExtra];
}
self._send_wamp(msg);
},
function (err) {
util.handle_error(self._on_user_error, err, "onchallenge() raised: ");
var msg = [MSG_TYPE.ABORT, {message: "sorry, I cannot authenticate (onchallenge handler raised an exception)"}, "wamp.error.cannot_authenticate"];